Skip to content

Commit f8c7cb4

Browse files
Integration test activemq (#1497)
Co-authored-by: Sylvain Juge <[email protected]>
1 parent e464516 commit f8c7cb4

File tree

5 files changed

+251
-2
lines changed

5 files changed

+251
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.jmxscraper.target_systems;
7+
8+
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGaugeWithAttributes;
9+
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes;
10+
import static org.assertj.core.api.Assertions.entry;
11+
12+
import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer;
13+
import java.time.Duration;
14+
import org.testcontainers.containers.GenericContainer;
15+
import org.testcontainers.containers.wait.strategy.Wait;
16+
import org.testcontainers.images.builder.ImageFromDockerfile;
17+
18+
public class ActiveMqIntegrationTest extends TargetSystemIntegrationTest {
19+
20+
@Override
21+
protected GenericContainer<?> createTargetContainer(int jmxPort) {
22+
return new GenericContainer<>(
23+
new ImageFromDockerfile()
24+
.withDockerfileFromBuilder(
25+
builder -> builder.from("apache/activemq-classic:5.18.6").build()))
26+
.withEnv(
27+
"JAVA_TOOL_OPTIONS",
28+
"-Dcom.sun.management.jmxremote.port="
29+
+ jmxPort
30+
+ " -Dcom.sun.management.jmxremote.rmi.port="
31+
+ jmxPort
32+
+ " -Dcom.sun.management.jmxremote.ssl=false"
33+
+ " -Dcom.sun.management.jmxremote.authenticate=false")
34+
.withStartupTimeout(Duration.ofMinutes(2))
35+
.waitingFor(Wait.forListeningPort());
36+
}
37+
38+
@Override
39+
protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) {
40+
return scraper.withTargetSystem("activemq");
41+
}
42+
43+
@Override
44+
protected void verifyMetrics() {
45+
waitAndAssertMetrics(
46+
metric ->
47+
assertSumWithAttributes(
48+
metric,
49+
"activemq.consumer.count",
50+
"The number of consumers currently reading from the broker.",
51+
"consumers",
52+
/* isMonotonic= */ false,
53+
attrs ->
54+
attrs.containsOnly(
55+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
56+
entry("broker", "localhost"))),
57+
metric ->
58+
assertSumWithAttributes(
59+
metric,
60+
"activemq.producer.count",
61+
"The number of producers currently attached to the broker.",
62+
"producers",
63+
/* isMonotonic= */ false,
64+
attrs ->
65+
attrs.containsOnly(
66+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
67+
entry("broker", "localhost"))),
68+
metric ->
69+
assertSumWithAttributes(
70+
metric,
71+
"activemq.connection.count",
72+
"The total number of current connections.",
73+
"connections",
74+
/* isMonotonic= */ false,
75+
attrs -> attrs.containsOnly(entry("broker", "localhost"))),
76+
metric ->
77+
assertGaugeWithAttributes(
78+
metric,
79+
"activemq.memory.usage",
80+
"The percentage of configured memory used.",
81+
"%",
82+
attrs ->
83+
attrs.containsOnly(
84+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
85+
entry("broker", "localhost"))),
86+
metric ->
87+
assertGaugeWithAttributes(
88+
metric,
89+
"activemq.disk.store_usage",
90+
"The percentage of configured disk used for persistent messages.",
91+
"%",
92+
attrs -> attrs.containsOnly(entry("broker", "localhost"))),
93+
metric ->
94+
assertGaugeWithAttributes(
95+
metric,
96+
"activemq.disk.temp_usage",
97+
"The percentage of configured disk used for non-persistent messages.",
98+
"%",
99+
attrs -> attrs.containsOnly(entry("broker", "localhost"))),
100+
metric ->
101+
assertSumWithAttributes(
102+
metric,
103+
"activemq.message.current",
104+
"The current number of messages waiting to be consumed.",
105+
"messages",
106+
/* isMonotonic= */ false,
107+
attrs ->
108+
attrs.containsOnly(
109+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
110+
entry("broker", "localhost"))),
111+
metric ->
112+
assertSumWithAttributes(
113+
metric,
114+
"activemq.message.expired",
115+
"The total number of messages not delivered because they expired.",
116+
"messages",
117+
attrs ->
118+
attrs.containsOnly(
119+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
120+
entry("broker", "localhost"))),
121+
metric ->
122+
assertSumWithAttributes(
123+
metric,
124+
"activemq.message.enqueued",
125+
"The total number of messages received by the broker.",
126+
"messages",
127+
attrs ->
128+
attrs.containsOnly(
129+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
130+
entry("broker", "localhost"))),
131+
metric ->
132+
assertSumWithAttributes(
133+
metric,
134+
"activemq.message.dequeued",
135+
"The total number of messages delivered to consumers.",
136+
"messages",
137+
attrs ->
138+
attrs.containsOnly(
139+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
140+
entry("broker", "localhost"))),
141+
metric ->
142+
assertGaugeWithAttributes(
143+
metric,
144+
"activemq.message.wait_time.avg",
145+
"The average time a message was held on a destination.",
146+
"ms",
147+
attrs ->
148+
attrs.containsOnly(
149+
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
150+
entry("broker", "localhost"))));
151+
}
152+
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,23 @@ static void assertSumWithAttributes(
7272
String description,
7373
String unit,
7474
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
75+
assertSumWithAttributes(
76+
metric, name, description, unit, /* isMonotonic= */ true, attributeGroupAssertions);
77+
}
78+
79+
@SafeVarargs
80+
static void assertSumWithAttributes(
81+
Metric metric,
82+
String name,
83+
String description,
84+
String unit,
85+
boolean isMonotonic,
86+
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
7587
assertThat(metric.getName()).isEqualTo(name);
7688
assertThat(metric.getDescription()).isEqualTo(description);
7789
assertThat(metric.getUnit()).isEqualTo(unit);
7890
assertThat(metric.hasSum()).isTrue();
91+
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic);
7992
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions);
8093
}
8194

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

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
3030
"https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war",
3131
"/usr/local/tomcat/webapps/ROOT.war")
3232
.build()))
33-
.withEnv("LOCAL_JMX", "no")
3433
.withEnv(
3534
"CATALINA_OPTS",
3635
"-Dcom.sun.management.jmxremote.local.only=false"

jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void main(String[] args) {
7878
System.err.println("Unable to connect " + e.getMessage());
7979
System.exit(2);
8080
} catch (RuntimeException e) {
81-
System.err.println("ERROR: " + e.getMessage());
81+
e.printStackTrace(System.err);
8282
System.exit(3);
8383
}
8484
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
rules:
3+
- beans:
4+
- org.apache.activemq:type=Broker,brokerName=*,destinationType=Queue,destinationName=*
5+
- org.apache.activemq:type=Broker,brokerName=*,destinationType=Topic,destinationName=*
6+
metricAttribute:
7+
destination: param(destinationName)
8+
broker: param(brokerName)
9+
prefix: activemq.
10+
mapping:
11+
ProducerCount:
12+
metric: producer.count
13+
# Unit name inherited from activemq.groovy file.
14+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
15+
unit: "producers"
16+
type: updowncounter
17+
desc: The number of producers currently attached to the broker.
18+
ConsumerCount:
19+
metric: consumer.count
20+
# Unit name inherited from activemq.groovy file.
21+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
22+
unit: "consumers"
23+
type: updowncounter
24+
desc: The number of consumers currently reading from the broker.
25+
MemoryPercentUsage:
26+
metric: memory.usage
27+
unit: "%"
28+
type: gauge
29+
desc: The percentage of configured memory used.
30+
QueueSize:
31+
metric: message.current
32+
# Unit name inherited from activemq.groovy file.
33+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
34+
unit: "messages"
35+
type: updowncounter
36+
desc: The current number of messages waiting to be consumed.
37+
ExpiredCount:
38+
metric: message.expired
39+
# Unit name inherited from activemq.groovy file.
40+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
41+
unit: "messages"
42+
type: counter
43+
desc: The total number of messages not delivered because they expired.
44+
EnqueueCount:
45+
metric: message.enqueued
46+
# Unit name inherited from activemq.groovy file.
47+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
48+
unit: "messages"
49+
type: counter
50+
desc: The total number of messages received by the broker.
51+
DequeueCount:
52+
metric: message.dequeued
53+
# Unit name inherited from activemq.groovy file.
54+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
55+
unit: "messages"
56+
type: counter
57+
desc: The total number of messages delivered to consumers.
58+
AverageEnqueueTime:
59+
metric: message.wait_time.avg
60+
unit: ms
61+
type: gauge
62+
desc: The average time a message was held on a destination.
63+
64+
- bean: org.apache.activemq:type=Broker,brokerName=*
65+
metricAttribute:
66+
# minor divergence from activemq.groovy to capture broker name, making it closer to
67+
# the definition in JMX Insights
68+
broker: param(brokerName)
69+
prefix: activemq.
70+
unit: "%"
71+
type: gauge
72+
mapping:
73+
CurrentConnectionsCount:
74+
metric: connection.count
75+
type: updowncounter
76+
# Unit name inherited from activemq.groovy file.
77+
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights
78+
unit: "connections"
79+
desc: The total number of current connections.
80+
StorePercentUsage:
81+
metric: disk.store_usage
82+
desc: The percentage of configured disk used for persistent messages.
83+
TempPercentUsage:
84+
metric: disk.temp_usage
85+
desc: The percentage of configured disk used for non-persistent messages.

0 commit comments

Comments
 (0)