-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emit rate limited JFR events when RejectedExecutionHandlers run (#7076)
- Loading branch information
1 parent
87dc120
commit 8a0a406
Showing
8 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ava11/datadog/trace/bootstrap/instrumentation/jfr/backpressure/BackpressureProfiling.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,36 @@ | ||
package datadog.trace.bootstrap.instrumentation.jfr.backpressure; | ||
|
||
import datadog.trace.api.Config; | ||
import datadog.trace.bootstrap.instrumentation.api.TaskWrapper; | ||
|
||
public final class BackpressureProfiling { | ||
|
||
private static final class Holder { | ||
static final BackpressureProfiling INSTANCE = new BackpressureProfiling(Config.get()); | ||
} | ||
|
||
public static BackpressureProfiling getInstance() { | ||
return Holder.INSTANCE; | ||
} | ||
|
||
private final BackpressureSampler sampler; | ||
|
||
private BackpressureProfiling(final Config config) { | ||
this(new BackpressureSampler(config)); | ||
} | ||
|
||
BackpressureProfiling(BackpressureSampler sampler) { | ||
this.sampler = sampler; | ||
} | ||
|
||
public void start() { | ||
sampler.start(); | ||
} | ||
|
||
public void process(Class<?> backpressureMechanism, Object task) { | ||
if (sampler.sample()) { | ||
new BackpressureSampleEvent(backpressureMechanism, TaskWrapper.getUnwrappedType(task)) | ||
.commit(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...a11/datadog/trace/bootstrap/instrumentation/jfr/backpressure/BackpressureSampleEvent.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,38 @@ | ||
package datadog.trace.bootstrap.instrumentation.jfr.backpressure; | ||
|
||
import datadog.trace.bootstrap.instrumentation.jfr.ContextualEvent; | ||
import jdk.jfr.Category; | ||
import jdk.jfr.Description; | ||
import jdk.jfr.Event; | ||
import jdk.jfr.Label; | ||
import jdk.jfr.Name; | ||
|
||
@Name("datadog.BackpressureSample") | ||
@Label("Backpressure Sample") | ||
@Description("Datadog backpressure sample event.") | ||
@Category("Datadog") | ||
public class BackpressureSampleEvent extends Event implements ContextualEvent { | ||
@Label("Policy") | ||
private final Class<?> policy; | ||
|
||
@Label("Task") | ||
private final Class<?> task; | ||
|
||
@Label("Local Root Span Id") | ||
private long localRootSpanId; | ||
|
||
@Label("Span Id") | ||
private long spanId; | ||
|
||
public BackpressureSampleEvent(Class<?> policy, Class<?> task) { | ||
this.policy = policy; | ||
this.task = task; | ||
captureContext(); | ||
} | ||
|
||
@Override | ||
public void setContext(long localRootSpanId, long spanId) { | ||
this.localRootSpanId = localRootSpanId; | ||
this.spanId = spanId; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../java11/datadog/trace/bootstrap/instrumentation/jfr/backpressure/BackpressureSampler.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 datadog.trace.bootstrap.instrumentation.jfr.backpressure; | ||
|
||
import datadog.trace.api.Config; | ||
import datadog.trace.bootstrap.instrumentation.jfr.WindowSampler; | ||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
final class BackpressureSampler extends WindowSampler<BackpressureSampleEvent> { | ||
/* | ||
* Fixed 0.5 second sampling window. | ||
* Logic in AdaptiveSampler relies on sampling window being small compared to (in our case) recording duration: | ||
* sampler may overshoot on one given window but should average to samplesPerWindow in the long run. | ||
*/ | ||
private static final Duration SAMPLING_WINDOW = Duration.of(500, ChronoUnit.MILLIS); | ||
|
||
BackpressureSampler(final Config config) { | ||
this( | ||
SAMPLING_WINDOW, | ||
getSamplesPerWindow(config), | ||
samplingWindowsPerRecording(config.getProfilingUploadPeriod(), SAMPLING_WINDOW)); | ||
} | ||
|
||
BackpressureSampler(Duration windowDuration, int samplesPerWindow, int lookback) { | ||
super(windowDuration, samplesPerWindow, lookback, BackpressureSampleEvent.class); | ||
} | ||
|
||
protected static int getSamplesPerWindow(final Config config) { | ||
return config.getProfilingBackPressureSampleLimit() | ||
/ samplingWindowsPerRecording(config.getProfilingUploadPeriod(), SAMPLING_WINDOW); | ||
} | ||
} |
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