You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/07/01 12:36:20 UTC
[activemq-artemis] branch master updated: ARTEMIS-2833 Fix metrics
configuration backwards compatibility
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/master by this push:
new d02f5db ARTEMIS-2833 Fix metrics configuration backwards compatibility
new 3b8ab97 This closes #3210
d02f5db is described below
commit d02f5db9b897072013c846704438530b9c6e2243
Author: brusdev <br...@gmail.com>
AuthorDate: Wed Jul 1 11:33:02 2020 +0200
ARTEMIS-2833 Fix metrics configuration backwards compatibility
---
.../deployers/impl/FileConfigurationParser.java | 24 +++----
.../artemis/core/server/ActiveMQServerLogger.java | 9 +++
.../core/config/impl/FileConfigurationTest.java | 74 ++++++++++++++++++++++
artemis-server/src/test/resources/metrics.xml | 33 ++++++++++
.../src/test/resources/metricsConflict.xml | 38 +++++++++++
.../src/test/resources/metricsPlugin.xml | 28 ++++++++
6 files changed, 195 insertions(+), 11 deletions(-)
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
index 7fe293b..6b77206 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
@@ -711,14 +711,6 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
parseBrokerPlugins(e, config);
- { // for backwards compatibility
- NodeList metricsPlugin = e.getElementsByTagName("metrics-plugin");
-
- if (metricsPlugin.getLength() != 0) {
- parseMetricsPlugin(metricsPlugin.item(0), config);
- }
- }
-
parseMetrics(e, config);
NodeList connectorServiceConfigs = e.getElementsByTagName("connector-service");
@@ -816,11 +808,12 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
* @param config
*/
private void parseMetrics(final Element e, final Configuration config) {
- NodeList elements = e.getElementsByTagName("metrics");
+ NodeList metrics = e.getElementsByTagName("metrics");
+ NodeList metricsPlugin = e.getElementsByTagName("metrics-plugin");
MetricsConfiguration metricsConfiguration = new MetricsConfiguration();
- if (elements.getLength() != 0) {
- Element node = (Element) elements.item(0);
+ if (metrics.getLength() != 0) {
+ Element node = (Element) metrics.item(0);
NodeList children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
@@ -834,6 +827,15 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
metricsConfiguration.setPlugin(parseMetricsPlugin(child, config));
}
}
+
+ if (metricsPlugin.getLength() != 0) {
+ ActiveMQServerLogger.LOGGER.metricsPluginElementIgnored();
+ }
+ } else { // for backwards compatibility
+ if (metricsPlugin.getLength() != 0) {
+ ActiveMQServerLogger.LOGGER.metricsPluginElementDeprecated();
+ metricsConfiguration.setPlugin(parseMetricsPlugin(metricsPlugin.item(0), config));
+ }
}
config.setMetricsConfiguration(metricsConfiguration);
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
index ced6ee4..3ae605e 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
@@ -1692,6 +1692,15 @@ public interface ActiveMQServerLogger extends BasicLogger {
format = Message.Format.MESSAGE_FORMAT)
void failedToFindClusterConnection(String packet);
+ @LogMessage(level = Logger.Level.WARN)
+ @Message(id = 222291, value = "The metrics-plugin element is deprecated and replaced by the metrics element", format = Message.Format.MESSAGE_FORMAT)
+ void metricsPluginElementDeprecated();
+
+ @LogMessage(level = Logger.Level.WARN)
+ @Message(id = 222292, value = "The metrics-plugin element is ignored because the metrics element is defined", format = Message.Format.MESSAGE_FORMAT)
+ void metricsPluginElementIgnored();
+
+
@LogMessage(level = Logger.Level.ERROR)
@Message(id = 224000, value = "Failure in initialisation", format = Message.Format.MESSAGE_FORMAT)
void initializationError(@Cause Throwable e);
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
index 6d41c8d..c43618c 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import io.micrometer.core.instrument.MeterRegistry;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
@@ -758,6 +759,60 @@ public class FileConfigurationTest extends ConfigurationImplTest {
}
}
+ @Test
+ public void testMetricsPlugin() throws Exception {
+ FileConfiguration fc = new FileConfiguration();
+ FileDeploymentManager deploymentManager = new FileDeploymentManager("metricsPlugin.xml");
+ deploymentManager.addDeployable(fc);
+ deploymentManager.readConfiguration();
+
+ ActiveMQMetricsPlugin metricPlugin = fc.getMetricsConfiguration().getPlugin();
+ assertTrue(metricPlugin instanceof FakeMetricPlugin);
+
+ Map<String, String> metricPluginOptions = ((FakeMetricPlugin)metricPlugin).getOptions();
+ assertEquals("value1", metricPluginOptions.get("key1"));
+ assertEquals("value2", metricPluginOptions.get("key2"));
+ assertEquals("value3", metricPluginOptions.get("key3"));
+ }
+
+ @Test
+ public void testMetrics() throws Exception {
+ FileConfiguration fc = new FileConfiguration();
+ FileDeploymentManager deploymentManager = new FileDeploymentManager("metrics.xml");
+ deploymentManager.addDeployable(fc);
+ deploymentManager.readConfiguration();
+
+
+ MetricsConfiguration metricsConfiguration = fc.getMetricsConfiguration();
+ assertTrue(metricsConfiguration.isJvmMemory());
+ assertTrue(metricsConfiguration.isJvmGc());
+ assertTrue(metricsConfiguration.isJvmThread());
+
+ ActiveMQMetricsPlugin metricPlugin = metricsConfiguration.getPlugin();
+ assertTrue(metricPlugin instanceof FakeMetricPlugin);
+
+ Map<String, String> metricPluginOptions = ((FakeMetricPlugin)metricPlugin).getOptions();
+ assertEquals("value1", metricPluginOptions.get("key1"));
+ assertEquals("value2", metricPluginOptions.get("key2"));
+ assertEquals("value3", metricPluginOptions.get("key3"));
+ }
+
+ @Test
+ public void testMetricsConflict() throws Exception {
+ FileConfiguration fc = new FileConfiguration();
+ FileDeploymentManager deploymentManager = new FileDeploymentManager("metricsConflict.xml");
+ deploymentManager.addDeployable(fc);
+ deploymentManager.readConfiguration();
+
+ ActiveMQMetricsPlugin metricPlugin = fc.getMetricsConfiguration().getPlugin();
+ assertTrue(metricPlugin instanceof FakeMetricPlugin);
+
+ Map<String, String> metricPluginOptions = ((FakeMetricPlugin)metricPlugin).getOptions();
+ assertEquals("value1", metricPluginOptions.get("key1"));
+ assertEquals("value2", metricPluginOptions.get("key2"));
+ assertEquals("value3", metricPluginOptions.get("key3"));
+ }
+
@Override
protected Configuration createConfiguration() throws Exception {
// This may be set for the entire testsuite, but on this test we need this out
@@ -784,4 +839,23 @@ public class FileConfigurationTest extends ConfigurationImplTest {
public static class EmptyPlugin2 implements ActiveMQServerPlugin {
}
+
+ public static class FakeMetricPlugin implements ActiveMQMetricsPlugin {
+ private Map<String, String> options;
+
+ public Map<String, String> getOptions() {
+ return options;
+ }
+
+ @Override
+ public ActiveMQMetricsPlugin init(Map<String, String> options) {
+ this.options = options;
+ return this;
+ }
+
+ @Override
+ public MeterRegistry getRegistry() {
+ return null;
+ }
+ }
}
diff --git a/artemis-server/src/test/resources/metrics.xml b/artemis-server/src/test/resources/metrics.xml
new file mode 100644
index 0000000..57a15a4
--- /dev/null
+++ b/artemis-server/src/test/resources/metrics.xml
@@ -0,0 +1,33 @@
+<!--
+ 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
+ xmlns="urn:activemq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:activemq ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
+ <core xmlns="urn:activemq:core">
+ <metrics>
+ <jvm-memory>true</jvm-memory>
+ <jvm-gc>true</jvm-gc>
+ <jvm-threads>true</jvm-threads>
+ <plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$FakeMetricPlugin">
+ <property key="key1" value="value1"/>
+ <property key="key2" value="value2"/>
+ <property key="key3" value="value3"/>
+ </plugin>
+ </metrics>
+ </core>
+</configuration>
diff --git a/artemis-server/src/test/resources/metricsConflict.xml b/artemis-server/src/test/resources/metricsConflict.xml
new file mode 100644
index 0000000..9ea84c8
--- /dev/null
+++ b/artemis-server/src/test/resources/metricsConflict.xml
@@ -0,0 +1,38 @@
+<!--
+ 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
+ xmlns="urn:activemq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:activemq ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
+ <core xmlns="urn:activemq:core">
+ <metrics-plugin class-name="IgnoredMetricPlugin">
+ <property key="key1" value="value1"/>
+ <property key="key2" value="value2"/>
+ <property key="key3" value="value3"/>
+ </metrics-plugin>
+ <metrics>
+ <jvm-memory>true</jvm-memory>
+ <jvm-gc>true</jvm-gc>
+ <jvm-threads>true</jvm-threads>
+ <plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$FakeMetricPlugin">
+ <property key="key1" value="value1"/>
+ <property key="key2" value="value2"/>
+ <property key="key3" value="value3"/>
+ </plugin>
+ </metrics>
+ </core>
+</configuration>
diff --git a/artemis-server/src/test/resources/metricsPlugin.xml b/artemis-server/src/test/resources/metricsPlugin.xml
new file mode 100644
index 0000000..0c57eb6
--- /dev/null
+++ b/artemis-server/src/test/resources/metricsPlugin.xml
@@ -0,0 +1,28 @@
+<!--
+ 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
+ xmlns="urn:activemq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:activemq ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
+ <core xmlns="urn:activemq:core">
+ <metrics-plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$FakeMetricPlugin">
+ <property key="key1" value="value1"/>
+ <property key="key2" value="value2"/>
+ <property key="key3" value="value3"/>
+ </metrics-plugin>
+ </core>
+</configuration>