Skip to content

Commit 6e02fe5

Browse files
committed
Merge branch '1.5.x'
2 parents ae389d2 + 78ee863 commit 6e02fe5

File tree

33 files changed

+537
-127
lines changed

33 files changed

+537
-127
lines changed

spring-boot-actuator/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@
199199
</exclusion>
200200
</exclusions>
201201
</dependency>
202-
<dependency>
203-
<groupId>org.springframework.integration</groupId>
204-
<artifactId>spring-integration-jmx</artifactId>
205-
<optional>true</optional>
206-
</dependency>
207202
<dependency>
208203
<groupId>org.springframework.integration</groupId>
209204
<artifactId>spring-integration-core</artifactId>
@@ -349,6 +344,11 @@
349344
<artifactId>spring-data-rest-webmvc</artifactId>
350345
<scope>test</scope>
351346
</dependency>
347+
<dependency>
348+
<groupId>org.springframework.integration</groupId>
349+
<artifactId>spring-integration-jmx</artifactId>
350+
<scope>test</scope>
351+
</dependency>
352352
<dependency>
353353
<groupId>org.springframework.security</groupId>
354354
<artifactId>spring-security-test</artifactId>

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ManagementServerProperties implements SecurityPrerequisite {
4545
/**
4646
* Order applied to the WebSecurityConfigurerAdapter that is used to configure basic
4747
* authentication for management endpoints. If you want to add your own authentication
48-
* for all or some of those endpoints the best thing to do is add your own
48+
* for all or some of those endpoints the best thing to do is to add your own
4949
* WebSecurityConfigurerAdapter with lower order, for instance by using
5050
* {@code ACCESS_OVERRIDE_ORDER}.
5151
*/

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfiguration.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,23 @@
4444
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4545
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4646
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
47+
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
4748
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
4849
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
4950
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
5051
import org.springframework.cache.CacheManager;
5152
import org.springframework.context.annotation.Bean;
5253
import org.springframework.context.annotation.Configuration;
5354
import org.springframework.integration.monitor.IntegrationMBeanExporter;
55+
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
5456

5557
/**
5658
* {@link EnableAutoConfiguration Auto-configuration} for {@link PublicMetrics}.
5759
*
5860
* @author Stephane Nicoll
5961
* @author Phillip Webb
6062
* @author Johannes Edmeier
63+
* @author Artem Bilan
6164
* @since 1.2.0
6265
*/
6366
@Configuration
@@ -137,15 +140,23 @@ public CachePublicMetrics cachePublicMetrics() {
137140

138141
@Configuration
139142
@ConditionalOnClass(IntegrationMBeanExporter.class)
140-
@ConditionalOnBean(IntegrationMBeanExporter.class)
141143
static class IntegrationMetricsConfiguration {
142144

145+
@Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)
146+
@ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT)
147+
public IntegrationManagementConfigurer managementConfigurer() {
148+
IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
149+
configurer.setDefaultCountsEnabled(true);
150+
configurer.setDefaultStatsEnabled(true);
151+
return configurer;
152+
}
153+
143154
@Bean
144155
@ConditionalOnMissingBean(name = "springIntegrationPublicMetrics")
145156
public MetricReaderPublicMetrics springIntegrationPublicMetrics(
146-
IntegrationMBeanExporter exporter) {
157+
IntegrationManagementConfigurer managementConfigurer) {
147158
return new MetricReaderPublicMetrics(
148-
new SpringIntegrationMetricReader(exporter));
159+
new SpringIntegrationMetricReader(managementConfigurer));
149160
}
150161

151162
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReader.java

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@
2222

2323
import org.springframework.boot.actuate.metrics.Metric;
2424
import org.springframework.boot.actuate.metrics.reader.MetricReader;
25-
import org.springframework.integration.monitor.IntegrationMBeanExporter;
25+
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
26+
import org.springframework.integration.support.management.MessageChannelMetrics;
27+
import org.springframework.integration.support.management.MessageHandlerMetrics;
28+
import org.springframework.integration.support.management.MessageSourceMetrics;
29+
import org.springframework.integration.support.management.PollableChannelManagement;
2630
import org.springframework.integration.support.management.Statistics;
2731

