Commit d3b3c8c6 authored by Andy Wilkinson's avatar Andy Wilkinson

Honour management.metrics.web.server.auto-time-requests with WebFlux

Closes gh-13895
parent 1f34da90
...@@ -66,7 +66,8 @@ public class WebFluxMetricsAutoConfiguration { ...@@ -66,7 +66,8 @@ public class WebFluxMetricsAutoConfiguration {
public MetricsWebFilter webfluxMetrics(MeterRegistry registry, public MetricsWebFilter webfluxMetrics(MeterRegistry registry,
WebFluxTagsProvider tagConfigurer) { WebFluxTagsProvider tagConfigurer) {
return new MetricsWebFilter(registry, tagConfigurer, return new MetricsWebFilter(registry, tagConfigurer,
this.properties.getWeb().getServer().getRequestsMetricName()); this.properties.getWeb().getServer().getRequestsMetricName(),
this.properties.getWeb().getServer().isAutoTimeRequests());
} }
@Bean @Bean
......
...@@ -98,6 +98,19 @@ public class WebFluxMetricsAutoConfigurationTests { ...@@ -98,6 +98,19 @@ public class WebFluxMetricsAutoConfigurationTests {
}); });
} }
@Test
public void metricsAreNotRecordedIfAutoTimeRequestsIsDisabled() {
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)
......
...@@ -46,16 +46,36 @@ public class MetricsWebFilter implements WebFilter { ...@@ -46,16 +46,36 @@ public class MetricsWebFilter implements WebFilter {
private final String metricName; private final String metricName;
private final boolean autoTimeRequests;
/**
* Create a new {@code MetricsWebFilter}.
* @param registry the registry to which metrics are recorded
* @param tagsProvider provider for metrics tags
* @param metricName name of the metric to record
* @deprecated since 2.0.6 in favour of
* {@link #MetricsWebFilter(MeterRegistry, WebFluxTagsProvider, String, boolean)}
*/
@Deprecated
public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider, public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider,
String metricName) { String metricName) {
this(registry, tagsProvider, metricName, true);
}
public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider,
String metricName, boolean autoTimeRequests) {
this.registry = registry; this.registry = registry;
this.tagsProvider = tagsProvider; this.tagsProvider = tagsProvider;
this.metricName = metricName; this.metricName = metricName;
this.autoTimeRequests = autoTimeRequests;
} }
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange).compose((call) -> filter(exchange, call)); if (this.autoTimeRequests) {
return chain.filter(exchange).compose((call) -> filter(exchange, call));
}
return chain.filter(exchange);
} }
private Publisher<Void> filter(ServerWebExchange exchange, Mono<Void> call) { private Publisher<Void> filter(ServerWebExchange exchange, Mono<Void> call) {
......
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