Skip to content

Commit a031bf4

Browse files
committed
Merge branch '3.0.x'
Closes gh-34867
2 parents 041d3d3 + 378b468 commit a031bf4

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ dependencies {
116116
optional("org.springframework:spring-webflux")
117117
optional("org.springframework:spring-webmvc")
118118
optional("org.springframework.amqp:spring-rabbit")
119+
optional("org.springframework.batch:spring-batch-core")
119120
optional("org.springframework.data:spring-data-cassandra") {
120121
exclude group: "org.slf4j", module: "jcl-over-slf4j"
121122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2012-2023 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.observation.batch;
18+
19+
import io.micrometer.observation.ObservationRegistry;
20+
21+
import org.springframework.batch.core.configuration.annotation.BatchObservabilityBeanPostProcessor;
22+
import org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration;
23+
import org.springframework.boot.autoconfigure.AutoConfiguration;
24+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28+
import org.springframework.context.annotation.Bean;
29+
30+
/**
31+
* {@link EnableAutoConfiguration Auto-configuration} for instrumentation of Spring Batch
32+
* Jobs.
33+
*
34+
* @author Mark Bonnekessel
35+
* @since 3.0.6
36+
*/
37+
@AutoConfiguration(after = ObservationAutoConfiguration.class)
38+
@ConditionalOnBean(ObservationRegistry.class)
39+
@ConditionalOnClass({ ObservationRegistry.class, BatchObservabilityBeanPostProcessor.class })
40+
public class BatchObservationAutoConfiguration {
41+
42+
@ConditionalOnMissingBean
43+
@Bean
44+
public static BatchObservabilityBeanPostProcessor batchObservabilityBeanPostProcessor() {
45+
return new BatchObservabilityBeanPostProcessor();
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2023 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 Batch observations.
19+
*/
20+
package org.springframework.boot.actuate.autoconfigure.observation.batch;

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetri
6868
org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver.StackdriverMetricsExportAutoConfiguration
6969
org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration
7070
org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontMetricsExportAutoConfiguration
71+
org.springframework.boot.actuate.autoconfigure.observation.batch.BatchObservationAutoConfiguration
7172
org.springframework.boot.actuate.autoconfigure.observation.graphql.GraphQlObservationAutoConfiguration
7273
org.springframework.boot.actuate.autoconfigure.metrics.integration.IntegrationMetricsAutoConfiguration
7374
org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2012-2023 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.observation.batch;
18+
19+
import io.micrometer.observation.tck.TestObservationRegistry;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.batch.core.configuration.annotation.BatchObservabilityBeanPostProcessor;
23+
import org.springframework.boot.autoconfigure.AutoConfigurations;
24+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* Tests for {@link BatchObservationAutoConfiguration}.
30+
*
31+
* @author Mark Bonnekessel
32+
*/
33+
class BatchObservationAutoConfigurationTests {
34+
35+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
36+
.withBean(TestObservationRegistry.class, TestObservationRegistry::create)
37+
.withConfiguration(AutoConfigurations.of(BatchObservationAutoConfiguration.class));
38+
39+
@Test
40+
void backsOffWhenObservationRegistryIsMissing() {
41+
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(BatchObservationAutoConfiguration.class))
42+
.run((context) -> assertThat(context).doesNotHaveBean(BatchObservabilityBeanPostProcessor.class));
43+
}
44+
45+
@Test
46+
void beanIsPresentWhenSpringBatchIsPresent() {
47+
this.contextRunner
48+
.run((context) -> assertThat(context).hasSingleBean(BatchObservabilityBeanPostProcessor.class));
49+
}
50+
51+
}

spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,22 @@ NOTE: Only caches that are configured on startup are bound to the registry.
858858
For caches not defined in the cache’s configuration, such as caches created on the fly or programmatically after the startup phase, an explicit registration is required.
859859
A `CacheMetricsRegistrar` bean is made available to make that process easier.
860860

861+
862+
863+
[[actuator.metrics.supported.spring-batch]]
864+
==== Spring Batch Metrics
865+
866+
See the {spring-batch-docs}monitoring-and-metrics.html[Spring Batch reference documentation].
867+
868+
869+
861870
[[actuator.metrics.supported.spring-graphql]]
862871
==== Spring GraphQL Metrics
863872

864873
See the {spring-graphql-docs}[Spring GraphQL reference documentation].
865874

866875

876+
867877
[[actuator.metrics.supported.jdbc]]
868878
==== DataSource Metrics
869879
Auto-configuration enables the instrumentation of all available `DataSource` objects with metrics prefixed with `jdbc.connections`.

0 commit comments

Comments
 (0)