From f34aa6f4d859d67df9533adf5e5e82223f9d75cd Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 12 Feb 2018 11:43:38 -0800 Subject: [PATCH] Migrate to Spring Integration Micrometer support Remove custom `SpringIntegrationMetrics` and instead provide auto-configuration to the direct Micrometer support added in Spring Integration 5.0.2. Closes gh-11985 --- .../metrics/MetricsAutoConfiguration.java | 30 ---- .../MetricsIntegrationAutoConfiguration.java | 53 ++++++ .../metrics/integration/package-info.java | 4 +- .../main/resources/META-INF/spring.factories | 1 + .../MetricsAutoConfigurationTests.java | 37 ---- ...ricsIntegrationAutoConfigurationTests.java | 96 ++++++++++ .../integration/SpringIntegrationMetrics.java | 166 ------------------ ...ingIntegrationMetricsIntegrationTests.java | 134 -------------- .../IntegrationAutoConfiguration.java | 8 +- .../IntegrationAutoConfigurationTests.java | 4 +- .../spring-boot-dependencies/pom.xml | 2 +- .../asciidoc/production-ready-features.adoc | 59 ------- .../main/asciidoc/spring-boot-features.adoc | 4 + 13 files changed, 162 insertions(+), 436 deletions(-) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfiguration.java rename spring-boot-project/{spring-boot-actuator/src/main/java/org/springframework/boot/actuate => spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure}/metrics/integration/package-info.java (82%) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfigurationTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetrics.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java index b7f961b0db..1beceb70c0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java @@ -25,19 +25,15 @@ import io.micrometer.core.instrument.binder.logging.LogbackMetrics; import io.micrometer.core.instrument.binder.system.ProcessorMetrics; import io.micrometer.core.instrument.binder.system.UptimeMetrics; -import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetrics; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; -import org.springframework.integration.config.EnableIntegrationManagement; -import org.springframework.integration.support.management.IntegrationManagementConfigurer; /** * {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics. @@ -125,30 +121,4 @@ public class MetricsAutoConfiguration { } - /** - * Binds metrics from Spring Integration. - */ - @Configuration - @ConditionalOnClass(EnableIntegrationManagement.class) - @ConditionalOnProperty(value = "management.metrics.binders.integration.enabled", matchIfMissing = true) - static class MetricsIntegrationConfiguration { - - @Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME) - @ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT) - public IntegrationManagementConfigurer integrationManagementConfigurer() { - IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer(); - configurer.setDefaultCountsEnabled(true); - configurer.setDefaultStatsEnabled(true); - return configurer; - } - - @Bean - @ConditionalOnMissingBean - public SpringIntegrationMetrics springIntegrationMetrics( - IntegrationManagementConfigurer configurer) { - return new SpringIntegrationMetrics(configurer); - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfiguration.java new file mode 100644 index 0000000000..79e9775c1a --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2018 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 + * + * 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. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.integration; + +import io.micrometer.core.instrument.MeterRegistry; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.support.management.micrometer.MicrometerMetricsFactory; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for Spring Integration Micrometer + * support. + * + * @author Phillip Webb + * @author Gary Russell + * @since 2.0.0 + */ +@Configuration +@ConditionalOnClass({ EnableIntegration.class, MeterRegistry.class }) +@AutoConfigureAfter({ IntegrationAutoConfiguration.class, + SimpleMetricsExportAutoConfiguration.class }) +@ConditionalOnBean(MeterRegistry.class) +public class MetricsIntegrationAutoConfiguration { + + @Bean + public MicrometerMetricsFactory integrationMicrometerMetricsFactory( + MeterRegistry meterRegistry) { + return new MicrometerMetricsFactory(meterRegistry); + } + +} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/package-info.java similarity index 82% rename from spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java rename to spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/package-info.java index ff3b2d5942..294cdf100d 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -17,4 +17,4 @@ /** * Actuator support for Spring Integration metrics. */ -package org.springframework.boot.actuate.metrics.integration; +package org.springframework.boot.actuate.autoconfigure.metrics.integration; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories index 49a046e2f0..e7732a3362 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories @@ -48,6 +48,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetri org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxMetricsExportAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration,\ +org.springframework.boot.actuate.autoconfigure.metrics.integration.MetricsIntegrationAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.web.client.RestTemplateMetricsAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration,\ diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java index eec9e73695..5ace579ba7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java @@ -32,12 +32,10 @@ import io.micrometer.core.instrument.config.MeterFilter; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.junit.Test; -import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetrics; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.integration.support.management.IntegrationManagementConfigurer; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -196,30 +194,6 @@ public class MetricsAutoConfigurationTests { .hasBean("customProcessorMetrics")); } - @Test - public void autoConfiguresSpringIntegrationMetrics() { - this.runner.run((context) -> assertThat(context) - .hasSingleBean(SpringIntegrationMetrics.class)); - } - - @Test - public void allowsSpringIntegrationMetricsToBeDisabled() { - this.runner - .withPropertyValues( - "management.metrics.binders.integration.enabled=false") - .run((context) -> assertThat(context) - .doesNotHaveBean(SpringIntegrationMetrics.class)); - } - - @Test - public void allowsCustomSpringIntegrationMetricsToBeUsed() { - this.runner - .withUserConfiguration(CustomSpringIntegrationMetricsConfiguration.class) - .run((context) -> assertThat(context) - .hasSingleBean(SpringIntegrationMetrics.class) - .hasBean("customSpringIntegrationMetrics")); - } - @Configuration static class CustomClockConfiguration { @@ -312,15 +286,4 @@ public class MetricsAutoConfigurationTests { } - @Configuration - static class CustomSpringIntegrationMetricsConfiguration { - - @Bean - SpringIntegrationMetrics customSpringIntegrationMetrics( - IntegrationManagementConfigurer configurer) { - return new SpringIntegrationMetrics(configurer); - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfigurationTests.java new file mode 100644 index 0000000000..9432318ee0 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/integration/MetricsIntegrationAutoConfigurationTests.java @@ -0,0 +1,96 @@ +/* + * Copyright 2012-2018 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 + * + * 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. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.integration; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.support.management.AbstractMessageChannelMetrics; +import org.springframework.integration.support.management.DefaultMetricsFactory; +import org.springframework.integration.support.management.MetricsFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.SubscribableChannel; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link MetricsIntegrationAutoConfiguration}. + * + * @author Phillip Webb + */ +public class MetricsIntegrationAutoConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(IntegrationAutoConfiguration.class, + MetricsIntegrationAutoConfiguration.class)) + .withUserConfiguration(BaseConfiguration.class) + .withPropertyValues("spring.jmx.enabled=false"); + + @Test + public void autoConfiguredIntegrationIsInstrumented() { + this.contextRunner.run((context) -> { + Message message = MessageBuilder.withPayload("hello").build(); + SubscribableChannel channel = context.getBean("errorChannel", + SubscribableChannel.class); + channel.send(message); + MeterRegistry registry = context.getBean(MeterRegistry.class); + registry.get("errorChannel.timer").timer(); + registry.get("errorChannel.errorCounter").counter(); + }); + } + + @Test + public void autoConfigurationBacksOffWhenHasMetricsFactory() { + this.contextRunner.withUserConfiguration(LegacyConfiguration.class) + .run((context) -> { + SubscribableChannel channel = context.getBean("errorChannel", + SubscribableChannel.class); + AbstractMessageChannelMetrics metrics = (AbstractMessageChannelMetrics) ReflectionTestUtils + .getField(channel, "channelMetrics"); + assertThat(metrics.getTimer()).isNull(); + }); + } + + @Configuration + static class BaseConfiguration { + + @Bean + public SimpleMeterRegistry simpleMeterRegistry() { + return new SimpleMeterRegistry(); + } + + } + + @Configuration + static class LegacyConfiguration { + + @Bean + public MetricsFactory legacyMetricsFactory() { + return new DefaultMetricsFactory(); + } + + } + +} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetrics.java deleted file mode 100644 index 528bfe288f..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetrics.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2012-2018 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 - * - * 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. - */ - -package org.springframework.boot.actuate.metrics.integration; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.TimeUnit; -import java.util.function.ToDoubleFunction; - -import io.micrometer.core.instrument.FunctionCounter; -import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.TimeGauge; -import io.micrometer.core.instrument.binder.MeterBinder; - -import org.springframework.beans.factory.SmartInitializingSingleton; -import org.springframework.integration.support.management.IntegrationManagementConfigurer; -import org.springframework.integration.support.management.MessageChannelMetrics; -import org.springframework.integration.support.management.MessageHandlerMetrics; -import org.springframework.integration.support.management.MessageSourceMetrics; -import org.springframework.integration.support.management.PollableChannelManagement; - -/** - * A {@link MeterBinder} for Spring Integration metrics. - * - * @author Jon Schneider - * @since 2.0.0 - */ -public class SpringIntegrationMetrics implements MeterBinder, SmartInitializingSingleton { - - private final Tags tags; - - private Collection registries = new ArrayList<>(); - - private final IntegrationManagementConfigurer configurer; - - public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer) { - this(configurer, Collections.emptyList()); - } - - public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer, - Iterable tags) { - this.configurer = configurer; - this.tags = Tags.of(tags); - } - - @Override - public void bindTo(MeterRegistry registry) { - registerGauge(registry, this.configurer, this.tags, - "spring.integration.channelNames", - "The number of spring integration channels", - (configurer) -> configurer.getChannelNames().length); - registerGauge(registry, this.configurer, this.tags, - "spring.integration.handlerNames", - "The number of spring integration handlers", - (configurer) -> configurer.getHandlerNames().length); - registerGauge(registry, this.configurer, this.tags, - "spring.integration.sourceNames", - "The number of spring integration sources", - (configurer) -> configurer.getSourceNames().length); - this.registries.add(registry); - } - - private void addSourceMetrics(MeterRegistry registry) { - for (String source : this.configurer.getSourceNames()) { - MessageSourceMetrics sourceMetrics = this.configurer.getSourceMetrics(source); - Iterable tagsWithSource = this.tags.and("source", source); - registerFunctionCounter(registry, sourceMetrics, tagsWithSource, - "spring.integration.source.messages", - "The number of successful handler calls", - MessageSourceMetrics::getMessageCount); - } - } - - private void addHandlerMetrics(MeterRegistry registry) { - for (String handler : this.configurer.getHandlerNames()) { - MessageHandlerMetrics handlerMetrics = this.configurer - .getHandlerMetrics(handler); - Iterable tagsWithHandler = this.tags.and("handler", handler); - registerTimedGauge(registry, handlerMetrics, tagsWithHandler, - "spring.integration.handler.duration.max", - "The maximum handler duration", - MessageHandlerMetrics::getMaxDuration); - registerTimedGauge(registry, handlerMetrics, tagsWithHandler, - "spring.integration.handler.duration.min", - "The minimum handler duration", - MessageHandlerMetrics::getMinDuration); - registerTimedGauge(registry, handlerMetrics, tagsWithHandler, - "spring.integration.handler.duration.mean", - "The mean handler duration", MessageHandlerMetrics::getMeanDuration); - registerGauge(registry, handlerMetrics, tagsWithHandler, - "spring.integration.handler.activeCount", - "The number of active handlers", - MessageHandlerMetrics::getActiveCount); - } - } - - private void addChannelMetrics(MeterRegistry registry) { - for (String channel : this.configurer.getChannelNames()) { - MessageChannelMetrics channelMetrics = this.configurer - .getChannelMetrics(channel); - Iterable tagsWithChannel = this.tags.and("channel", channel); - registerFunctionCounter(registry, channelMetrics, tagsWithChannel, - "spring.integration.channel.sendErrors", - "The number of failed sends (either throwing an exception or rejected by the channel)", - MessageChannelMetrics::getSendErrorCount); - registerFunctionCounter(registry, channelMetrics, tagsWithChannel, - "spring.integration.channel.sends", "The number of successful sends", - MessageChannelMetrics::getSendCount); - if (channelMetrics instanceof PollableChannelManagement) { - registerFunctionCounter(registry, - (PollableChannelManagement) channelMetrics, tagsWithChannel, - "spring.integration.receives", "The number of messages received", - PollableChannelManagement::getReceiveCount); - } - } - } - - private void registerGauge(MeterRegistry registry, T object, Iterable tags, - String name, String description, ToDoubleFunction value) { - Gauge.Builder builder = Gauge.builder(name, object, value); - builder.tags(tags).description(description).register(registry); - } - - private void registerTimedGauge(MeterRegistry registry, T object, - Iterable tags, String name, String description, - ToDoubleFunction value) { - TimeGauge.Builder builder = TimeGauge.builder(name, object, - TimeUnit.MILLISECONDS, value); - builder.tags(tags).description(description).register(registry); - } - - private void registerFunctionCounter(MeterRegistry registry, T object, - Iterable tags, String name, String description, - ToDoubleFunction value) { - FunctionCounter.builder(name, object, value).tags(tags).description(description) - .register(registry); - } - - @Override - public void afterSingletonsInstantiated() { - this.registries.forEach((registry) -> { - addChannelMetrics(registry); - addHandlerMetrics(registry); - addSourceMetrics(registry); - }); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java deleted file mode 100644 index 978e8a8842..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2012-2018 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 - * - * 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. - */ - -package org.springframework.boot.actuate.metrics.integration; - -import java.io.IOException; -import java.util.Map; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.integration.annotation.Gateway; -import org.springframework.integration.annotation.IntegrationComponentScan; -import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.config.EnableIntegration; -import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.support.management.IntegrationManagementConfigurer; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link SpringIntegrationMetrics}. - * - * @author Jon Schneider - * @author Andy Wilkinson - */ -@RunWith(SpringRunner.class) -public class SpringIntegrationMetricsIntegrationTests { - - @Autowired - TestSpringIntegrationApplication.TempConverter converter; - - @Autowired - MeterRegistry registry; - - @Test - public void springIntegrationMetrics() { - this.converter.fahrenheitToCelsius(68.0); - assertThat(this.registry.get("spring.integration.channel.sends") - .tags("channel", "convert.input").functionCounter().count()).isEqualTo(1); - this.registry.get("spring.integration.handler.duration.min").gauge(); - this.registry.get("spring.integration.sourceNames").meter(); - } - - @Configuration - @EnableIntegration - @IntegrationComponentScan - public static class TestSpringIntegrationApplication { - - @Bean - MeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - @Bean - public IntegrationManagementConfigurer integrationManagementConfigurer() { - IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer(); - configurer.setDefaultCountsEnabled(true); - configurer.setDefaultStatsEnabled(true); - return configurer; - } - - @Bean - public SpringIntegrationMetrics springIntegrationMetrics( - IntegrationManagementConfigurer configurer, MeterRegistry registry) { - SpringIntegrationMetrics springIntegrationMetrics = new SpringIntegrationMetrics( - configurer); - springIntegrationMetrics.bindTo(registry); - return springIntegrationMetrics; - } - - @Bean - public IntegrationFlow convert() { - return (f) -> f - .transform((payload) -> "{\"fahrenheit\":" + payload + "}", - (e) -> e.id("toJson")) - .handle(String.class, this::fahrenheitToCelsius, - (e) -> e.id("temperatureConverter")) - .transform(this::extractResult, (e) -> e.id("toResponse")); - } - - private double extractResult(String json) { - try { - return (double) new ObjectMapper().readValue(json, Map.class) - .get("celsius"); - } - catch (IOException ex) { - throw new RuntimeException(ex); - } - } - - private String fahrenheitToCelsius(String payload, Map headers) { - try { - double fahrenheit = (double) new ObjectMapper() - .readValue(payload, Map.class).get("fahrenheit"); - double celsius = (fahrenheit - 32) * (5.0 / 9.0); - return "{\"celsius\":" + celsius + "}"; - } - catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - @MessagingGateway - public interface TempConverter { - - @Gateway(requestChannel = "convert.input") - double fahrenheitToCelsius(double fahrenheit); - - } - - } - -} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index cae7337c42..a0361c8627 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -115,14 +115,12 @@ public class IntegrationAutoConfiguration { * Integration management configuration. */ @Configuration - @ConditionalOnClass({ EnableIntegrationManagement.class, - EnableIntegrationMBeanExport.class }) + @ConditionalOnClass(EnableIntegrationManagement.class) @ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT) - @ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) protected static class IntegrationManagementConfiguration { @Configuration - @EnableIntegrationManagement(defaultCountsEnabled = "true", defaultStatsEnabled = "true") + @EnableIntegrationManagement(countsEnabled = "true") protected static class EnableIntegrationManagementConfiguration { } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index 5bc689b1d3..ce41c7b37c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -127,7 +127,7 @@ public class IntegrationAutoConfigurationTests { load("spring.jmx.enabled=false"); assertThat(this.context.getBeansOfType(MBeanServer.class)).hasSize(0); assertThat(this.context.getBeansOfType(IntegrationManagementConfigurer.class)) - .isEmpty(); + .isNotEmpty(); // As of Boot 2.0 we always configure } @Test diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index fada9190d6..3e58173556 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -147,7 +147,7 @@ 2.0.1.RELEASE Kay-BUILD-SNAPSHOT 0.24.0.RELEASE - 5.0.1.RELEASE + 5.0.2.BUILD-SNAPSHOT 2.1.2.RELEASE 2.3.2.RELEASE 1.2.0.RELEASE diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index ff308d2933..01966d5b42 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1258,65 +1258,6 @@ factories with a metric named `rabbitmq`. The prefix can be customized by using -[[production-ready-metrics-integration]] -=== Spring Integration Metrics -Auto-configuration enables binding of a number of Spring Integration-related metrics: - -.General metrics -|=== -| Metric | Description - -| `spring.integration.channelNames` -| Number of Spring Integration channels - -| `spring.integration.handlerNames` -| Number of Spring Integration handlers - -| `spring.integration.sourceNames` -| Number of Spring Integration sources -|=== - -.Channel metrics -|=== -| Metric | Description - -| `spring.integration.channel.receives` -| Number of receives - -| `spring.integration.channel.sendErrors` -| Number of failed sends - -| `spring.integration.channel.sends` -| Number of successful sends -|=== - -.Handler metrics -|=== -| Metric | Description - -| `spring.integration.handler.duration.max` -| Maximum handler duration in milliseconds - -| `spring.integration.handler.duration.min` -| Minimum handler duration in milliseconds - -| `spring.integration.handler.duration.mean` -| Mean handler duration in milliseconds - -| `spring.integration.handler.activeCount` -| Number of active handlers -|=== - -.Source metrics -|=== -| Metric | Description - -| `spring.integration.source.messages` -| Number of successful source calls -|=== - - - [[production-ready-metrics-per-meter-properties]] === Customizing individual meters If you need to apply customizations to specific `Meter` instances you can use the diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 426376524b..5855b2391f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -5839,6 +5839,10 @@ See the and {sc-spring-boot-autoconfigure}/integration/IntegrationProperties.{sc-ext}[`IntegrationProperties`] classes for more details. +By default, if a Micrometer `meterRegistry` bean is present, Spring Integration metrics +will be managed by Micrometer. If you wish to use legacy Spring Integration metrics, add +a `DefaultMetricsFactory` bean to the application context. + [[boot-features-session]]