-
Notifications
You must be signed in to change notification settings - Fork 337
Add Additional OTel JVM Runtime Metrics and Gate "Developmental" Metrics #11411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mhlidd
wants to merge
6
commits into
master
Choose a base branch
from
mhlidd/otlp_runtime_metrics_follow_up
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82c7398
init
mhlidd b2a3ff6
update checks to match OTel checks
mhlidd cbdabdd
adding jvm.gc.duration
mhlidd de166ab
adding tests for experimental off
mhlidd 40ef357
removing unnecessary test and adding configs
mhlidd 8f0dd9c
pr comments and split jvm.thread.count by attributes and jdk version
mhlidd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
420 changes: 389 additions & 31 deletions
420
...gent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JvmOtlpRuntimeMetrics.java
Large diffs are not rendered by default.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
...elemetry-1.47/src/test/java/opentelemetry147/metrics/JvmOtlpRuntimeMetricsForkedTest.java
This file contains hidden or 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,107 @@ | ||
| package opentelemetry147.metrics; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import datadog.trace.agent.jmxfetch.JvmOtlpRuntimeMetrics; | ||
| import datadog.trace.bootstrap.otel.metrics.data.OtelMetricRegistry; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| // Forked test: runs in an isolated JVM and starts JvmOtlpRuntimeMetrics with the experimental | ||
| // flag OFF, verifying that Development-status instruments are not registered and that the | ||
| // jvm.gc.cause attribute is omitted from jvm.gc.duration data points. The JvmOtlpRuntimeMetrics | ||
| // class uses a one-shot AtomicBoolean to guard registration, so this scenario must run in its | ||
| // own JVM separate from the always-on JvmOtlpRuntimeMetricsTest. | ||
| class JvmOtlpRuntimeMetricsForkedTest { | ||
|
|
||
| @BeforeAll | ||
| static void setUp() { | ||
| System.setProperty("dd.metrics.otel.enabled", "true"); | ||
| JvmOtlpRuntimeMetrics.start(false); | ||
| } | ||
|
|
||
| @Test | ||
| void registersOnlyStableMetricsWhenExperimentalDisabled() { | ||
| JvmOtlpRuntimeMetricsTest.MetricCollector collector = | ||
| new JvmOtlpRuntimeMetricsTest.MetricCollector(); | ||
| OtelMetricRegistry.INSTANCE.collectMetrics(collector); | ||
|
|
||
| Set<String> names = collector.metricNames; | ||
|
|
||
| List<String> expectedStableMetrics = | ||
| Arrays.asList( | ||
| "jvm.memory.used", | ||
| "jvm.memory.committed", | ||
| "jvm.memory.limit", | ||
| "jvm.memory.used_after_last_gc", | ||
| "jvm.thread.count", | ||
| "jvm.class.loaded", | ||
| "jvm.class.count", | ||
| "jvm.class.unloaded", | ||
| "jvm.cpu.time", | ||
| "jvm.cpu.count", | ||
| "jvm.cpu.recent_utilization", | ||
| "jvm.gc.duration"); | ||
| for (String metric : expectedStableMetrics) { | ||
| assertTrue( | ||
| names.contains(metric), | ||
| "Expected stable metric '" + metric + "' not found. Got: " + new TreeSet<>(names)); | ||
| } | ||
|
|
||
| List<String> developmentMetrics = | ||
| Arrays.asList( | ||
| "jvm.memory.init", | ||
| "jvm.buffer.memory.used", | ||
| "jvm.buffer.memory.limit", | ||
| "jvm.buffer.count", | ||
| "jvm.system.cpu.utilization", | ||
| "jvm.system.cpu.load_1m", | ||
| "jvm.file_descriptor.count", | ||
| "jvm.file_descriptor.limit"); | ||
| for (String metric : developmentMetrics) { | ||
| assertFalse( | ||
| names.contains(metric), | ||
| "Development metric '" | ||
| + metric | ||
| + "' should not be registered when experimental disabled. Got: " | ||
| + new TreeSet<>(names)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void jvmGcDurationDataPointsOmitGcCauseWhenExperimentalDisabled() throws InterruptedException { | ||
| System.gc(); | ||
|
|
||
| List<JvmOtlpRuntimeMetricsTest.DataPointEntry> points = null; | ||
| long deadlineNanos = System.nanoTime() + TimeUnit.SECONDS.toNanos(2); | ||
| while (System.nanoTime() < deadlineNanos) { | ||
| JvmOtlpRuntimeMetricsTest.MetricCollector collector = | ||
| new JvmOtlpRuntimeMetricsTest.MetricCollector(); | ||
| OtelMetricRegistry.INSTANCE.collectMetrics(collector); | ||
| points = collector.points.get("jvm.gc.duration"); | ||
| if (points != null && !points.isEmpty()) { | ||
| break; | ||
| } | ||
| Thread.sleep(50); | ||
| } | ||
|
|
||
| assertNotNull(points, "jvm.gc.duration should have data points after System.gc()"); | ||
| assertFalse(points.isEmpty(), "jvm.gc.duration should have at least one data point"); | ||
| assertTrue( | ||
| points.stream() | ||
| .allMatch( | ||
| p -> | ||
| p.attrs.containsKey("jvm.gc.name") | ||
| && p.attrs.containsKey("jvm.gc.action") | ||
| && !p.attrs.containsKey("jvm.gc.cause")), | ||
| "jvm.gc.duration data points must carry jvm.gc.name and jvm.gc.action, but not jvm.gc.cause" | ||
| + " when experimental disabled"); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default for this in OTel is
false- do we want to match that?https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/runtime-telemetry/README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an intentional decision. Idea being that JMX inherently emits many metrics that are considered as "developmental" in OTel, so it would be an easy win to enable these by default.