55
66package io .opentelemetry .contrib .jmxscraper .target_systems ;
77
8+ import static io .opentelemetry .contrib .jmxscraper .assertions .DataPointAttributes .attribute ;
9+ import static io .opentelemetry .contrib .jmxscraper .assertions .DataPointAttributes .attributeGroup ;
10+
811import io .opentelemetry .contrib .jmxscraper .JmxScraperContainer ;
912import io .opentelemetry .contrib .jmxscraper .TestAppContainer ;
13+ import io .opentelemetry .contrib .jmxscraper .assertions .AttributeMatcherGroup ;
1014import java .nio .file .Path ;
11- import java .util .Arrays ;
12- import java .util .List ;
1315import org .testcontainers .containers .GenericContainer ;
1416import org .testcontainers .containers .wait .strategy .Wait ;
1517
@@ -34,15 +36,16 @@ protected JmxScraperContainer customizeScraperContainer(
3436 @ Override
3537 protected MetricsVerifier createMetricsVerifier () {
3638 // those values depend on the JVM GC configured
37- List < String > gcLabels =
38- Arrays . asList (
39+ AttributeMatcherGroup [] memoryAttributes =
40+ nameAttributeMatchers (
3941 "Code Cache" ,
4042 "PS Eden Space" ,
4143 "PS Old Gen" ,
4244 "Metaspace" ,
4345 "Compressed Class Space" ,
4446 "PS Survivor Space" );
45- List <String > gcCollectionLabels = Arrays .asList ("PS MarkSweep" , "PS Scavenge" );
47+ AttributeMatcherGroup [] gcAlgorithmAttributes =
48+ nameAttributeMatchers ("PS MarkSweep" , "PS Scavenge" );
4649
4750 return MetricsVerifier .create ()
4851 .add (
@@ -60,7 +63,7 @@ protected MetricsVerifier createMetricsVerifier() {
6063 .hasDescription ("total number of collections that have occurred" )
6164 .hasUnit ("1" )
6265 .isCounter ()
63- .hasTypedDataPoints ( gcCollectionLabels ))
66+ .hasDataPointsWithAttributes ( gcAlgorithmAttributes ))
6467 .add (
6568 "jvm.gc.collections.elapsed" ,
6669 metric ->
@@ -69,7 +72,7 @@ protected MetricsVerifier createMetricsVerifier() {
6972 "the approximate accumulated collection elapsed time in milliseconds" )
7073 .hasUnit ("ms" )
7174 .isCounter ()
72- .hasTypedDataPoints ( gcCollectionLabels ))
75+ .hasDataPointsWithAttributes ( gcAlgorithmAttributes ))
7376 .add (
7477 "jvm.memory.heap.committed" ,
7578 metric ->
@@ -141,31 +144,31 @@ protected MetricsVerifier createMetricsVerifier() {
141144 .hasDescription ("current memory pool usage" )
142145 .hasUnit ("by" )
143146 .isGauge ()
144- .hasTypedDataPoints ( gcLabels ))
147+ .hasDataPointsWithAttributes ( memoryAttributes ))
145148 .add (
146149 "jvm.memory.pool.init" ,
147150 metric ->
148151 metric
149152 .hasDescription ("current memory pool usage" )
150153 .hasUnit ("by" )
151154 .isGauge ()
152- .hasTypedDataPoints ( gcLabels ))
155+ .hasDataPointsWithAttributes ( memoryAttributes ))
153156 .add (
154157 "jvm.memory.pool.max" ,
155158 metric ->
156159 metric
157160 .hasDescription ("current memory pool usage" )
158161 .hasUnit ("by" )
159162 .isGauge ()
160- .hasTypedDataPoints ( gcLabels ))
163+ .hasDataPointsWithAttributes ( memoryAttributes ))
161164 .add (
162165 "jvm.memory.pool.used" ,
163166 metric ->
164167 metric
165168 .hasDescription ("current memory pool usage" )
166169 .hasUnit ("by" )
167170 .isGauge ()
168- .hasTypedDataPoints ( gcLabels ))
171+ .hasDataPointsWithAttributes ( memoryAttributes ))
169172 .add (
170173 "jvm.threads.count" ,
171174 metric ->
@@ -175,4 +178,12 @@ protected MetricsVerifier createMetricsVerifier() {
175178 .isGauge ()
176179 .hasDataPointsWithoutAttributes ());
177180 }
181+
182+ private static AttributeMatcherGroup [] nameAttributeMatchers (String ... values ) {
183+ AttributeMatcherGroup [] groups = new AttributeMatcherGroup [values .length ];
184+ for (int i = 0 ; i < values .length ; i ++) {
185+ groups [i ] = attributeGroup (attribute ("name" , values [i ]));
186+ }
187+ return groups ;
188+ }
178189}
0 commit comments