This closes #3210
This commit is contained in:
commit
3b8ab97629
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue