Skip to content

Commit 1027242

Browse files
committed
test for session metrics for jetty < 12
1 parent 7ccf852 commit 1027242

File tree

2 files changed

+137
-53
lines changed

2 files changed

+137
-53
lines changed

instrumentation/jmx-metrics/library/src/main/resources/jmx/rules/jetty.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,36 @@ rules:
7878
type: counter
7979
unit: "{operation}"
8080
desc: The number of select calls
81+
82+
- bean: org.eclipse.jetty.server.session:context=*,type=sessionhandler,id=*
83+
prefix: jetty.session.
84+
metricAttribute:
85+
jetty.context: param(context)
86+
jetty.session.handler.id: param(id)
87+
mapping:
88+
# jetty.session.created.count
89+
sessionsCreated:
90+
metric: created.count
91+
unit: "{session}"
92+
type: counter
93+
desc: The total number of created sessions
94+
# jetty.session.duration.sum
95+
sessionTimeTotal:
96+
metric: duration.sum
97+
unit: s
98+
type: counter
99+
desc: The cumulated session duration
100+
# jetty.session.duration.max
101+
sessionTimeMax:
102+
metric: duration.max
103+
unit: s
104+
# gauge because it can't be aggregated
105+
type: gauge
106+
desc: The maximum session duration
107+
# jetty.session.duration.mean
108+
sessionTimeMean:
109+
metric: duration.mean
110+
unit: s
111+
# gauge because it can't be aggregated
112+
type: gauge
113+
desc: The mean session duration

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/rules/JettyIntegrationTest.java

Lines changed: 104 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class JettyIntegrationTest extends TargetSystemTest {
2323

2424
private static final int JETTY_PORT = 8080;
2525

26-
@ParameterizedTest(name="jetty:{arguments}")
26+
@ParameterizedTest(name = "jetty:{arguments}")
2727
@ValueSource(ints = {9, 10, 11, 12})
2828
void testCollectedMetrics(int jettyMajorVersion) {
2929

@@ -78,57 +78,108 @@ private static MetricsVerifier createMetricsVerifier(int jettyMajorVersion) {
7878
threadPoolAttributes = attributeGroup(attributeWithAnyValue("jetty.thread.pool.id"));
7979
}
8080

81-
return MetricsVerifier.create()
82-
.add(
83-
"jetty.thread.count",
84-
metric ->
85-
metric
86-
.hasDescription("The current number of threads")
87-
.hasUnit("{thread}")
88-
.hasDataPointsWithAttributes(threadPoolAttributes)
89-
.isUpDownCounter())
90-
.add(
91-
"jetty.thread.limit",
92-
metric ->
93-
metric
94-
.hasDescription("The configured maximum number of threads in the pool")
95-
.hasUnit("{thread}")
96-
.hasDataPointsWithAttributes(threadPoolAttributes)
97-
.isUpDownCounter())
98-
.add(
99-
"jetty.thread.idle.count",
100-
metric ->
101-
metric
102-
.hasDescription("The current number of idle threads")
103-
.hasUnit("{thread}")
104-
.hasDataPointsWithAttributes(threadPoolAttributes)
105-
.isUpDownCounter())
106-
.add(
107-
"jetty.thread.busy.count",
108-
metric ->
109-
metric
110-
.hasDescription("The current number of busy threads")
111-
.hasUnit("{thread}")
112-
.hasDataPointsWithAttributes(threadPoolAttributes)
113-
.isUpDownCounter())
114-
.add(
115-
"jetty.thread.queue.size",
116-
metric ->
117-
metric
118-
.hasDescription("The current job queue size")
119-
.hasUnit("{thread}")
120-
.hasDataPointsWithAttributes(threadPoolAttributes)
121-
.isUpDownCounter())
122-
.add(
123-
"jetty.select.count",
124-
metric ->
125-
metric
126-
.hasDescription("The number of select calls")
127-
.hasUnit("{operation}")
128-
.hasDataPointsWithAttributes(
129-
attributeGroup(
130-
attributeWithAnyValue("jetty.selector.id"),
131-
attributeWithAnyValue("jetty.selector.context")))
132-
.isCounter());
81+
MetricsVerifier verifier =
82+
MetricsVerifier.create()
83+
.add(
84+
"jetty.thread.count",
85+
metric ->
86+
metric
87+
.isUpDownCounter()
88+
.hasDescription("The current number of threads")
89+
.hasUnit("{thread}")
90+
.hasDataPointsWithAttributes(threadPoolAttributes))
91+
.add(
92+
"jetty.thread.limit",
93+
metric ->
94+
metric
95+
.isUpDownCounter()
96+
.hasDescription("The configured maximum number of threads in the pool")
97+
.hasUnit("{thread}")
98+
.hasDataPointsWithAttributes(threadPoolAttributes))
99+
.add(
100+
"jetty.thread.idle.count",
101+
metric ->
102+
metric
103+
.isUpDownCounter()
104+
.hasDescription("The current number of idle threads")
105+
.hasUnit("{thread}")
106+
.hasDataPointsWithAttributes(threadPoolAttributes))
107+
.add(
108+
"jetty.thread.busy.count",
109+
metric ->
110+
metric
111+
.isUpDownCounter()
112+
.hasDescription("The current number of busy threads")
113+
.hasUnit("{thread}")
114+
.hasDataPointsWithAttributes(threadPoolAttributes))
115+
.add(
116+
"jetty.thread.queue.size",
117+
metric ->
118+
metric
119+
.isUpDownCounter()
120+
.hasDescription("The current job queue size")
121+
.hasUnit("{thread}")
122+
.hasDataPointsWithAttributes(threadPoolAttributes))
123+
.add(
124+
"jetty.select.count",
125+
metric ->
126+
metric
127+
.isCounter()
128+
.hasDescription("The number of select calls")
129+
.hasUnit("{operation}")
130+
.hasDataPointsWithAttributes(
131+
attributeGroup(
132+
attributeWithAnyValue("jetty.selector.id"),
133+
attributeWithAnyValue("jetty.selector.context"))));
134+
135+
if (jettyMajorVersion < 12) {
136+
verifier
137+
.add(
138+
"jetty.session.created.count",
139+
metric ->
140+
metric
141+
.isCounter()
142+
.hasDescription("The total number of created sessions")
143+
.hasUnit("{session}")
144+
.hasDataPointsWithAttributes(
145+
attributeGroup(
146+
attributeWithAnyValue("jetty.context"),
147+
attributeWithAnyValue("jetty.session.handler.id"))))
148+
.add(
149+
"jetty.session.duration.sum",
150+
metric ->
151+
metric
152+
.isCounter()
153+
.hasDescription("The cumulated session duration")
154+
.hasUnit("s")
155+
.hasDataPointsWithAttributes(
156+
attributeGroup(
157+
attributeWithAnyValue("jetty.context"),
158+
attributeWithAnyValue("jetty.session.handler.id"))))
159+
.add(
160+
"jetty.session.duration.max",
161+
metric ->
162+
metric
163+
.isGauge()
164+
.hasDescription("The maximum session duration")
165+
.hasUnit("s")
166+
.hasDataPointsWithAttributes(
167+
attributeGroup(
168+
attributeWithAnyValue("jetty.context"),
169+
attributeWithAnyValue("jetty.session.handler.id"))))
170+
.add(
171+
"jetty.session.duration.mean",
172+
metric ->
173+
metric
174+
.isGauge()
175+
.hasDescription("The mean session duration")
176+
.hasUnit("s")
177+
.hasDataPointsWithAttributes(
178+
attributeGroup(
179+
attributeWithAnyValue("jetty.context"),
180+
attributeWithAnyValue("jetty.session.handler.id"))));
181+
}
182+
183+
return verifier;
133184
}
134185
}

0 commit comments

Comments
 (0)