Add remaining deprecations for legacy metrics

- add a module to suppress legacy metrics from the Integration Graph
- move graph tests package to match src/main

Fix missed deprecation and checkstyle.

More deprecations and remove GraphLegacyStatsNullModule.

* Revert GRAPH_VERSION.
* Fix JavaDocs warnings
* Fix `MBeanExporterParserTests`
This commit is contained in:
Gary Russell
2020-04-21 17:44:05 -04:00
committed by Artem Bilan
parent b06322787e
commit c2babe4ba2
46 changed files with 642 additions and 553 deletions

View File

@@ -25,8 +25,7 @@
default-counts-enabled="false"
default-stats-enabled="false"
counts-enabled-patterns="foo, !baz, ba*"
stats-enabled-patterns="fiz, buz"
metrics-factory="mf" />
stats-enabled-patterns="fiz, buz" />
<util:properties id="appProperties">
<prop key="foo">foo</prop>
@@ -51,6 +50,4 @@
<si:transformer id="transformer" input-channel="foo" expression="payload" />
<bean id="mf" class="org.springframework.integration.jmx.config.MBeanExporterParserTests$CustomMetrics" />
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,35 +22,26 @@ import java.util.Properties;
import javax.management.MBeanServer;
import org.assertj.core.data.Offset;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.config.IntegrationManagementConfigurer;
import org.springframework.integration.monitor.IntegrationMBeanExporter;
import org.springframework.integration.support.management.AbstractMessageChannelMetrics;
import org.springframework.integration.support.management.AbstractMessageHandlerMetrics;
import org.springframework.integration.support.management.DefaultMessageChannelMetrics;
import org.springframework.integration.support.management.DefaultMessageHandlerMetrics;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@SuppressWarnings("deprecation")
public class MBeanExporterParserTests {
@Autowired
@@ -67,89 +58,7 @@ public class MBeanExporterParserTests {
assertThat(properties.containsKey("bar")).isTrue();
assertThat(exporter.getServer()).isEqualTo(server);
assertThat(TestUtils.getPropertyValue(exporter, "namingStrategy")).isSameAs(context.getBean("keyNamer"));
org.springframework.integration.support.management.MessageChannelMetrics metrics =
context.getBean("foo", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isTrue();
assertThat(metrics.isStatsEnabled()).isFalse();
checkCustomized(metrics);
org.springframework.integration.support.management.MessageHandlerMetrics handlerMetrics =
context.getBean("transformer.handler",
org.springframework.integration.support.management.MessageHandlerMetrics.class);
checkCustomized(handlerMetrics);
metrics = context.getBean("bar", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isTrue();
assertThat(metrics.isStatsEnabled()).isFalse();
metrics = context.getBean("baz", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isFalse();
assertThat(metrics.isStatsEnabled()).isFalse();
metrics = context.getBean("qux", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isFalse();
assertThat(metrics.isStatsEnabled()).isFalse();
metrics = context.getBean("fiz", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isTrue();
assertThat(metrics.isStatsEnabled()).isTrue();
metrics = context.getBean("buz", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isTrue();
assertThat(metrics.isStatsEnabled()).isTrue();
metrics = context.getBean("!excluded", org.springframework.integration.support.management.MessageChannelMetrics.class);
assertThat(metrics.isCountsEnabled()).isFalse();
assertThat(metrics.isStatsEnabled()).isFalse();
checkCustomized(metrics);
org.springframework.integration.support.management.MetricsFactory factory =
context.getBean(org.springframework.integration.support.management.MetricsFactory.class);
IntegrationManagementConfigurer configurer = context.getBean(IntegrationManagementConfigurer.class);
assertThat(TestUtils.getPropertyValue(configurer, "metricsFactory")).isSameAs(factory);
exporter.destroy();
}
private void checkCustomized(org.springframework.integration.support.management.MessageChannelMetrics metrics) {
assertThat(metrics.isLoggingEnabled()).isFalse();
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendDuration.window")).isEqualTo(20);
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendDuration.factor", Double.class))
.isCloseTo(1000000., Offset.offset(.01));
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendErrorRate.window")).isEqualTo(30);
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendErrorRate.period", Double.class))
.isCloseTo(2000000., Offset.offset(.01));
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendErrorRate.lapse", Double.class))
.isCloseTo(.001 / 120000, Offset.offset(.01));
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendSuccessRatio.window")).isEqualTo(40);
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendRate.lapse", Double.class))
.isCloseTo(.001 / 130000, Offset.offset(.01));
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendRate.window")).isEqualTo(50);
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendRate.period", Double.class))
.isCloseTo(3000000., Offset.offset(.01));
assertThat(TestUtils.getPropertyValue(metrics, "channelMetrics.sendRate.lapse", Double.class))
.isCloseTo(.001 / 140000, Offset.offset(.01));
}
private void checkCustomized(org.springframework.integration.support.management.MessageHandlerMetrics metrics) {
assertThat(TestUtils.getPropertyValue(metrics, "handlerMetrics.duration.window")).isEqualTo(20);
assertThat(TestUtils.getPropertyValue(metrics, "handlerMetrics.duration.factor", Double.class))
.isCloseTo(1000000., Offset.offset(.01));
}
public static class CustomMetrics implements org.springframework.integration.support.management.MetricsFactory {
@Override
public AbstractMessageChannelMetrics createChannelMetrics(String name) {
return new DefaultMessageChannelMetrics(name,
new org.springframework.integration.support.management.ExponentialMovingAverage(20, 1000000.),
new org.springframework.integration.support.management.ExponentialMovingAverageRate(2000, 120000,
30, true),
new org.springframework.integration.support.management.ExponentialMovingAverageRatio(130000, 40,
true),
new org.springframework.integration.support.management.ExponentialMovingAverageRate(3000, 140000,
50, true));
}
@Override
public AbstractMessageHandlerMetrics createHandlerMetrics(String name) {
return new DefaultMessageHandlerMetrics(name,
new org.springframework.integration.support.management.ExponentialMovingAverage(20, 1000000.));
}
}
}

View File

@@ -1,106 +0,0 @@
/*
* Copyright 2015-2019 the original author or authors.
*
* Licensed 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
*
* https://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.
*/
package org.springframework.integration.monitor;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.handler.BridgeHandler;
import org.springframework.integration.handler.ServiceActivatingHandler;
import org.springframework.integration.support.management.AggregatingMessageChannelMetrics;
import org.springframework.integration.support.management.AggregatingMessageHandlerMetrics;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @since 4.2
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class AggregatingMetricsTests {
@Autowired
private MessageChannel input;
@Autowired
private AbstractMessageChannel delay;
@Autowired
private QueueChannel output;
@Autowired
private BridgeHandler handler;
@Autowired
private ServiceActivatingHandler delayer;
@Test
public void testCounts() {
Message<?> message = new GenericMessage<String>("foo");
int count = 2000;
for (int i = 0; i < count; i++) {
input.send(message);
}
assertThat(this.output.getQueueSize()).isEqualTo(count);
assertThat(this.output.getSendCount()).isEqualTo(count);
assertThat(this.output.getSendDuration().getCountLong()).isEqualTo(Long.valueOf(count / 1000).longValue());
assertThat(this.handler.getHandleCount()).isEqualTo(count);
assertThat(this.handler.getDuration().getCountLong()).isEqualTo(Long.valueOf(count / 1000).longValue());
}
@Test
public void testElapsed() {
int sampleSize = 2;
this.delay.configureMetrics(new AggregatingMessageChannelMetrics("foo", sampleSize));
this.delay.setStatsEnabled(true);
this.delayer.configureMetrics(new AggregatingMessageHandlerMetrics("bar", sampleSize));
this.delayer.setStatsEnabled(true);
GenericMessage<String> message = new GenericMessage<String>("foo");
int count = 4;
for (int i = 0; i < count; i++) {
this.delay.send(message);
}
assertThat(this.delay.getSendCount()).isEqualTo(count);
assertThat(this.delay.getSendDuration().getCount()).isEqualTo(count / sampleSize);
assertThat((int) this.delay.getMeanSendDuration() / sampleSize).isGreaterThanOrEqualTo(50);
assertThat(this.delayer.getHandleCount()).isEqualTo(count);
assertThat(this.delayer.getDuration().getCount()).isEqualTo(count / sampleSize);
assertThat((int) this.delayer.getMeanDuration() / sampleSize).isGreaterThanOrEqualTo(50);
}
@Test @Ignore
public void perf() {
AggregatingMessageHandlerMetrics metrics = new AggregatingMessageHandlerMetrics();
for (int i = 0; i < 100000000; i++) {
metrics.afterHandle(metrics.beforeHandle(), true);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.integration.support.management.BaseHandlerMetrics;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.PollableChannel;
@@ -87,7 +86,8 @@ public class ChannelIntegrationTests {
assertThat(messageChannelsMonitor.getChannelMetrics(intermediateChannelName)).isSameAs(intermediate);
BaseHandlerMetrics handlerMetrics = messageChannelsMonitor
@SuppressWarnings("deprecation")
org.springframework.integration.support.management.BaseHandlerMetrics handlerMetrics = messageChannelsMonitor
.getHandlerMetrics("bridge");
assertThat(handlerMetrics.handleCount()).isEqualTo(3);

View File

@@ -1,150 +0,0 @@
/*
* Copyright 2015-2019 the original author or authors.
*
* Licensed 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
*
* https://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.
*/
package org.springframework.integration.monitor;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.support.management.DefaultMessageChannelMetrics;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @author Artem Bilan
* @since 4.2
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class MonitorTests {
@Autowired
private QueueChannel input;
@Autowired
private DirectChannel next;
@Autowired
private TestHandler handler;
@Autowired
private TestSource source;
@Autowired
private PublishSubscribeChannel pubsub;
@Autowired
private QueueChannel output;
@Autowired
private NullChannel nullChannel;
@SuppressWarnings("deprecation")
@Test
public void testStats() throws InterruptedException {
final CountDownLatch afterSendLatch = new CountDownLatch(1);
DefaultMessageChannelMetrics channelMetrics =
TestUtils.getPropertyValue(this.next, "channelMetrics", DefaultMessageChannelMetrics.class);
channelMetrics = Mockito.spy(channelMetrics);
Mockito.doAnswer(invocation -> {
Object result = invocation.callRealMethod();
afterSendLatch.countDown();
return result;
}).when(channelMetrics)
.afterSend(Mockito.any(org.springframework.integration.support.management.MetricsContext.class),
Mockito.eq(Boolean.TRUE));
new DirectFieldAccessor(this.next).setPropertyValue("channelMetrics", channelMetrics);
MessagingTemplate messagingTemplate = new MessagingTemplate(this.input);
messagingTemplate.setReceiveTimeout(100000);
Integer active = messagingTemplate.convertSendAndReceive("foo", Integer.class);
assertThat(active.intValue()).isEqualTo(1);
assertThat(afterSendLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.handler.getActiveCount()).isEqualTo(0);
assertThat(this.handler.getHandleCount()).isEqualTo(1);
assertThat(this.handler.getDuration().getMax()).isGreaterThan(99.0);
assertThat(this.handler.getDuration().getMax()).isLessThan(10000.0);
assertThat(this.input.getSendCount()).isEqualTo(1);
assertThat(this.input.getReceiveCount()).isEqualTo(1);
assertThat(this.next.getSendCount()).isEqualTo(1);
assertThat(this.next.getSendDuration().getMax()).isGreaterThan(99.0);
assertThat(this.next.getSendDuration().getMax()).isLessThan(10000.0);
Message<?> fromInbound = this.output.receive(100000);
assertThat(fromInbound).isNotNull();
assertThat(fromInbound.getPayload()).isEqualTo(0);
fromInbound = this.output.receive(10000);
assertThat(fromInbound).isNotNull();
assertThat(fromInbound.getPayload()).isEqualTo(1);
assertThat(this.source.getMessageCount()).isGreaterThanOrEqualTo(2);
assertThat(this.nullChannel.getSendCount()).isGreaterThanOrEqualTo(2);
assertThat(this.pubsub.getSendCount()).isGreaterThanOrEqualTo(2);
}
public static class TestHandler extends AbstractReplyProducingMessageHandler {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return getActiveCount();
}
}
public static class TestSource extends AbstractMessageSource<Integer> {
@Override
public String getComponentType() {
return "foo";
}
@Override
protected Object doReceive() {
return getMessageCount();
}
}
}