-
Notifications
You must be signed in to change notification settings - Fork 168
Integration test activemq #1497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
49cfb99
a8f8ace
e1043d1
5948f57
7f7681b
93bf770
ac67d0f
97038df
67a50a0
26efa72
edb3d6e
3a36466
70d0bb0
12e6533
172846c
898c3c8
da8f4d8
2260258
59e1e6f
df4e149
80f5e88
055813c
9d6fd15
5b046cb
36bc5aa
3f7d02f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.contrib.jmxscraper; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.Socket; | ||
| import java.util.Random; | ||
|
|
||
| /** Class used for finding random free network port from range 1024-65535 */ | ||
| public class PortSelector { | ||
| private static final Random random = new Random(System.currentTimeMillis()); | ||
|
|
||
| private static final int MIN_PORT = 1024; | ||
| private static final int MAX_PORT = 65535; | ||
|
|
||
| private PortSelector() {} | ||
|
|
||
| /** | ||
| * @return random available TCP port | ||
| */ | ||
| public static synchronized int getAvailableRandomPort() { | ||
| int port; | ||
|
|
||
| do { | ||
| port = random.nextInt(MAX_PORT - MIN_PORT + 1) + MIN_PORT; | ||
| } while (!isPortAvailable(port)); | ||
|
|
||
| return port; | ||
| } | ||
|
|
||
| private static boolean isPortAvailable(int port) { | ||
| // see https://stackoverflow.com/a/13826145 for the chosen implementation | ||
| try (Socket s = new Socket("localhost", port)) { | ||
| return false; | ||
| } catch (IOException e) { | ||
| return true; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.contrib.jmxscraper.target_systems; | ||
|
|
||
| import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGaugeWithAttributes; | ||
| import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; | ||
| import static org.assertj.core.api.Assertions.entry; | ||
|
|
||
| import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; | ||
| import java.time.Duration; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.images.builder.ImageFromDockerfile; | ||
| import org.testcontainers.utility.MountableFile; | ||
|
|
||
| public class ActiveMqIntegrationTest extends TargetSystemIntegrationTest { | ||
|
|
||
| @Override | ||
| protected GenericContainer<?> createTargetContainer(int jmxPort) { | ||
| return new GenericContainer<>( | ||
| new ImageFromDockerfile() | ||
| .withDockerfileFromBuilder( | ||
| builder -> builder.from("apache/activemq-classic:5.18.6").build())) | ||
| .withEnv("LOCAL_JMX", "no") | ||
| .withCopyFileToContainer( | ||
| MountableFile.forClasspathResource("activemq/env"), "/opt/apache-activemq/bin/env") | ||
|
||
| .withEnv( | ||
| "ACTIVEMQ_JMX_OPTS", | ||
| "-Dcom.sun.management.jmxremote.port=" | ||
| + jmxPort | ||
| + " -Dcom.sun.management.jmxremote.rmi.port=" | ||
| + jmxPort | ||
| + " -Dcom.sun.management.jmxremote.ssl=false" | ||
| + " -Dcom.sun.management.jmxremote.authenticate=false") | ||
| .withStartupTimeout(Duration.ofMinutes(2)) | ||
| .waitingFor(Wait.forListeningPort()); | ||
| } | ||
|
|
||
| @Override | ||
| protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { | ||
| return scraper.withTargetSystem("activemq"); | ||
| } | ||
|
|
||
| @Override | ||
| protected void verifyMetrics() { | ||
| waitAndAssertMetrics( | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.consumer.count", | ||
| "The number of consumers currently reading from the broker.", | ||
| "consumers", | ||
| /* isMonotonic= */ false, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] isMonotonic=false was added due to updatedDefinition of asserSumWithAttributes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all of the 3 metrics that are non-monotonic here I think it was probably a bug in the original test of the groovy version. The fact that they all have |
||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.producer.count", | ||
| "The number of producers currently attached to the broker.", | ||
| "producers", | ||
| /* isMonotonic= */ false, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] isMonotonic=false was added due to updatedDefinition of asserSumWithAttributes. |
||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.connection.count", | ||
| "The total number of current connections.", | ||
| "connections", | ||
| /* isMonotonic= */ false, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] isMonotonic=false was added due to updatedDefinition of asserSumWithAttributes. |
||
| attrs -> attrs.containsOnly(entry("broker", "localhost"))), | ||
| metric -> | ||
| assertGaugeWithAttributes( | ||
| metric, | ||
| "activemq.memory.usage", | ||
| "The percentage of configured memory used.", | ||
| "%", | ||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertGaugeWithAttributes( | ||
| metric, | ||
| "activemq.disk.store_usage", | ||
| "The percentage of configured disk used for persistent messages.", | ||
| "%", | ||
| attrs -> attrs.containsOnly(entry("broker", "localhost"))), | ||
| metric -> | ||
| assertGaugeWithAttributes( | ||
| metric, | ||
| "activemq.disk.temp_usage", | ||
| "The percentage of configured disk used for non-persistent messages.", | ||
| "%", | ||
| attrs -> attrs.containsOnly(entry("broker", "localhost"))), | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.message.current", | ||
| "The current number of messages waiting to be consumed.", | ||
| "messages", | ||
| /* isMonotonic= */ false, | ||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.message.expired", | ||
| "The total number of messages not delivered because they expired.", | ||
| "messages", | ||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.message.enqueued", | ||
| "The total number of messages received by the broker.", | ||
| "messages", | ||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertSumWithAttributes( | ||
| metric, | ||
| "activemq.message.dequeued", | ||
| "The total number of messages delivered to consumers.", | ||
| "messages", | ||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost"))), | ||
| metric -> | ||
| assertGaugeWithAttributes( | ||
| metric, | ||
| "activemq.message.wait_time.avg", | ||
| "The average time a message was held on a destination.", | ||
| "ms", | ||
| attrs -> | ||
| attrs.containsOnly( | ||
| entry("destination", "ActiveMQ.Advisory.MasterBroker"), | ||
| entry("broker", "localhost")))); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] Updated activemq docker image to the most recent ActiveMQ Classic version (from rmohr/activemq:5.15.9 used in JMX Metric Gatherer)