-
Notifications
You must be signed in to change notification settings - Fork 129
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
Integration test activemq #1497
Changes from 25 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,158 @@ | ||
/* | ||
* 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( | ||
// Overwrite default ActiveMQ configuration in order to let ActiveMQ use JMX options | ||
// stored in $ACTIVEMQ_JMX_OPTS env variable defined below | ||
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. Maybe not for this PR, but do you know if there is a way to avoid adding the whole env file as an alternative ? For example could an env variable be used instead ? Or maybe as we are in a containers the Ideally if we don't have extra files to manage for those containers, the easier it gets to maintain them, even if I agree that this one does not seem very complicated. 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. This is actually a very good point. Replacing file with JAVA_TOOL_OPTIONS was trivial and worked. '''env''' file was used in jmx-metrics and ported here, but really was not needed. |
||
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")))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,10 +72,23 @@ static void assertSumWithAttributes( | |
String description, | ||
String unit, | ||
Consumer<MapAssert<String, String>>... attributeGroupAssertions) { | ||
assertSumWithAttributes( | ||
metric, name, description, unit, /* isMonotonic= */ true, attributeGroupAssertions); | ||
} | ||
|
||
@SafeVarargs | ||
static void assertSumWithAttributes( | ||
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] This override method is added to support 'monotonic' flag and metric attributes at he same time. |
||
Metric metric, | ||
String name, | ||
String description, | ||
String unit, | ||
boolean isMonotonic, | ||
Consumer<MapAssert<String, String>>... attributeGroupAssertions) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasSum()).isTrue(); | ||
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic); | ||
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ public static void main(String[] args) { | |
System.err.println("Unable to connect " + e.getMessage()); | ||
System.exit(2); | ||
} catch (RuntimeException e) { | ||
System.err.println("ERROR: " + e.getMessage()); | ||
e.printStackTrace(System.err); | ||
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. Simple printing Exception message is not enough here. We lose a lot of information regarding the issue. Stacktrace is better |
||
System.exit(3); | ||
} | ||
} | ||
|
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
rules: | ||
- beans: | ||
- org.apache.activemq:type=Broker,brokerName=*,destinationType=Queue,destinationName=* | ||
- org.apache.activemq:type=Broker,brokerName=*,destinationType=Topic,destinationName=* | ||
metricAttribute: | ||
destination: param(destinationName) | ||
broker: param(brokerName) | ||
prefix: activemq. | ||
mapping: | ||
ProducerCount: | ||
metric: producer.count | ||
# Unit name inherited from activemq.groovy file. | ||
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. [minor] for those adding a 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. Eventually we are going to use original *.yaml files from JMX Insights, right? I think we may not need to update this file and added these comments for informational purposes only. But if you have different opinion then I can add TODOs :-), not a problem. 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. Yes, those are likely to remain "as is", and regarding their location having them in a dedicated folder might also make sense when we reorganize but it's another topic. I'm just trying to not to forget about this, but a TODO here is probably not the best choice, it's probably better to add this to the issue where we listed all the supported systems for feature parity: open-telemetry/opentelemetry-java-instrumentation#12158 so I've updated it to ensure we don't forget about it. |
||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "producers" | ||
type: updowncounter | ||
desc: The number of producers currently attached to the broker. | ||
ConsumerCount: | ||
metric: consumer.count | ||
# Unit name inherited from activemq.groovy file. | ||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "consumers" | ||
type: updowncounter | ||
desc: The number of consumers currently reading from the broker. | ||
MemoryPercentUsage: | ||
metric: memory.usage | ||
unit: "%" | ||
type: gauge | ||
desc: The percentage of configured memory used. | ||
QueueSize: | ||
metric: message.current | ||
# Unit name inherited from activemq.groovy file. | ||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "messages" | ||
type: updowncounter | ||
desc: The current number of messages waiting to be consumed. | ||
ExpiredCount: | ||
metric: message.expired | ||
# Unit name inherited from activemq.groovy file. | ||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "messages" | ||
type: counter | ||
desc: The total number of messages not delivered because they expired. | ||
EnqueueCount: | ||
metric: message.enqueued | ||
# Unit name inherited from activemq.groovy file. | ||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "messages" | ||
type: counter | ||
desc: The total number of messages received by the broker. | ||
DequeueCount: | ||
metric: message.dequeued | ||
# Unit name inherited from activemq.groovy file. | ||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "messages" | ||
type: counter | ||
desc: The total number of messages delivered to consumers. | ||
AverageEnqueueTime: | ||
metric: message.wait_time.avg | ||
unit: ms | ||
type: gauge | ||
desc: The average time a message was held on a destination. | ||
|
||
- bean: org.apache.activemq:type=Broker,brokerName=* | ||
metricAttribute: | ||
# minor divergence from activemq.groovy to capture broker name, making it closer to | ||
# the definition in JMX Insights | ||
broker: param(brokerName) | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prefix: activemq. | ||
unit: "%" | ||
type: gauge | ||
mapping: | ||
CurrentConnectionsCount: | ||
metric: connection.count | ||
type: updowncounter | ||
# Unit name inherited from activemq.groovy file. | ||
# Will be updated to {} semconv notation when we switch to use original files from JMX Insights | ||
unit: "connections" | ||
desc: The total number of current connections. | ||
StorePercentUsage: | ||
metric: disk.store_usage | ||
desc: The percentage of configured disk used for persistent messages. | ||
TempPercentUsage: | ||
metric: disk.temp_usage | ||
desc: The percentage of configured disk used for non-persistent messages. |
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. Once we merge it will be good to update resources folder structure. I did not want to do too much in this PR. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/bin/sh | ||
# ------------------------------------------------------------------------ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------ | ||
# | ||
# Configuration file for running Apache Active MQ as standalone provider. | ||
# | ||
# This file overwrites the predefined settings of the sysv init-script. | ||
# You can also use alternate location for default settings - | ||
# invoke the init-script without a argument an review help section "Configuration of this script" | ||
# /etc/default/activemq <activemq user home>/.activemqrc <activemq installation dir>/bin/env | ||
|
||
# Active MQ installation dirs | ||
# ACTIVEMQ_HOME="<Installationdir>/" | ||
# ACTIVEMQ_BASE="$ACTIVEMQ_HOME" | ||
# ACTIVEMQ_CONF="$ACTIVEMQ_BASE/conf" | ||
# ACTIVEMQ_DATA="$ACTIVEMQ_BASE/data" | ||
# ACTIVEMQ_TMP="$ACTIVEMQ_BASE/tmp" | ||
|
||
# Set jvm memory configuration (minimal/maximum amount of memory) | ||
ACTIVEMQ_OPTS_MEMORY="-Xms64M -Xmx256M" | ||
|
||
if [ -z "$ACTIVEMQ_OPTS" ] ; then | ||
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config" | ||
fi | ||
|
||
if [ -z "$ACTIVEMQ_OUT" ]; then | ||
ACTIVEMQ_OUT="/dev/null" | ||
fi | ||
|
||
# Uncomment to enable audit logging | ||
#ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.audit=true" | ||
|
||
# Set jvm jmx configuration | ||
# This enables jmx access over a configured jmx-tcp-port. | ||
# You have to configure the first four settings if you run a ibm jvm, caused by the | ||
# fact that IBM's jvm does not support VirtualMachine.attach(PID). | ||
# JMX access is needed for quering a running activemq instance to gain data or to | ||
# trigger management operations. | ||
# | ||
# Example for ${ACTIVEMQ_CONF}/jmx.access: | ||
# --- | ||
# # The "monitorRole" role has readonly access. | ||
# # The "controlRole" role has readwrite access. | ||
# monitorRole readonly | ||
# controlRole readwrite | ||
# --- | ||
# | ||
# Example for ${ACTIVEMQ_CONF}/jmx.password: | ||
# --- | ||
# # The "monitorRole" role has password "abc123". | ||
# # # The "controlRole" role has password "abcd1234". | ||
# monitorRole abc123 | ||
# controlRole abcd1234 | ||
# --- | ||
# | ||
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.port=11099 " | ||
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password" | ||
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access" | ||
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false" | ||
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote" | ||
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote" | ||
|
||
# Set jvm jmx configuration for controlling the broker process | ||
# You only have to configure the first four settings if you run a ibm jvm, caused by the | ||
# fact that IBM's jvm does not support VirtualMachine.attach(PID) | ||
# (see also com.sun.management.jmxremote.port, .jmx.password.file and .jmx.access.file ) | ||
#ACTIVEMQ_SUNJMX_CONTROL="--jmxurl service:jmx:rmi:///jndi/rmi://127.0.0.1:1099/jmxrmi --jmxuser controlRole --jmxpassword abcd1234" | ||
ACTIVEMQ_SUNJMX_CONTROL="" | ||
|
||
# Specify the queue manager URL for using "browse" option of sysv initscript | ||
if [ -z "$ACTIVEMQ_QUEUEMANAGERURL" ]; then | ||
ACTIVEMQ_QUEUEMANAGERURL="--amqurl tcp://localhost:61616" | ||
fi | ||
|
||
# Set additional JSE arguments | ||
if [ -z "$ACTIVEMQ_SSL_OPTS" ] ; then | ||
#ACTIVEMQ_SSL_OPTS="-Djava.security.properties=$ACTIVEMQ_CONF/java.security" | ||
ACTIVEMQ_SSL_OPTS="" | ||
fi | ||
|
||
# Uncomment to enable remote debugging | ||
#ACTIVEMQ_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" | ||
|
||
# ActiveMQ tries to shutdown the broker by jmx, | ||
# after a specified number of seconds send SIGKILL | ||
if [ -z "$ACTIVEMQ_KILL_MAXSECONDS" ]; then | ||
ACTIVEMQ_KILL_MAXSECONDS=30 | ||
fi | ||
|
||
# Configure a user with non root privileges, if no user is specified do not change user | ||
# (the entire activemq installation should be owned by this user) | ||
ACTIVEMQ_USER="" | ||
|
||
# location of the pidfile | ||
# ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA/activemq.pid" | ||
|
||
# Location of the java installation | ||
# Specify the location of your java installation using JAVA_HOME, or specify the | ||
# path to the "java" binary using JAVACMD | ||
# (set JAVACMD to "auto" for automatic detection) | ||
#JAVA_HOME="" | ||
JAVACMD="auto" | ||
|
||
# Use JMX options defined in environment variable | ||
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_JMX_OPTS" |
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)