Skip to content

Commit 4d8df3c

Browse files
committed
Polish "Allow configuration of auto-timed metrics"
This commit makes sure the "auto-time-requests" property is still available in a deprecated fashion. See gh-15988
1 parent 128b41d commit 4d8df3c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,37 @@ public ServerRequest getRequest() {
184184
return this.request;
185185
}
186186

187+
/**
188+
* Return whether server requests should be automatically timed.
189+
* @return {@code true} if server request should be automatically timed
190+
* @deprecated since 2.2.0 in favor of {@link Autotime#isEnabled()}
191+
*/
192+
@DeprecatedConfigurationProperty(
193+
replacement = "management.metrics.web.server.request.autotime.enabled")
194+
@Deprecated
195+
public boolean isAutoTimeRequests() {
196+
return this.request.getAutotime().isEnabled();
197+
}
198+
199+
/**
200+
* Set whether server requests should be automatically timed.
201+
* @param autoTimeRequests whether server requests should be automatically
202+
* timed
203+
* @deprecated since 2.2.0 in favor of {@link Autotime#isEnabled()}
204+
*/
205+
@Deprecated
206+
public void setAutoTimeRequests(boolean autoTimeRequests) {
207+
this.request.getAutotime().setEnabled(autoTimeRequests);
208+
}
209+
187210
/**
188211
* Return name of the metric for server requests.
189212
* @return request metric name
190213
* @deprecated since 2.2.0 in favor of {@link ServerRequest#getMetricName()}
191214
*/
192215
@DeprecatedConfigurationProperty(
193216
replacement = "management.metrics.web.server.request.metric-name")
217+
@Deprecated
194218
public String getRequestsMetricName() {
195219
return this.request.getMetricName();
196220
}
@@ -201,6 +225,7 @@ public String getRequestsMetricName() {
201225
* @deprecated since 2.2.0 in favor of
202226
* {@link ServerRequest#setMetricName(String)}
203227
*/
228+
@Deprecated
204229
public void setRequestsMetricName(String requestsMetricName) {
205230
this.request.setMetricName(requestsMetricName);
206231
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/reactive/WebFluxMetricsAutoConfigurationTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ public void metricsAreNotRecordedIfAutoTimeRequestsIsDisabled() {
109109
});
110110
}
111111

112+
@Test
113+
@Deprecated
114+
public void metricsAreNotRecordedIfAutoTimeRequestsIsDisabledWithDeprecatedProperty() {
115+
this.contextRunner
116+
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
117+
.withUserConfiguration(TestController.class)
118+
.withPropertyValues(
119+
"management.metrics.web.server.auto-time-requests=false")
120+
.run((context) -> {
121+
MeterRegistry registry = getInitializedMeterRegistry(context);
122+
assertThat(registry.find("http.server.requests").meter()).isNull();
123+
});
124+
}
125+
112126
private MeterRegistry getInitializedMeterRegistry(
113127
AssertableReactiveWebApplicationContext context) {
114128
WebTestClient webTestClient = WebTestClient.bindToApplicationContext(context)

0 commit comments

Comments
 (0)