99import static io .opentelemetry .instrumentation .jmx .rules .assertions .DataPointAttributes .attributeGroup ;
1010import static io .opentelemetry .instrumentation .jmx .rules .assertions .DataPointAttributes .attributeWithAnyValue ;
1111
12+ import io .opentelemetry .instrumentation .jmx .rules .assertions .AttributeMatcher ;
1213import java .time .Duration ;
1314import java .util .ArrayList ;
1415import java .util .Collections ;
1516import java .util .List ;
1617import org .junit .jupiter .params .ParameterizedTest ;
17- import org .junit .jupiter .params .provider .ValueSource ;
18+ import org .junit .jupiter .params .provider .CsvSource ;
1819import org .testcontainers .containers .GenericContainer ;
1920import org .testcontainers .containers .wait .strategy .Wait ;
2021
2122public class TomcatIntegrationTest extends TargetSystemTest {
2223
2324 @ ParameterizedTest
24- @ ValueSource (
25- strings = {
26- "tomcat:10.0" ,
27- "tomcat:9.0"
28- } )
29- void testCollectedMetrics ( String dockerImageName ) throws Exception {
25+ @ CsvSource ({
26+ "tomcat:10.0, https://tomcat.apache.org/tomcat-10.0-doc/appdev/sample/sample.war" ,
27+ "tomcat:9.0, https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war"
28+ })
29+ void testCollectedMetrics ( String dockerImageName , String sampleWebApplicationURL )
30+ throws Exception {
3031 List <String > yamlFiles = Collections .singletonList ("tomcat.yaml" );
3132
3233 yamlFiles .forEach (this ::validateYamlSyntax );
@@ -46,11 +47,19 @@ void testCollectedMetrics(String dockerImageName) throws Exception {
4647 copyFilesToTarget (target , yamlFiles );
4748
4849 startTarget (target );
50+ target .execInContainer ("rm" , "-fr" , "/usr/local/tomcat/webapps/ROOT" );
51+ target .execInContainer (
52+ "curl" , sampleWebApplicationURL , "-o" , "/usr/local/tomcat/webapps/ROOT.war" );
4953
5054 verifyMetrics (createMetricsVerifier ());
5155 }
5256
5357 private static MetricsVerifier createMetricsVerifier () {
58+ AttributeMatcher requestProcessorNameAttribute =
59+ attribute ("tomcat.request_processor.name" , "\" http-nio-8080\" " );
60+ AttributeMatcher threadPoolNameAttribute =
61+ attribute ("tomcat.thread_pool.name" , "\" http-nio-8080\" " );
62+
5463 return MetricsVerifier .create ()
5564 .add (
5665 "tomcat.error.count" ,
@@ -59,46 +68,45 @@ private static MetricsVerifier createMetricsVerifier() {
5968 .hasDescription ("The number of errors." )
6069 .hasUnit ("{error}" )
6170 .isCounter ()
62- .hasDataPointsWithOneAttribute (attribute ( "tomcat.request_processor.name" , " \" http-nio-8080 \" " ) ))
71+ .hasDataPointsWithOneAttribute (requestProcessorNameAttribute ))
6372 .add (
6473 "tomcat.request.count" ,
6574 metric ->
6675 metric
6776 .hasDescription ("The number of requests processed." )
6877 .hasUnit ("{request}" )
6978 .isCounter ()
70- .hasDataPointsWithOneAttribute (attribute ( "tomcat.request_processor.name" , " \" http-nio-8080 \" " ) ))
79+ .hasDataPointsWithOneAttribute (requestProcessorNameAttribute ))
7180 .add (
7281 "tomcat.request.duration.max" ,
7382 metric ->
7483 metric
7584 .hasDescription ("The longest request processing time." )
7685 .hasUnit ("s" )
7786 .isGauge ()
78- .hasDataPointsWithOneAttribute (attribute ( "tomcat.request_processor.name" , " \" http-nio-8080 \" " ) ))
87+ .hasDataPointsWithOneAttribute (requestProcessorNameAttribute ))
7988 .add (
8089 "tomcat.request.processing_time" ,
8190 metric ->
8291 metric
8392 .hasDescription ("Total time for processing all requests." )
8493 .hasUnit ("s" )
8594 .isCounter ()
86- .hasDataPointsWithOneAttribute (attribute ( "tomcat.request_processor.name" , " \" http-nio-8080 \" " ) ))
95+ .hasDataPointsWithOneAttribute (requestProcessorNameAttribute ))
8796 .add (
8897 "tomcat.network.io" ,
8998 metric ->
9099 metric
91- .hasDescription ("The number of bytes transmitted and received " )
100+ .hasDescription ("The number of bytes transmitted. " )
92101 .hasUnit ("By" )
93102 .isCounter ()
94103 .hasDataPointsWithAttributes (
95104 attributeGroup (
96105 attribute ("tomcat.network.io.direction" , "sent" ),
97- attribute ( "tomcat.request_processor.name" , " \" http-nio-8080 \" " ) ),
106+ requestProcessorNameAttribute ),
98107 attributeGroup (
99108 attribute ("tomcat.network.io.direction" , "received" ),
100- attribute ("tomcat.request_processor.name" , "\" http-nio-8080\" " ))))
101-
109+ requestProcessorNameAttribute )))
102110 .add (
103111 "tomcat.active_session.count" ,
104112 metric ->
@@ -107,7 +115,6 @@ private static MetricsVerifier createMetricsVerifier() {
107115 .hasUnit ("{session}" )
108116 .isUpDownCounter ()
109117 .hasDataPointsWithOneAttribute (attributeWithAnyValue ("tomcat.web_app_context" )))
110-
111118 .add (
112119 "tomcat.thread.count" ,
113120 metric ->
@@ -117,11 +124,8 @@ private static MetricsVerifier createMetricsVerifier() {
117124 .isUpDownCounter ()
118125 .hasDataPointsWithAttributes (
119126 attributeGroup (
120- attribute ("state" , "idle" ),
121- attribute ("tomcat.thread_pool.name" , "\" http-nio-8080\" " )),
127+ attribute ("tomcat.thread.state" , "idle" ), threadPoolNameAttribute ),
122128 attributeGroup (
123- attribute ("state" , "busy" ),
124- attribute ("tomcat.thread_pool.name" , "\" http-nio-8080\" " ))));
125-
129+ attribute ("tomcat.thread.state" , "busy" ), threadPoolNameAttribute )));
126130 }
127131}
0 commit comments