Refactor Spring Integration metrics support

Update Spring Integration metrics support since Spring Integration
`4.3.6`+ no longer needs `spring-integration-jmx` enable
`MessageChannel`, `MessageHandler` and `MessageSource` metrics.

- Add `IntegrationManagementConfiguration` conditional auto-configuration
  to provide `@EnableIntegrationManagement` when JMX is `enabled` or there
  is no `IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME` bean.
  By default this bean doesn't exist and you explicitly should declare it
  (e.g. via `@EnableIntegrationManagement`) if you would like to collect
  metrics. At the same time Spring Integration enables it when JMX
  management is present (that is a purpose of that new
  `IntegrationManagementConfiguration`)

- Change `SpringIntegrationMetricReader` to read metrics from the
  `IntegrationManagementConfigurer`, not `IntegrationMBeanExporter`

- Change `PublicMetricsAutoConfiguration` to register
  `IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME` bean if
  not present. Since we are here in `actuator`, therefore we are
  interested in the metrics for SI as well.

- Since we don't need JMX for the metrics any more, remove SI-JMX
  dependency from the `spring-boot-starter-integration`.

- Remove `IntegrationManagementConfiguration` modification from the
  `integrationMbeanExporter()`, since that looks like mutation of an
  external object, when end-user would prefer their own options.
  Therefore we don't need `ObjectProvider<IntegrationManagementConfigurer>`, too

- Add missed `MessageSourceMetrics` gathering for the
  `SpringIntegrationMetricReader`

Closes gh-7722
This commit is contained in:
Artem Bilan
2016-12-21 15:13:59 -05:00
committed by Phillip Webb
parent 2e0f87e753
commit d69e43b433
9 changed files with 151 additions and 62 deletions

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2012-2016 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 org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration;
import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics;
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringIntegrationMetricReader}.
*
* @author Artem Bilan
*/
@RunWith(SpringRunner.class)
@SpringBootTest("spring.jmx.enabled=false")
@DirtiesContext
public class SpringIntegrationMetricReaderNoJmxTests {
@Autowired
@Qualifier("springIntegrationPublicMetrics")
private MetricReaderPublicMetrics integrationMetricReader;
@Test
public void test() {
assertThat(this.integrationMetricReader.metrics().size() > 0).isTrue();
}
@Configuration
@Import({IntegrationAutoConfiguration.class, PublicMetricsAutoConfiguration.class})
protected static class TestConfiguration {
}
}

View File

@@ -26,7 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.integration.monitor.IntegrationMBeanExporter;
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link SpringIntegrationMetricReader}.
*
* @author Dave Syer
* @author Artem Bilan
*/
@RunWith(SpringRunner.class)
@SpringBootTest("spring.jmx.enabled=true")
@@ -55,8 +56,8 @@ public class SpringIntegrationMetricReaderTests {
protected static class TestConfiguration {
@Bean
public SpringIntegrationMetricReader reader(IntegrationMBeanExporter exporter) {
return new SpringIntegrationMetricReader(exporter);
public SpringIntegrationMetricReader reader(IntegrationManagementConfigurer managementConfigurer) {
return new SpringIntegrationMetricReader(managementConfigurer);
}
}