INT-3755: Separate Stats Enablement from JMX
JIRA: https://jira.spring.io/browse/INT-3755 JIRA: https://jira.spring.io/browse/INT-3756 Previously JMX was required to enable capturing message counts and statistics. This is now a separate operation from JMX and can be enabled independently. For backwards compatibility, enabling JMX will automatically enable statistics (unless separately configured). INT-3755: Polishing; PR Comments Doc Polishing JavaDocs polishing
This commit is contained in:
committed by
Artem Bilan
parent
c68c7b3412
commit
9600006694
@@ -20,11 +20,16 @@
|
||||
default-domain="tests.MBeanExpoerterParser"
|
||||
object-name-static-properties="appProperties"
|
||||
object-naming-strategy="keyNamer"
|
||||
counts-enabled="foo, !baz, ba*"
|
||||
stats-enabled="fiz, buz"
|
||||
managed-components="\!excluded, f*, b*, q*, t*"
|
||||
metrics-factory="mf" />
|
||||
|
||||
managed-components="\!excluded, f*, b*, q*, t*" />
|
||||
|
||||
<si:management
|
||||
default-logging-enabled="false"
|
||||
default-counts-enabled="false"
|
||||
default-stats-enabled="false"
|
||||
counts-enabled-patterns="foo, !baz, ba*"
|
||||
stats-enabled-patterns="fiz, buz"
|
||||
metrics-factory="mf" />
|
||||
|
||||
<util:properties id="appProperties">
|
||||
<prop key="foo">foo</prop>
|
||||
<prop key="bar">bar</prop>
|
||||
|
||||
@@ -36,12 +36,13 @@ import org.springframework.integration.channel.management.DefaultMessageChannelM
|
||||
import org.springframework.integration.channel.management.MessageChannelMetrics;
|
||||
import org.springframework.integration.handler.management.AbstractMessageHandlerMetrics;
|
||||
import org.springframework.integration.handler.management.DefaultMessageHandlerMetrics;
|
||||
import org.springframework.integration.handler.management.MessageHandlerMetrics;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
import org.springframework.integration.monitor.MetricsFactory;
|
||||
import org.springframework.integration.support.management.ExponentialMovingAverage;
|
||||
import org.springframework.integration.support.management.ExponentialMovingAverageRate;
|
||||
import org.springframework.integration.support.management.ExponentialMovingAverageRatio;
|
||||
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
|
||||
import org.springframework.integration.support.management.MessageHandlerMetrics;
|
||||
import org.springframework.integration.support.management.MetricsFactory;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -99,11 +100,13 @@ public class MBeanExporterParserTests {
|
||||
assertFalse(metrics.isStatsEnabled());
|
||||
checkCustomized(metrics);
|
||||
MetricsFactory factory = context.getBean(MetricsFactory.class);
|
||||
assertSame(factory, TestUtils.getPropertyValue(exporter, "metricsFactory"));
|
||||
IntegrationManagementConfigurer configurer = context.getBean(IntegrationManagementConfigurer.class);
|
||||
assertSame(factory, TestUtils.getPropertyValue(configurer, "metricsFactory"));
|
||||
exporter.destroy();
|
||||
}
|
||||
|
||||
private void checkCustomized(MessageChannelMetrics metrics) {
|
||||
assertFalse(metrics.isLoggingEnabled());
|
||||
assertEquals(20, TestUtils.getPropertyValue(metrics, "channelMetrics.sendDuration.window"));
|
||||
assertEquals(1000000., TestUtils.getPropertyValue(metrics, "channelMetrics.sendDuration.factor", Double.class),
|
||||
.01);
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.integration.jmx.configuration;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -29,7 +31,6 @@ import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -41,8 +42,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.config.EnableIntegrationManagement;
|
||||
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
import org.springframework.integration.support.management.DefaultMetricsFactory;
|
||||
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
|
||||
import org.springframework.integration.support.management.MetricsFactory;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.jmx.support.MBeanServerFactoryBean;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
@@ -69,17 +74,27 @@ public class EnableMBeanExportTests {
|
||||
@Autowired
|
||||
private MBeanServer mBeanServer;
|
||||
|
||||
@Autowired
|
||||
private IntegrationManagementConfigurer configurer;
|
||||
|
||||
@Autowired
|
||||
private MetricsFactory myMetricsFactory;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testEnableMBeanExport() throws MalformedObjectNameException, ClassNotFoundException {
|
||||
|
||||
assertSame(this.mBeanServer, this.exporter.getServer());
|
||||
String[] componentNamePatterns = TestUtils.getPropertyValue(this.exporter, "componentNamePatterns", String[].class);
|
||||
assertThat(componentNamePatterns, Matchers.arrayContaining("input", "inputX", "in*"));
|
||||
String[] enabledCounts = TestUtils.getPropertyValue(this.exporter, "enabledCountsPatterns", String[].class);
|
||||
assertThat(enabledCounts, Matchers.arrayContaining("foo", "bar", "baz"));
|
||||
String[] enabledStatts = TestUtils.getPropertyValue(this.exporter, "enabledStatsPatterns", String[].class);
|
||||
assertThat(enabledStatts, Matchers.arrayContaining("qux", "!*"));
|
||||
assertThat(componentNamePatterns, arrayContaining("input", "inputX", "in*"));
|
||||
String[] enabledCounts = TestUtils.getPropertyValue(this.configurer, "enabledCountsPatterns", String[].class);
|
||||
assertThat(enabledCounts, arrayContaining("foo", "bar", "baz"));
|
||||
String[] enabledStatts = TestUtils.getPropertyValue(this.configurer, "enabledStatsPatterns", String[].class);
|
||||
assertThat(enabledStatts, arrayContaining("qux", "!*"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.configurer, "defaultLoggingEnabled", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.configurer, "defaultCountsEnabled", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.configurer, "defaultStatsEnabled", Boolean.class));
|
||||
assertSame(this.myMetricsFactory, TestUtils.getPropertyValue(this.configurer, "metricsFactory"));
|
||||
|
||||
Set<ObjectName> names = this.mBeanServer.queryNames(ObjectName.getInstance("FOO:type=MessageChannel,*"), null);
|
||||
// Only one registered (out of >2 available)
|
||||
@@ -106,9 +121,14 @@ public class EnableMBeanExportTests {
|
||||
@EnableIntegration
|
||||
@EnableIntegrationMBeanExport(server = "#{mbeanServer}",
|
||||
defaultDomain = "${managed.domain}",
|
||||
managedComponents = {"input", "${managed.component}"},
|
||||
countsEnabled = { "foo", "${count.patterns}" },
|
||||
statsEnabled = { "qux", "!*" })
|
||||
managedComponents = {"input", "${managed.component}"})
|
||||
@EnableIntegrationManagement(
|
||||
defaultLoggingEnabled = "false",
|
||||
defaultCountsEnabled = "true",
|
||||
defaultStatsEnabled = "true",
|
||||
countsEnabled = { "foo", "${count.patterns}" },
|
||||
statsEnabled = { "qux", "!*" },
|
||||
metricsFactory = "myMetricsFactory")
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -126,6 +146,11 @@ public class EnableMBeanExportTests {
|
||||
return new QueueChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MetricsFactory myMetricsFactory() {
|
||||
return new DefaultMetricsFactory();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class EnvironmentApplicationContextInitializer implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
<context:mbean-server />
|
||||
|
||||
<int-jmx:mbean-export metrics-factory="aggregatingMetricsFactory" />
|
||||
<int-jmx:mbean-export />
|
||||
|
||||
<int:management metrics-factory="aggregatingMetricsFactory" default-counts-enabled="true" default-stats-enabled="true" />
|
||||
|
||||
<int:channel id="input" />
|
||||
|
||||
@@ -21,7 +23,8 @@
|
||||
<int:queue />
|
||||
</int:channel>
|
||||
|
||||
<bean id="aggregatingMetricsFactory" class="org.springframework.integration.monitor.AggregatingMetricsFactory">
|
||||
<bean id="aggregatingMetricsFactory"
|
||||
class="org.springframework.integration.support.management.AggregatingMetricsFactory">
|
||||
<constructor-arg value="1000" />
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -80,9 +80,9 @@ public class AggregatingMetricsTests {
|
||||
public void testElapsed() {
|
||||
int sampleSize = 2;
|
||||
this.delay.configureMetrics(new AggregatingMessageChannelMetrics("foo", sampleSize));
|
||||
this.delay.enableStats(true);
|
||||
this.delay.setStatsEnabled(true);
|
||||
this.delayer.configureMetrics(new AggregatingMessageHandlerMetrics("bar", sampleSize));
|
||||
this.delayer.enableStats(true);
|
||||
this.delayer.setStatsEnabled(true);
|
||||
GenericMessage<String> message = new GenericMessage<String>("foo");
|
||||
int count = 4;
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.handler.management.MessageHandlerMetrics;
|
||||
import org.springframework.integration.support.management.MessageHandlerMetrics;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageDeliveryException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
|
||||
@@ -54,11 +54,11 @@ public class Int2307Tests {
|
||||
int count = 0;
|
||||
for (ObjectInstance mbean : mbeans) {
|
||||
Thread.sleep(500); //Added in order to pass test with Java 8
|
||||
if (mbean.toString().startsWith("org.springframework.integration.monitor.LifecycleTrackableMessageHandlerMetrics[test.domain:type=MessageHandler,name=rlr,bean=endpoint,random=")) {
|
||||
if (mbean.toString().startsWith("org.springframework.integration.support.management.LifecycleTrackableMessageHandlerMetrics[test.domain:type=MessageHandler,name=rlr,bean=endpoint,random=")) {
|
||||
bits |= 2;
|
||||
count++;
|
||||
}
|
||||
else if (mbean.toString().startsWith("org.springframework.integration.monitor.TrackableRouterMetrics[test.domain:type=MessageHandler,name=hvr,bean=endpoint,random=")) {
|
||||
else if (mbean.toString().startsWith("org.springframework.integration.support.management.TrackableRouterMetrics[test.domain:type=MessageHandler,name=hvr,bean=endpoint,random=")) {
|
||||
bits |= 8;
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user