@@ -28,38 +28,51 @@ class JvmOtlpRuntimeMetricsTest extends InstrumentationSpecification {
2828 injectSysConfig(" dd.metrics.otel.enabled" , " true" )
2929 }
3030
31- def " JVM runtime metrics are registered and produce data points " () {
31+ def " registers exactly 18 OTel-named JVM runtime metrics " () {
3232 when :
3333 JvmOtlpRuntimeMetrics . start()
3434 def collector = new MetricCollector ()
3535 OtelMetricRegistry . INSTANCE . collectMetrics(collector)
3636
3737 then :
38- // OtelInstrumentDescriptor.name is UTF8BytesString, convert to String for comparison
3938 def names = collector. metricNames. collect { it. toString() }
40- // Memory (5 metrics, all UpDownCounter per spec)
41- " jvm.memory.used" in names
42- " jvm.memory.committed" in names
43- " jvm.memory.limit" in names
44- " jvm.memory.init" in names
45- " jvm.memory.used_after_last_gc" in names
46- // Buffers (3 metrics, UpDownCounter per spec)
47- " jvm.buffer.memory.used" in names
48- " jvm.buffer.memory.limit" in names
49- " jvm.buffer.count" in names
50- // Threads (1 metric, UpDownCounter per spec)
51- " jvm.thread.count" in names
52- // Classes (3 metrics: loaded/unloaded are Counter, count is UpDownCounter per spec)
53- " jvm.class.loaded" in names
54- " jvm.class.count" in names
55- " jvm.class.unloaded" in names
56- // CPU (4 metrics per spec)
57- " jvm.cpu.time" in names
58- " jvm.cpu.count" in names
59- " jvm.cpu.recent_utilization" in names
60- " jvm.system.cpu.utilization" in names
61- // NOT included: jvm.gc.duration (spec requires Histogram, JMX can't produce it)
62- // NOT included: jvm.gc.count (not in OTel spec)
39+
40+ def expectedMetrics = [
41+ // Memory (5 metrics)
42+ " jvm.memory.used" ,
43+ " jvm.memory.committed" ,
44+ " jvm.memory.limit" ,
45+ " jvm.memory.init" ,
46+ " jvm.memory.used_after_last_gc" ,
47+ // Buffers (3 metrics)
48+ " jvm.buffer.memory.used" ,
49+ " jvm.buffer.memory.limit" ,
50+ " jvm.buffer.count" ,
51+ // Threads (1 metric)
52+ " jvm.thread.count" ,
53+ // Classes (3 metrics)
54+ " jvm.class.loaded" ,
55+ " jvm.class.count" ,
56+ " jvm.class.unloaded" ,
57+ // CPU (4 metrics)
58+ " jvm.cpu.time" ,
59+ " jvm.cpu.count" ,
60+ " jvm.cpu.recent_utilization" ,
61+ " jvm.system.cpu.utilization" ,
62+ // File descriptors (2 metrics)
63+ " jvm.file_descriptor.count" ,
64+ " jvm.file_descriptor.limit" ,
65+ ]
66+
67+ for (metric in expectedMetrics) {
68+ assert metric in names : " Expected metric '${ metric} ' not found. Got: ${ names.sort()} "
69+ }
70+
71+ names. size() == 18
72+
73+ // No DD-proprietary names should be present
74+ def ddNames = names. findAll { it. startsWith(" jvm.heap_memory" ) || it. startsWith(" jvm.thread_count" ) }
75+ ddNames. isEmpty()
6376 }
6477
6578 def " jvm.memory.used has heap and non_heap type attributes" () {
0 commit comments