Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebMvcMetricsFilter stopped working since 2.7.0 #31150

Closed
varpa89 opened this issue May 23, 2022 · 6 comments
Closed

WebMvcMetricsFilter stopped working since 2.7.0 #31150

varpa89 opened this issue May 23, 2022 · 6 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@varpa89
Copy link

varpa89 commented May 23, 2022

Since Spring Boot 2.7.0 there is no WebMvcMetricsFilter in the context from WebMvcMetricsAutoConfiguration so we lost timing metrics.
Probably we should specify the class in @ConditionalOnMissingBean annotation

@Bean
@ConditionalOnMissingBean
public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MeterRegistry registry,
        WebMvcTagsProvider tagsProvider) {
    ServerRequest request = this.properties.getWeb().getServer().getRequest();
    WebMvcMetricsFilter filter = new WebMvcMetricsFilter(registry, tagsProvider, request.getMetricName(),
            request.getAutotime());
    FilterRegistrationBean<WebMvcMetricsFilter> registration = new FilterRegistrationBean<>(filter);
    registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
    registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
    return registration;
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 23, 2022
@wilkinsona
Copy link
Member

Thanks for the report, @varpa89, and apologies for the inconvenience. You can work around the problem with the following bean declaration in your application:

public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MetricsProperties properties,
        MeterRegistry registry, WebMvcTagsProvider tagsProvider) {
    ServerRequest request = properties.getWeb().getServer().getRequest();
    WebMvcMetricsFilter filter = new WebMvcMetricsFilter(registry, tagsProvider, request.getMetricName(),
            request.getAutotime());
    FilterRegistrationBean<WebMvcMetricsFilter> registration = new FilterRegistrationBean<>(filter);
    registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
    registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
    return registration;
}

@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels May 23, 2022
@wilkinsona wilkinsona added this to the 2.7.1 milestone May 23, 2022
@wilkinsona wilkinsona self-assigned this May 23, 2022
@rikostave1234
Copy link

rikostave1234 commented May 24, 2022

Do I understand correctly that previous behaviour will be restored with v2.7.1 ? The update to v2.7.0 broke our @Timed metrics as well.

@wilkinsona
Copy link
Member

Correct. You can confirm that's the case by trying a 2.7.1-SNAPSHOT available from https://repo.spring.io/snapshot or using the workaround above. If you still have a problem with @Timed with the metrics filter in place, there may be another problem that we'll need to investigate.

MediaMarco added a commit to otto-de/edison-microservice that referenced this issue May 24, 2022
Co-authored-by: Marco Geweke <marco.geweke@otto.de>
@ChristianAnke
Copy link

Hey,

a workaround with a bit more code reuse:

	@Bean
	@ConditionalOnMissingFilterBean
	public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(
			WebMvcMetricsAutoConfiguration webMvcMetricsAutoConfiguration,
			MeterRegistry registry, WebMvcTagsProvider tagsProvider) {
		return webMvcMetricsAutoConfiguration.webMvcMetricsFilter(registry, tagsProvider);
	}

@wilkinsona
Copy link
Member

Thanks for trying to help, @ChristianAnke, but we do not recommend injecting (auto-)configuration classes and calling methods on them. While the workaround above is slightly more verbose, we believe it's more robust and is what we recommend users do until 2.7.1 has been released with a fix.

@olivergregorius
Copy link

Thanks @varpa89 for your workaround, saved my day :-)
BTW Spring Boot 2.7.1 - including the fix - has been released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

6 participants