Skip to content

Commit 4299811

Browse files
committed
simplify metrics to the reliable ones
1 parent 7e8de22 commit 4299811

File tree

3 files changed

+15
-63
lines changed

3 files changed

+15
-63
lines changed

instrumentation/jmx-metrics/library/jetty.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ Those metrics require the following Jetty modules to be enabled : `jmx`, `http`,
1919
| jetty.thread.queue.size | UpDownCounter | | The current job queue size |
2020
| jetty.io.select.count | Counter | | The number of select calls |
2121
| jetty.session.count | UpDownCounter | jetty.context | Current number of active sessions |
22-
| jetty.session.count.max | Gauge | jetty.context | Maximum number of active sessions (*) |
2322

2423
- `jetty.context` corresponds to the deployed application subfolder in `webapps` folder.
25-
- `jetty.session.count.max` metric produces unpredictable values when more than one `org.eclipse.jetty.session:context=*,type=defaultsessioncache,id=*` MBean is present, the default Jetty deployment includes a single one.
2624

2725
## Jetty 9 to 11
2826

@@ -37,9 +35,6 @@ Those metrics require the following Jetty modules to be enabled : `jmx`, `http`
3735
| jetty.thread.queue.size | UpDownCounter | | The current job queue size |
3836
| jetty.io.select.count | Counter | | The number of select calls |
3937
| jetty.session.created.count | Counter | jetty.context | The total number of created sessions |
40-
| jetty.session.duration.sum | Gauge | jetty.context | The cumulated session duration |
41-
| jetty.session.duration.max | Gauge | jetty.context | The maximum session duration |
42-
| jetty.session.duration.mean | Gauge | jetty.context | The mean session duration |
38+
| jetty.session.duration.sum | Counter | jetty.context | The cumulated session duration |
4339

4440
- `jetty.context` corresponds to the deployed application subfolder in `webapps` folder.
45-
- `jetty.session.duration.sum`, `jetty.session.duration.max`, `jetty.session.duration.mean` metrics will produce unpredictable results when more than one `org.eclipse.jetty.server.session:context=*,type=sessionhandler,id=*` MBean is present, the default Jetty deployment includes a single one.

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ rules:
4444

4545
# Session metrics for Jetty 12
4646
- bean: org.eclipse.jetty.session:context=*,type=defaultsessioncache,id=*
47-
# usually a single mbean instance exists per context, thus the metric is aggregated: sum for counter,
48-
# gauge metrics will return invalid (last-value) if more than one mbean instance exists.
47+
# Usually a single mbean instance exists per context, thus the metric is aggregated: sum for counter,
48+
# gauge metrics will return invalid (last-value) with more than 1 mbean instance, thus none
49+
# is included in this provided configuration.
4950
prefix: jetty.session.
5051
unit: "{session}"
5152
metricAttribute:
@@ -57,17 +58,12 @@ rules:
5758
metric: count
5859
type: updowncounter
5960
desc: Current number of active sessions
60-
# jetty.session.count.max
61-
sessionsMax:
62-
metric: count.max
63-
# gauge because it can't be aggregated
64-
type: gauge
65-
desc: Maximum number of active sessions
6661

6762
# Session metrics for Jetty 9 to 11
6863
- bean: org.eclipse.jetty.server.session:context=*,type=sessionhandler,id=*
69-
# usually a single mbean instance exists per context, thus the metric is aggregated: sum for counter,
70-
# gauge metrics will return invalid (last-value) if more than one mbean instance exists.
64+
# Usually a single mbean instance exists per context, thus the metric is aggregated: sum for counter,
65+
# gauge metrics will return invalid (last-value) with more than 1 mbean instance, thus none
66+
# is included in this provided configuration.
7167
prefix: jetty.session.
7268
metricAttribute:
7369
# 'context' corresponds to the webapp context path
@@ -85,17 +81,3 @@ rules:
8581
unit: s
8682
type: counter
8783
desc: The cumulated session duration
88-
# jetty.session.duration.max
89-
sessionTimeMax:
90-
metric: duration.max
91-
unit: s
92-
# gauge because it can't be aggregated
93-
type: gauge
94-
desc: The maximum session duration
95-
# jetty.session.duration.mean
96-
sessionTimeMean:
97-
metric: duration.mean
98-
unit: s
99-
# gauge because it can't be aggregated
100-
type: gauge
101-
desc: The mean session duration

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

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,14 @@ private static MetricsVerifier createMetricsVerifier(int jettyMajorVersion) {
128128

129129
AttributeMatcher contextAttribute = attributeWithAnyValue("jetty.context");
130130
if (jettyMajorVersion >= 12) {
131-
verifier
132-
.add(
133-
"jetty.session.count",
134-
metric ->
135-
metric
136-
.isUpDownCounter()
137-
.hasDescription("Current number of active sessions")
138-
.hasUnit("{session}")
139-
.hasDataPointsWithOneAttribute(contextAttribute))
140-
.add(
141-
"jetty.session.count.max",
142-
metric ->
143-
metric
144-
.isGauge()
145-
.hasDescription("Maximum number of active sessions")
146-
.hasUnit("{session}")
147-
.hasDataPointsWithOneAttribute(contextAttribute));
131+
verifier.add(
132+
"jetty.session.count",
133+
metric ->
134+
metric
135+
.isUpDownCounter()
136+
.hasDescription("Current number of active sessions")
137+
.hasUnit("{session}")
138+
.hasDataPointsWithOneAttribute(contextAttribute));
148139
} else {
149140
verifier
150141
.add(
@@ -162,22 +153,6 @@ private static MetricsVerifier createMetricsVerifier(int jettyMajorVersion) {
162153
.isCounter()
163154
.hasDescription("The cumulated session duration")
164155
.hasUnit("s")
165-
.hasDataPointsWithOneAttribute(contextAttribute))
166-
.add(
167-
"jetty.session.duration.max",
168-
metric ->
169-
metric
170-
.isGauge()
171-
.hasDescription("The maximum session duration")
172-
.hasUnit("s")
173-
.hasDataPointsWithOneAttribute(contextAttribute))
174-
.add(
175-
"jetty.session.duration.mean",
176-
metric ->
177-
metric
178-
.isGauge()
179-
.hasDescription("The mean session duration")
180-
.hasUnit("s")
181156
.hasDataPointsWithOneAttribute(contextAttribute));
182157
}
183158
return verifier;

0 commit comments

Comments
 (0)