Skip to content

Commit fbf4c8c

Browse files
committed
Merge pull request #24095 from artembilan
* gh-24095: Polish "Ensure that MeterRegistry bean is defined before SI looks for it" Ensure that MeterRegistry bean is defined before SI looks for it Closes gh-24095
2 parents 96e40e9 + 08b9d1d commit fbf4c8c

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2012-2020 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+
* https://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.autoconfigure.metrics.integration;
18+
19+
import io.micrometer.core.instrument.MeterRegistry;
20+
21+
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
22+
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
23+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
24+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
25+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
26+
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
27+
import org.springframework.context.annotation.Configuration;
28+
29+
/**
30+
* {@link EnableAutoConfiguration Auto-configuration} for Spring Integration's metrics.
31+
* Orders auto-configuration classes to ensure that the {@link MeterRegistry} bean has
32+
* been defined before Spring Integration's Micrometer support queries the bean factory
33+
* for it.
34+
*
35+
* @author Andy Wilkinson
36+
*/
37+
@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
38+
@AutoConfigureBefore(IntegrationAutoConfiguration.class)
39+
@Configuration(proxyBeanMethods = false)
40+
class IntegrationMetricsAutoConfiguration {
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2019 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+
* https://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+
/**
18+
* Auto-configuration for Spring Integration metrics.
19+
*/
20+
package org.springframework.boot.actuate.autoconfigure.metrics.integration;

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxM
6565
org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration,\
6666
org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration,\
6767
org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontMetricsExportAutoConfiguration,\
68+
org.springframework.boot.actuate.autoconfigure.metrics.integration.IntegrationMetricsAutoConfiguration,\
6869
org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration,\
6970
org.springframework.boot.actuate.autoconfigure.metrics.jersey.JerseyServerMetricsAutoConfiguration,\
7071
org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration,\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012-2020 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+
* https://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.autoconfigure.metrics.integration;
18+
19+
import io.micrometer.core.instrument.Gauge;
20+
import io.micrometer.core.instrument.MeterRegistry;
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.boot.actuate.autoconfigure.integration.IntegrationGraphEndpointAutoConfiguration;
24+
import org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration;
25+
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
26+
import org.springframework.boot.autoconfigure.AutoConfigurations;
27+
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
28+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Tests for {@link RabbitMetricsAutoConfiguration}.
34+
*
35+
* @author Artem Bilan
36+
*/
37+
class IntegrationMetricsAutoConfigurationTests {
38+
39+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
40+
.withConfiguration(AutoConfigurations.of(IntegrationAutoConfiguration.class,
41+
IntegrationGraphEndpointAutoConfiguration.class, IntegrationMetricsAutoConfiguration.class))
42+
.with(MetricsRun.simple()).withPropertyValues("management.metrics.tags.someTag=someValue");
43+
44+
@Test
45+
void integrationMetersAreInstrumented() {
46+
this.contextRunner.run((context) -> {
47+
MeterRegistry registry = context.getBean(MeterRegistry.class);
48+
Gauge gauge = registry.get("spring.integration.channels").tag("someTag", "someValue").gauge();
49+
assertThat(gauge).isNotNull().extracting(Gauge::value).isEqualTo(2.0);
50+
});
51+
}
52+
53+
}

0 commit comments

Comments
 (0)