-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Jonas Kunz
authored
Oct 2, 2020
1 parent
7840de5
commit 636f8fb
Showing
33 changed files
with
2,646 additions
and
63 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../src/system-test/java/rocks/inspectit/ocelot/instrumentation/tracing/AutoTracingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package rocks.inspectit.ocelot.instrumentation.tracing; | ||
|
||
import io.opencensus.trace.export.SpanData; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import rocks.inspectit.ocelot.utils.TestUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AutoTracingTest extends TraceTestBase { | ||
|
||
@BeforeAll | ||
static void waitForInstrumentation() { | ||
TestUtils.waitForClassInstrumentation(AutoTracingTest.class, true, 30, TimeUnit.SECONDS); | ||
} | ||
|
||
SpanData getSpanWithName(Collection<? extends SpanData> spans, String name) { | ||
Optional<? extends SpanData> spanOptional = spans.stream() | ||
.filter(s -> ((SpanData) s).getName().equals(name)) | ||
.findFirst(); | ||
assertThat(spanOptional).isNotEmpty(); | ||
return spanOptional.get(); | ||
} | ||
|
||
@Test | ||
void verifyStackTraceSampling() { | ||
instrumentMe(); | ||
|
||
assertTraceExported((spans) -> { | ||
|
||
SpanData root = getSpanWithName(spans, "AutoTracingTest.instrumentMe"); | ||
SpanData activeWait = getSpanWithName(spans, "*AutoTracingTest.activeWait"); | ||
SpanData passiveWait = getSpanWithName(spans, "*Thread.sleep"); | ||
|
||
assertThat(activeWait.getParentSpanId()).isEqualTo(root.getContext().getSpanId()); | ||
assertThat(passiveWait.getParentSpanId()).isEqualTo(root.getContext().getSpanId()); | ||
|
||
assertThat(activeWait.getEndTimestamp()).isLessThan(passiveWait.getStartTimestamp()); | ||
}); | ||
} | ||
|
||
private void passiveWait(long duration) { | ||
try { | ||
Thread.sleep(duration); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private void activeWait(long duration) { | ||
long durationNanos = duration * 1000 * 1000; | ||
long start = System.nanoTime(); | ||
while ((System.nanoTime() - start) < durationNanos) { | ||
} | ||
} | ||
|
||
private void nestedWait(long duration) { | ||
passiveWait(duration); | ||
} | ||
|
||
private void instrumentMe() { | ||
activeWait(150); | ||
nestedWait(100); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
inspectit-ocelot-agent/src/system-test/resources/config/AutoTracingTest.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
inspectit: | ||
tracing: | ||
auto-tracing: | ||
frequency: 10ms | ||
instrumentation: | ||
|
||
scopes: | ||
AutoTracingTest-instrumentMe: | ||
type: | ||
name: AutoTracingTest | ||
matcher-mode: ENDS_WITH | ||
methods: | ||
- name: instrumentMe | ||
|
||
rules: | ||
AutoTracingTest-instrumentMe: | ||
scopes: | ||
AutoTracingTest-instrumentMe: true | ||
tracing: | ||
start-span: true | ||
auto-tracing: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...config/src/main/java/rocks/inspectit/ocelot/config/model/tracing/AutoTracingSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package rocks.inspectit.ocelot.config.model.tracing; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Defines global settings regarding the stack trace sampling feature. | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
public class AutoTracingSettings { | ||
|
||
/** | ||
* Defines the frequency at which stack trace samples are taken. | ||
* The higher the frequency, the greater the accuracy of the resulting trace. | ||
* <p> | ||
* However, taking stack traces is very expensive, therefore high frequencies can induce a big performance penalty. | ||
*/ | ||
private Duration frequency; | ||
|
||
/** | ||
* When the first method executes with auto-tracing enabled, a separate Thread is started as a timer for taking stack trace samples. | ||
* If at some point no more methods with stack-trace sampling are executed, this thread spins unnecessarily. | ||
* <p> | ||
* Therefore if no samples has been taken for at least the duration of {@link #shutdownDelay}, the timer will be shutdown. | ||
* If a span requests sampling after the timer has shutdown, it will restart it. | ||
*/ | ||
private Duration shutdownDelay; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.