Skip to content

Commit 643618b

Browse files
committed
finally making it work !!
1 parent 8a735ef commit 643618b

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
package io.opentelemetry.contrib.jmxscraper.target_systems;
77

8+
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGauge;
89
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGaugeWithAttributes;
910
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes;
11+
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributesMultiplePoints;
1012

1113
import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer;
1214
import java.time.Duration;
@@ -72,28 +74,29 @@ protected void verifyMetrics() {
7274
"The maximum amount of time a session has been active.",
7375
"s",
7476
attrs -> attrs.containsKey("resource")),
75-
// metric ->
76-
// assertSumWithAttributes(metric,
77-
// "jetty.select.count",
78-
// "The number of select calls.",
79-
// "{operations}",
80-
// // minor divergence from jetty.groovy with extra metrics attributes
81-
// attrs -> attrs.containsKey("context"),
82-
// attrs -> attrs.containsKey("id")
83-
// ),
77+
metric ->
78+
assertSumWithAttributesMultiplePoints(metric,
79+
"jetty.select.count",
80+
"The number of select calls.",
81+
"{operations}",
82+
/* isMonotonic= */ true,
83+
// minor divergence from jetty.groovy with extra metrics attributes
84+
attrs -> attrs.containsKey("context").containsKey("id")
85+
),
8486
metric ->
8587
assertGaugeWithAttributes(
8688
metric,
8789
"jetty.thread.count",
8890
"The current number of threads.",
8991
"{threads}",
9092
attrs -> attrs.containsEntry("state", "busy"),
91-
attrs -> attrs.containsEntry("state", "idle"))/*,
93+
attrs -> attrs.containsEntry("state", "idle")),
9294
metric ->
9395
assertGauge(
9496
metric,
9597
"jetty.thread.queue.count",
9698
"The current number of threads in the queue.",
97-
"{threads}")*/);
99+
"{threads}"
100+
));
98101
}
99102
}

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ static void assertSumWithAttributes(
9292
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions);
9393
}
9494

95+
@SafeVarargs
96+
static void assertSumWithAttributesMultiplePoints(
97+
Metric metric,
98+
String name,
99+
String description,
100+
String unit,
101+
boolean isMonotonic,
102+
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
103+
assertThat(metric.getName()).isEqualTo(name);
104+
assertThat(metric.getDescription()).isEqualTo(description);
105+
assertThat(metric.getUnit()).isEqualTo(unit);
106+
assertThat(metric.hasSum()).isTrue();
107+
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic);
108+
assertAttributedMultiplePoints(metric.getSum().getDataPointsList(), attributeGroupAssertions);
109+
}
110+
95111
@SafeVarargs
96112
static void assertGaugeWithAttributes(
97113
Metric metric,
@@ -127,6 +143,7 @@ private static void assertAttributedPoints(
127143
Arrays.stream(attributeGroupAssertions)
128144
.map(assertion -> (Consumer<Map<String, String>>) m -> assertion.accept(assertThat(m)))
129145
.toArray(Consumer[]::new);
146+
130147
assertThat(points)
131148
.extracting(
132149
numberDataPoint ->
@@ -136,4 +153,19 @@ private static void assertAttributedPoints(
136153
KeyValue::getKey, keyValue -> keyValue.getValue().getStringValue())))
137154
.satisfiesExactlyInAnyOrder(assertions);
138155
}
156+
157+
@SuppressWarnings("unchecked")
158+
private static void assertAttributedMultiplePoints(
159+
List<NumberDataPoint> points,
160+
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
161+
162+
points.stream()
163+
.map(NumberDataPoint::getAttributesList)
164+
.forEach(kvList -> {
165+
Map<String, String> kvMap = kvList.stream()
166+
.collect(Collectors.toMap(KeyValue::getKey, kv -> kv.getValue().getStringValue()));
167+
Arrays.stream(attributeGroupAssertions)
168+
.forEach(assertion -> assertion.accept(assertThat(kvMap)));
169+
});
170+
}
139171
}

jmx-scraper/src/main/resources/jetty.yaml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
rules:
44

5-
# - bean: org.eclipse.jetty.io:context=*,type=managedselector,id=*
6-
# mapping:
7-
# selectCount:
8-
# metric: jetty.select.count
9-
# type: counter
10-
# unit: "{operations}"
11-
# desc: The number of select calls.
12-
# metricAttribute:
13-
# # minor divergence from jetty.groovy allowing to avoid warnings
14-
# # 'id' is a numerical value in [0,9] by default
15-
# # 'context' is a high cardinality value like 'HTTP_1_1@7674f035' but likely stable for the
16-
# # duration of the jetty process lifecycle
17-
# context: param(context)
18-
# id: param(id)
5+
- bean: org.eclipse.jetty.io:context=*,type=managedselector,id=*
6+
mapping:
7+
selectCount:
8+
metric: jetty.select.count
9+
type: counter
10+
unit: "{operations}"
11+
desc: The number of select calls.
12+
metricAttribute:
13+
# minor divergence from jetty.groovy with extra attribute(s)
14+
# 'id' is a numerical value in [0,9] by default
15+
# 'context' is a high cardinality value like 'HTTP_1_1@7674f035' but likely stable for the
16+
# duration of the jetty process lifecycle
17+
context: param(context)
18+
id: param(id)
1919

2020
- bean: org.eclipse.jetty.server.session:context=*,type=sessionhandler,id=*
2121
prefix: jetty.session.
@@ -40,6 +40,7 @@ rules:
4040
desc: The maximum amount of time a session has been active.
4141

4242
- bean: org.eclipse.jetty.util.thread:type=queuedthreadpool,id=*
43+
# here the 'id' can be ignored as it's usually a single value equal to '0'
4344
prefix: jetty.thread.
4445
unit: "{threads}"
4546
mapping:
@@ -57,7 +58,8 @@ rules:
5758
desc: The current number of threads.
5859
metricAttribute:
5960
state: const(idle)
60-
# queueSize:
61-
# metric: queue.count
62-
# # here an 'updowncounter' seems more appropriate but gauge reflects jetty.groovy impl.
63-
# type: gauge
61+
queueSize:
62+
metric: queue.count
63+
# here an 'updowncounter' seems more appropriate but gauge reflects jetty.groovy impl.
64+
type: gauge
65+
desc: The current number of threads in the queue.

0 commit comments

Comments
 (0)