Merge branch '1.5.x'
This commit is contained in:
@@ -45,7 +45,7 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
/**
|
||||
* Order applied to the WebSecurityConfigurerAdapter that is used to configure basic
|
||||
* authentication for management endpoints. If you want to add your own authentication
|
||||
* for all or some of those endpoints the best thing to do is add your own
|
||||
* for all or some of those endpoints the best thing to do is to add your own
|
||||
* WebSecurityConfigurerAdapter with lower order, for instance by using
|
||||
* {@code ACCESS_OVERRIDE_ORDER}.
|
||||
*/
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
|
||||
@@ -51,6 +52,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link PublicMetrics}.
|
||||
@@ -58,6 +60,7 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @author Johannes Edmeier
|
||||
* @author Artem Bilan
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Configuration
|
||||
@@ -137,15 +140,23 @@ public class PublicMetricsAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(IntegrationMBeanExporter.class)
|
||||
@ConditionalOnBean(IntegrationMBeanExporter.class)
|
||||
static class IntegrationMetricsConfiguration {
|
||||
|
||||
@Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)
|
||||
@ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT)
|
||||
public IntegrationManagementConfigurer managementConfigurer() {
|
||||
IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
|
||||
configurer.setDefaultCountsEnabled(true);
|
||||
configurer.setDefaultStatsEnabled(true);
|
||||
return configurer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "springIntegrationPublicMetrics")
|
||||
public MetricReaderPublicMetrics springIntegrationPublicMetrics(
|
||||
IntegrationMBeanExporter exporter) {
|
||||
IntegrationManagementConfigurer managementConfigurer) {
|
||||
return new MetricReaderPublicMetrics(
|
||||
new SpringIntegrationMetricReader(exporter));
|
||||
new SpringIntegrationMetricReader(managementConfigurer));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,22 +22,27 @@ import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
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;
|
||||
import org.springframework.integration.support.management.Statistics;
|
||||
|
||||
/**
|
||||
* A {@link MetricReader} for Spring Integration metrics (as provided by
|
||||
* spring-integration-jmx).
|
||||
* {@link IntegrationManagementConfigurer}).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class SpringIntegrationMetricReader implements MetricReader {
|
||||
|
||||
private final IntegrationMBeanExporter exporter;
|
||||
private final IntegrationManagementConfigurer configurer;
|
||||
|
||||
public SpringIntegrationMetricReader(IntegrationMBeanExporter exporter) {
|
||||
this.exporter = exporter;
|
||||
public SpringIntegrationMetricReader(IntegrationManagementConfigurer configurer) {
|
||||
this.configurer = configurer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,51 +52,80 @@ public class SpringIntegrationMetricReader implements MetricReader {
|
||||
|
||||
@Override
|
||||
public Iterable<Metric<?>> findAll() {
|
||||
IntegrationMBeanExporter exporter = this.exporter;
|
||||
List<Metric<?>> metrics = new ArrayList<Metric<?>>();
|
||||
for (String name : exporter.getChannelNames()) {
|
||||
String prefix = "integration.channel." + name;
|
||||
metrics.addAll(getStatistics(prefix + ".errorRate",
|
||||
exporter.getChannelErrorRate(name)));
|
||||
metrics.add(new Metric<Long>(prefix + ".sendCount",
|
||||
exporter.getChannelSendCountLong(name)));
|
||||
metrics.addAll(getStatistics(prefix + ".sendRate",
|
||||
exporter.getChannelSendRate(name)));
|
||||
metrics.add(new Metric<Long>(prefix + ".receiveCount",
|
||||
exporter.getChannelReceiveCountLong(name)));
|
||||
}
|
||||
for (String name : exporter.getHandlerNames()) {
|
||||
metrics.addAll(getStatistics("integration.handler." + name + ".duration",
|
||||
exporter.getHandlerDuration(name)));
|
||||
}
|
||||
metrics.add(new Metric<Integer>("integration.activeHandlerCount",
|
||||
exporter.getActiveHandlerCount()));
|
||||
metrics.add(new Metric<Integer>("integration.handlerCount",
|
||||
exporter.getHandlerCount()));
|
||||
metrics.add(new Metric<Integer>("integration.channelCount",
|
||||
exporter.getChannelCount()));
|
||||
metrics.add(new Metric<Integer>("integration.queuedMessageCount",
|
||||
exporter.getQueuedMessageCount()));
|
||||
return metrics;
|
||||
List<Metric<?>> result = new ArrayList<Metric<?>>();
|
||||
String[] channelNames = this.configurer.getChannelNames();
|
||||
String[] handlerNames = this.configurer.getHandlerNames();
|
||||
String[] sourceNames = this.configurer.getSourceNames();
|
||||
addChannelMetrics(result, channelNames);
|
||||
addHandlerMetrics(result, handlerNames);
|
||||
addSourceMetrics(result, sourceNames);
|
||||
result.add(new Metric<Integer>("integration.handlerCount", handlerNames.length));
|
||||
result.add(new Metric<Integer>("integration.channelCount", channelNames.length));
|
||||
result.add(new Metric<Integer>("integration.sourceCount", sourceNames.length));
|
||||
return result;
|
||||
}
|
||||
|
||||
private Collection<? extends Metric<?>> getStatistics(String name,
|
||||
Statistics statistic) {
|
||||
private void addChannelMetrics(List<Metric<?>> result, String[] names) {
|
||||
for (String name : names) {
|
||||
addChannelMetrics(result, name, this.configurer.getChannelMetrics(name));
|
||||
}
|
||||
}
|
||||
|
||||
private void addChannelMetrics(List<Metric<?>> result, String name,
|
||||
MessageChannelMetrics metrics) {
|
||||
String prefix = "integration.channel." + name;
|
||||
result.addAll(getStatistics(prefix + ".errorRate", metrics.getErrorRate()));
|
||||
result.add(new Metric<Long>(prefix + ".sendCount", metrics.getSendCountLong()));
|
||||
result.addAll(getStatistics(prefix + ".sendRate", metrics.getSendRate()));
|
||||
if (metrics instanceof PollableChannelManagement) {
|
||||
result.add(new Metric<Long>(prefix + ".receiveCount",
|
||||
((PollableChannelManagement) metrics).getReceiveCountLong()));
|
||||
}
|
||||
}
|
||||
|
||||
private void addHandlerMetrics(List<Metric<?>> result, String[] names) {
|
||||
for (String name : names) {
|
||||
addHandlerMetrics(result, name, this.configurer.getHandlerMetrics(name));
|
||||
}
|
||||
}
|
||||
|
||||
private void addHandlerMetrics(List<Metric<?>> result, String name,
|
||||
MessageHandlerMetrics metrics) {
|
||||
String prefix = "integration.handler." + name;
|
||||
result.addAll(getStatistics(prefix + ".duration", metrics.getDuration()));
|
||||
long activeCount = metrics.getActiveCountLong();
|
||||
result.add(new Metric<Long>(prefix + ".activeCount", activeCount));
|
||||
}
|
||||
|
||||
private void addSourceMetrics(List<Metric<?>> result, String[] names) {
|
||||
for (String name : names) {
|
||||
addSourceMetrics(result, name, this.configurer.getSourceMetrics(name));
|
||||
}
|
||||
}
|
||||
|
||||
private void addSourceMetrics(List<Metric<?>> result, String name,
|
||||
MessageSourceMetrics sourceMetrics) {
|
||||
String prefix = "integration.source." + name;
|
||||
result.add(new Metric<Long>(prefix + ".messageCount",
|
||||
sourceMetrics.getMessageCountLong()));
|
||||
}
|
||||
|
||||
private Collection<? extends Metric<?>> getStatistics(String name, Statistics stats) {
|
||||
List<Metric<?>> metrics = new ArrayList<Metric<?>>();
|
||||
metrics.add(new Metric<Double>(name + ".mean", statistic.getMean()));
|
||||
metrics.add(new Metric<Double>(name + ".max", statistic.getMax()));
|
||||
metrics.add(new Metric<Double>(name + ".min", statistic.getMin()));
|
||||
metrics.add(
|
||||
new Metric<Double>(name + ".stdev", statistic.getStandardDeviation()));
|
||||
metrics.add(new Metric<Long>(name + ".count", statistic.getCountLong()));
|
||||
metrics.add(new Metric<Double>(name + ".mean", stats.getMean()));
|
||||
metrics.add(new Metric<Double>(name + ".max", stats.getMax()));
|
||||
metrics.add(new Metric<Double>(name + ".min", stats.getMin()));
|
||||
metrics.add(new Metric<Double>(name + ".stdev", stats.getStandardDeviation()));
|
||||
metrics.add(new Metric<Long>(name + ".count", stats.getCountLong()));
|
||||
return metrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
int totalChannelCount = this.exporter.getChannelCount() * 11;
|
||||
int totalHandlerCount = this.exporter.getHandlerCount() * 5;
|
||||
return totalChannelCount + totalHandlerCount + 4;
|
||||
int totalChannelCount = this.configurer.getChannelNames().length;
|
||||
int totalHandlerCount = this.configurer.getHandlerNames().length;
|
||||
int totalSourceCount = this.configurer.getSourceNames().length;
|
||||
return totalChannelCount + totalHandlerCount + totalSourceCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
public void metricReaderPublicMetrics() throws Exception {
|
||||
load();
|
||||
assertThat(this.context.getBeansOfType(MetricReaderPublicMetrics.class))
|
||||
.hasSize(1);
|
||||
.hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,7 +47,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JolokiaMvcEndpoint}
|
||||
* Integration tests for {@link JolokiaMvcEndpoint}.
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @author Dave Syer
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,9 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user