2832
/**
2933
* A {@link MetricReader} for Spring Integration metrics (as provided by
30-
* spring-integration-jmx).
34+
* {@link IntegrationManagementConfigurer}).
3135
*
3236
* @author Dave Syer
37+
* @author Artem Bilan
3338
* @since 1.3.0
3439
*/
3540
public class SpringIntegrationMetricReader implements MetricReader {
3641

37-
private final IntegrationMBeanExporter exporter;
42+
private final IntegrationManagementConfigurer configurer;
3843

39-
public SpringIntegrationMetricReader(IntegrationMBeanExporter exporter) {
40-
this.exporter = exporter;
44+
public SpringIntegrationMetricReader(IntegrationManagementConfigurer configurer) {
45+
this.configurer = configurer;
4146
}
4247

4348
@Override
@@ -47,51 +52,80 @@ public Metric<?> findOne(String metricName) {
4752

4853
@Override
4954
public Iterable<Metric<?>> findAll() {
50-
IntegrationMBeanExporter exporter = this.exporter;
51-
List<Metric<?>> metrics = new ArrayList<Metric<?>>();
52-
for (String name : exporter.getChannelNames()) {
53-
String prefix = "integration.channel." + name;
54-
metrics.addAll(getStatistics(prefix + ".errorRate",
55-
exporter.getChannelErrorRate(name)));
56-
metrics.add(new Metric<Long>(prefix + ".sendCount",
57-
exporter.getChannelSendCountLong(name)));
58-
metrics.addAll(getStatistics(prefix + ".sendRate",
59-
exporter.getChannelSendRate(name)));
60-
metrics.add(new Metric<Long>(prefix + ".receiveCount",
61-
exporter.getChannelReceiveCountLong(name)));
55+
List<Metric<?>> result = new ArrayList<Metric<?>>();
56+
String[] channelNames = this.configurer.getChannelNames();
57+
String[] handlerNames = this.configurer.getHandlerNames();
58+
String[] sourceNames = this.configurer.getSourceNames();
59+
addChannelMetrics(result, channelNames);
60+
addHandlerMetrics(result, handlerNames);
61+
addSourceMetrics(result, sourceNames);
62+
result.add(new Metric<Integer>("integration.handlerCount", handlerNames.length));
63+
result.add(new Metric<Integer>("integration.channelCount", channelNames.length));
64+
result.add(new Metric<Integer>("integration.sourceCount", sourceNames.length));
65+
return result;
66+
}
67+
68+
private void addChannelMetrics(List<Metric<?>> result, String[] names) {
69+
for (String name : names) {
70+
addChannelMetrics(result, name, this.configurer.getChannelMetrics(name));
6271
}
63-
for (String name : exporter.getHandlerNames()) {
64-
metrics.addAll(getStatistics("integration.handler." + name + ".duration",
65-
exporter.getHandlerDuration(name)));
72+
}
73+
74+
private void addChannelMetrics(List<Metric<?>> result, String name,
75+
MessageChannelMetrics metrics) {
76+
String prefix = "integration.channel." + name;
77+
result.addAll(getStatistics(prefix + ".errorRate", metrics.getErrorRate()));
78+
result.add(new Metric<Long>(prefix + ".sendCount", metrics.getSendCountLong()));
79+
result.addAll(getStatistics(prefix + ".sendRate", metrics.getSendRate()));
80+
if (metrics instanceof PollableChannelManagement) {
81+
result.add(new Metric<Long>(prefix + ".receiveCount",
82+
((PollableChannelManagement) metrics).getReceiveCountLong()));
6683
}
67-
metrics.add(new Metric<Integer>("integration.activeHandlerCount",
68-
exporter.getActiveHandlerCount()));
69-
metrics.add(new Metric<Integer>("integration.handlerCount",
70-
exporter.getHandlerCount()));
71-
metrics.add(new Metric<Integer>("integration.channelCount",
72-
exporter.getChannelCount()));
73-
metrics.add(new Metric<Integer>("integration.queuedMessageCount",
74-
exporter.getQueuedMessageCount()));
75-
return metrics;
7684
}
7785

78-
private Collection<? extends Metric<?>> getStatistics(String name,
79-
Statistics statistic) {
86+
private void addHandlerMetrics(List<Metric<?>> result, String[] names) {
87+
for (String name : names) {
88+
addHandlerMetrics(result, name, this.configurer.getHandlerMetrics(name));
89+
}
90+
}
91+
92+
private void addHandlerMetrics(List<Metric<?>> result, String name,
93+
MessageHandlerMetrics metrics) {
94+
String prefix = "integration.handler." + name;
95+
result.addAll(getStatistics(prefix + ".duration", metrics.getDuration()));
96+
long activeCount = metrics.getActiveCountLong();
97+
result.add(new Metric<Long>(prefix + ".activeCount", activeCount));
98+
}
99+
100+
private void addSourceMetrics(List<Metric<?>> result, String[] names) {
101+
for (String name : names) {
102+
addSourceMetrics(result, name, this.configurer.getSourceMetrics(name));
103+
}
104+
}
105+
106+
private void addSourceMetrics(List<Metric<?>> result, String name,
107+
MessageSourceMetrics sourceMetrics) {
108+
String prefix = "integration.source." + name;
109+
result.add(new Metric<Long>(prefix + ".messageCount",
110+
sourceMetrics.getMessageCountLong()));
111+
}
112+
113+
private Collection<? extends Metric<?>> getStatistics(String name, Statistics stats) {
80114
List<Metric<?>> metrics = new ArrayList<Metric<?>>();
81-
metrics.add(new Metric<Double>(name + ".mean", statistic.getMean()));
82-
metrics.add(new Metric<Double>(name + ".max", statistic.getMax()));
83-
metrics.add(new Metric<Double>(name + ".min", statistic.getMin()));
84-
metrics.add(
85-
new Metric<Double>(name + ".stdev", statistic.getStandardDeviation()));
86-
metrics.add(new Metric<Long>(name + ".count", statistic.getCountLong()));
115+
metrics.add(new Metric<Double>(name + ".mean", stats.getMean()));
116+
metrics.add(new Metric<Double>(name + ".max", stats.getMax()));
117+
metrics.add(new Metric<Double>(name + ".min", stats.getMin()));
118+
metrics.add(new Metric<Double>(name + ".stdev", stats.getStandardDeviation()));
119+
metrics.add(new Metric<Long>(name + ".count", stats.getCountLong()));
87120
return metrics;
88121
}
89122

90123
@Override
91124
public long count() {
92-
int totalChannelCount = this.exporter.getChannelCount() * 11;
93-
int totalHandlerCount = this.exporter.getHandlerCount() * 5;
94-
return totalChannelCount + totalHandlerCount + 4;
125+
int totalChannelCount = this.configurer.getChannelNames().length;
126+
int totalHandlerCount = this.configurer.getHandlerNames().length;
127+
int totalSourceCount = this.configurer.getSourceNames().length;
128+
return totalChannelCount + totalHandlerCount + totalSourceCount;
95129
}
96130

97131
}

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void systemPublicMetrics() throws Exception {
9292
public void metricReaderPublicMetrics() throws Exception {
9393
load();
9494
assertThat(this.context.getBeansOfType(MetricReaderPublicMetrics.class))
95-
.hasSize(1);
95+
.hasSize(2);
9696
}
9797

9898
@Test

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpointIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4848

4949
/**
50-
* Integration tests for {@link JolokiaMvcEndpoint}
50+
* Integration tests for {@link JolokiaMvcEndpoint}.
5151
*
5252
* @author Christian Dupuis
5353
* @author Dave Syer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2012-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.metrics.integration;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.beans.factory.annotation.Qualifier;
24+
import org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration;
25+
import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics;
26+
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.context.annotation.Import;
30+
import org.springframework.test.annotation.DirtiesContext;
31+
import org.springframework.test.context.junit4.SpringRunner;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
/**
36+
* Tests for {@link SpringIntegrationMetricReader}.
37+
*
38+
* @author Artem Bilan
39+
*/
40+
@RunWith(SpringRunner.class)
41+
@SpringBootTest("spring.jmx.enabled=false")
42+
@DirtiesContext
43+
public class SpringIntegrationMetricReaderNoJmxTests {
44+
45+
@Autowired
46+
@Qualifier("springIntegrationPublicMetrics")
47+
private MetricReaderPublicMetrics integrationMetricReader;
48+
49+
@Test
50+
public void test() {
51+
assertThat(this.integrationMetricReader.metrics().size() > 0).isTrue();
52+
}
53+
54+
@Configuration
55+
@Import({ IntegrationAutoConfiguration.class, PublicMetricsAutoConfiguration.class })
56+
protected static class TestConfiguration {
57+
58+
}
59+
60+
}

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.context.annotation.Bean;
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.context.annotation.Import;
29-
import org.springframework.integration.monitor.IntegrationMBeanExporter;
29+
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
3030
import org.springframework.test.annotation.DirtiesContext;
3131
import org.springframework.test.context.junit4.SpringRunner;
3232

@@ -36,6 +36,7 @@
3636
* Tests for {@link SpringIntegrationMetricReader}.
3737
*
3838
* @author Dave Syer
39+
* @author Artem Bilan
3940
*/
4041
@RunWith(SpringRunner.class)
4142
@SpringBootTest("spring.jmx.enabled=true")
@@ -55,8 +56,9 @@ public void test() {
5556
protected static class TestConfiguration {
5657

5758
@Bean
58-
public SpringIntegrationMetricReader reader(IntegrationMBeanExporter exporter) {
59-
return new SpringIntegrationMetricReader(exporter);
59+
public SpringIntegrationMetricReader reader(
60+
IntegrationManagementConfigurer managementConfigurer) {
61+
return new SpringIntegrationMetricReader(managementConfigurer);
6062
}
6163

6264
}

0 commit comments

Comments
 (0)