55
66package io .opentelemetry .instrumentation .jmx .rules ;
77
8- import static io .opentelemetry .instrumentation .jmx .rules .assertions .DataPointAttributes .attributeGroup ;
98import static io .opentelemetry .instrumentation .jmx .rules .assertions .DataPointAttributes .attributeWithAnyValue ;
109
11- import io .opentelemetry .instrumentation .jmx .rules .assertions .AttributeMatcherGroup ;
10+ import io .opentelemetry .instrumentation .jmx .rules .assertions .AttributeMatcher ;
1211import java .time .Duration ;
1312import java .util .ArrayList ;
1413import java .util .Arrays ;
@@ -76,16 +75,6 @@ void testCollectedMetrics(int jettyMajorVersion) {
7675
7776 private static MetricsVerifier createMetricsVerifier (int jettyMajorVersion ) {
7877
79- AttributeMatcherGroup threadPoolAttributes ;
80- if (jettyMajorVersion >= 12 ) {
81- threadPoolAttributes =
82- attributeGroup (
83- attributeWithAnyValue ("jetty.thread.pool.id" ),
84- attributeWithAnyValue ("jetty.thread.context" ));
85- } else {
86- threadPoolAttributes = attributeGroup (attributeWithAnyValue ("jetty.thread.pool.id" ));
87- }
88-
8978 MetricsVerifier verifier =
9079 MetricsVerifier .create ()
9180 .add (
@@ -95,51 +84,49 @@ private static MetricsVerifier createMetricsVerifier(int jettyMajorVersion) {
9584 .isUpDownCounter ()
9685 .hasDescription ("The current number of threads" )
9786 .hasUnit ("{thread}" )
98- .hasDataPointsWithAttributes ( threadPoolAttributes ))
87+ .hasDataPointsWithoutAttributes ( ))
9988 .add (
10089 "jetty.thread.limit" ,
10190 metric ->
10291 metric
10392 .isUpDownCounter ()
10493 .hasDescription ("The configured maximum number of threads in the pool" )
10594 .hasUnit ("{thread}" )
106- .hasDataPointsWithAttributes ( threadPoolAttributes ))
95+ .hasDataPointsWithoutAttributes ( ))
10796 .add (
10897 "jetty.thread.idle.count" ,
10998 metric ->
11099 metric
111100 .isUpDownCounter ()
112101 .hasDescription ("The current number of idle threads" )
113102 .hasUnit ("{thread}" )
114- .hasDataPointsWithAttributes ( threadPoolAttributes ))
103+ .hasDataPointsWithoutAttributes ( ))
115104 .add (
116105 "jetty.thread.busy.count" ,
117106 metric ->
118107 metric
119108 .isUpDownCounter ()
120109 .hasDescription ("The current number of busy threads" )
121110 .hasUnit ("{thread}" )
122- .hasDataPointsWithAttributes ( threadPoolAttributes ))
111+ .hasDataPointsWithoutAttributes ( ))
123112 .add (
124113 "jetty.thread.queue.size" ,
125114 metric ->
126115 metric
127116 .isUpDownCounter ()
128117 .hasDescription ("The current job queue size" )
129118 .hasUnit ("{thread}" )
130- .hasDataPointsWithAttributes ( threadPoolAttributes ))
119+ .hasDataPointsWithoutAttributes ( ))
131120 .add (
132121 "jetty.select.count" ,
133122 metric ->
134123 metric
135124 .isCounter ()
136125 .hasDescription ("The number of select calls" )
137126 .hasUnit ("{operation}" )
138- .hasDataPointsWithAttributes (
139- attributeGroup (
140- attributeWithAnyValue ("jetty.selector.id" ),
141- attributeWithAnyValue ("jetty.selector.context" ))));
127+ .hasDataPointsWithoutAttributes ());
142128
129+ AttributeMatcher contextAttribute = attributeWithAnyValue ("jetty.context" );
143130 if (jettyMajorVersion >= 12 ) {
144131 verifier
145132 .add (
@@ -149,21 +136,15 @@ private static MetricsVerifier createMetricsVerifier(int jettyMajorVersion) {
149136 .isUpDownCounter ()
150137 .hasDescription ("Current number of active sessions" )
151138 .hasUnit ("{session}" )
152- .hasDataPointsWithAttributes (
153- attributeGroup (
154- attributeWithAnyValue ("jetty.context" ),
155- attributeWithAnyValue ("jetty.session.cache.id" ))))
139+ .hasDataPointsWithOneAttribute (contextAttribute ))
156140 .add (
157141 "jetty.session.count.max" ,
158142 metric ->
159143 metric
160144 .isGauge ()
161145 .hasDescription ("Maximum number of active sessions" )
162146 .hasUnit ("{session}" )
163- .hasDataPointsWithAttributes (
164- attributeGroup (
165- attributeWithAnyValue ("jetty.context" ),
166- attributeWithAnyValue ("jetty.session.cache.id" ))));
147+ .hasDataPointsWithOneAttribute (contextAttribute ));
167148 } else {
168149 verifier
169150 .add (
@@ -173,43 +154,31 @@ private static MetricsVerifier createMetricsVerifier(int jettyMajorVersion) {
173154 .isCounter ()
174155 .hasDescription ("The total number of created sessions" )
175156 .hasUnit ("{session}" )
176- .hasDataPointsWithAttributes (
177- attributeGroup (
178- attributeWithAnyValue ("jetty.context" ),
179- attributeWithAnyValue ("jetty.session.handler.id" ))))
157+ .hasDataPointsWithOneAttribute (contextAttribute ))
180158 .add (
181159 "jetty.session.duration.sum" ,
182160 metric ->
183161 metric
184162 .isCounter ()
185163 .hasDescription ("The cumulated session duration" )
186164 .hasUnit ("s" )
187- .hasDataPointsWithAttributes (
188- attributeGroup (
189- attributeWithAnyValue ("jetty.context" ),
190- attributeWithAnyValue ("jetty.session.handler.id" ))))
165+ .hasDataPointsWithOneAttribute (contextAttribute ))
191166 .add (
192167 "jetty.session.duration.max" ,
193168 metric ->
194169 metric
195170 .isGauge ()
196171 .hasDescription ("The maximum session duration" )
197172 .hasUnit ("s" )
198- .hasDataPointsWithAttributes (
199- attributeGroup (
200- attributeWithAnyValue ("jetty.context" ),
201- attributeWithAnyValue ("jetty.session.handler.id" ))))
173+ .hasDataPointsWithOneAttribute (contextAttribute ))
202174 .add (
203175 "jetty.session.duration.mean" ,
204176 metric ->
205177 metric
206178 .isGauge ()
207179 .hasDescription ("The mean session duration" )
208180 .hasUnit ("s" )
209- .hasDataPointsWithAttributes (
210- attributeGroup (
211- attributeWithAnyValue ("jetty.context" ),
212- attributeWithAnyValue ("jetty.session.handler.id" ))));
181+ .hasDataPointsWithOneAttribute (contextAttribute ));
213182 }
214183 return verifier ;
215184 }
0 commit comments