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 7fe293b476..6b77206cad 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 ced6ee4490..3ae605eff8 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 6d41c8d4ff..c43618c81b 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 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 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 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 options; + + public Map getOptions() { + return options; + } + + @Override + public ActiveMQMetricsPlugin init(Map 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 0000000000..57a15a49f3 --- /dev/null +++ b/artemis-server/src/test/resources/metrics.xml @@ -0,0 +1,33 @@ + + + + + true + true + true + + + + + + + + diff --git a/artemis-server/src/test/resources/metricsConflict.xml b/artemis-server/src/test/resources/metricsConflict.xml new file mode 100644 index 0000000000..9ea84c82fe --- /dev/null +++ b/artemis-server/src/test/resources/metricsConflict.xml @@ -0,0 +1,38 @@ + + + + + + + + + + true + true + true + + + + + + + + diff --git a/artemis-server/src/test/resources/metricsPlugin.xml b/artemis-server/src/test/resources/metricsPlugin.xml new file mode 100644 index 0000000000..0c57eb6140 --- /dev/null +++ b/artemis-server/src/test/resources/metricsPlugin.xml @@ -0,0 +1,28 @@ + + + + + + + + + +