Commit 4d8df3cc authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 128b41d4
...@@ -184,6 +184,29 @@ public class MetricsProperties { ...@@ -184,6 +184,29 @@ public class MetricsProperties {
return this.request; return this.request;
} }
/**
* Return whether server requests should be automatically timed.
* @return {@code true} if server request should be automatically timed
* @deprecated since 2.2.0 in favor of {@link Autotime#isEnabled()}
*/
@DeprecatedConfigurationProperty(
replacement = "management.metrics.web.server.request.autotime.enabled")
@Deprecated
public boolean isAutoTimeRequests() {
return this.request.getAutotime().isEnabled();
}
/**
* Set whether server requests should be automatically timed.
* @param autoTimeRequests whether server requests should be automatically
* timed
* @deprecated since 2.2.0 in favor of {@link Autotime#isEnabled()}
*/
@Deprecated
public void setAutoTimeRequests(boolean autoTimeRequests) {
this.request.getAutotime().setEnabled(autoTimeRequests);
}
/** /**
* Return name of the metric for server requests. * Return name of the metric for server requests.
* @return request metric name * @return request metric name
...@@ -191,6 +214,7 @@ public class MetricsProperties { ...@@ -191,6 +214,7 @@ public class MetricsProperties {
*/ */
@DeprecatedConfigurationProperty( @DeprecatedConfigurationProperty(
replacement = "management.metrics.web.server.request.metric-name") replacement = "management.metrics.web.server.request.metric-name")
@Deprecated
public String getRequestsMetricName() { public String getRequestsMetricName() {
return this.request.getMetricName(); return this.request.getMetricName();
} }
...@@ -201,6 +225,7 @@ public class MetricsProperties { ...@@ -201,6 +225,7 @@ public class MetricsProperties {
* @deprecated since 2.2.0 in favor of * @deprecated since 2.2.0 in favor of
* {@link ServerRequest#setMetricName(String)} * {@link ServerRequest#setMetricName(String)}
*/ */
@Deprecated
public void setRequestsMetricName(String requestsMetricName) { public void setRequestsMetricName(String requestsMetricName) {
this.request.setMetricName(requestsMetricName); this.request.setMetricName(requestsMetricName);
} }
......
...@@ -109,6 +109,20 @@ public class WebFluxMetricsAutoConfigurationTests { ...@@ -109,6 +109,20 @@ public class WebFluxMetricsAutoConfigurationTests {
}); });
} }
@Test
@Deprecated
public void metricsAreNotRecordedIfAutoTimeRequestsIsDisabledWithDeprecatedProperty() {
this.contextRunner
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
.withUserConfiguration(TestController.class)
.withPropertyValues(
"management.metrics.web.server.auto-time-requests=false")
.run((context) -> {
MeterRegistry registry = getInitializedMeterRegistry(context);
assertThat(registry.find("http.server.requests").meter()).isNull();
});
}
private MeterRegistry getInitializedMeterRegistry( private MeterRegistry getInitializedMeterRegistry(
AssertableReactiveWebApplicationContext context) { AssertableReactiveWebApplicationContext context) {
WebTestClient webTestClient = WebTestClient.bindToApplicationContext(context) WebTestClient webTestClient = WebTestClient.bindToApplicationContext(context)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment