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

Spring Boot minor upgrade brings major breaking changes to Metrics #30613

Closed
ghost opened this issue Apr 8, 2022 · 13 comments
Closed

Spring Boot minor upgrade brings major breaking changes to Metrics #30613

ghost opened this issue Apr 8, 2022 · 13 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@ghost
Copy link

ghost commented Apr 8, 2022

While updating our components to the recent 2.5.12 Spring boot version we came across an issue.
A "simple" minor update from version 2.5.3 to the new and secure 2.5.12 contains a hidden breaking change in the prometheus client version 0.10.0 that forces all counters to now have the suffix _total.
Our first approach was to try to force the use of the version 0.9.0 that we used before with no issues, but now, spring boot actuator uses methods that are only available after 0.10.0 and so using an older version of the client is no longer possible.

There were already complaints on the prometheus client side Issue 640 from people having the same issue.
The thing is, right now, some apps are not affected by the Spring4Shell vulnerability but in the near future there might a new vulnerability or even an extension to Spring4Shell that shows its efective against other types of spring boot apps and a lot of people will face this issue and will be unable to update to fix a serious security issue.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 8, 2022
@mhalbritter
Copy link
Contributor

mhalbritter commented Apr 8, 2022

I don't quite follow: Spring Boot 2.5.3 uses Prometheus 0.10.0, like Spring Boot 2.5.12. It's the same version. The update has been done in #27349 and #25250.

The only thing which changes from Boot 2.5.3 to 2.5.12 related to prometheus is

io.micrometer:micrometer-registry-prometheus:jar:1.7.2 vs io.micrometer:micrometer-registry-prometheus:jar:1.7.10

Spring Boot 2.4.x uses prometheus 0.9.0, so the breaking change was done from Boot 2.4.x to Boot 2.5.x.

You can use the CVE mitigation which updates only spring-framework to the fixed version and stay on 2.5.3. Details are here. A better approach would be to fix the metric names in the place where you are using them to the "new" prometheus format and then use the lastest Spring Boot 2.5.x (or even 2.6.x)

@mhalbritter mhalbritter added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 8, 2022
@ghost
Copy link
Author

ghost commented Apr 8, 2022

The issue is that between 2.5.3 and 2.5.12, not exactly sure where that change is made, it starts using org.springframework.boot.actuate.metrics.export.prometheus.TextOutputFormat.CONTENT_TYPE_OPENMETRICS_100
instead of org.springframework.boot.actuate.metrics.export.prometheus.TextOutputFormat.CONTENT_TYPE_004.

There is maybe a way to override that default?
I will def look into the mitigation, thank you

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 8, 2022
@mhalbritter
Copy link
Contributor

Ah, so the change isn't the version bump, it's the change of the TextOutputFormat somewhere. I will take a look.

@ghost
Copy link
Author

ghost commented Apr 8, 2022

The format comes from org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint.scrape
on the version 2.5.3 it comes as CONTENT_TYPE_004 but for 2.4.12 it comes as CONTENT_TYPE_OPENMETRICS_100 so it might be something further up.

The prometheus server doing the request is the same in both cases

@mhalbritter
Copy link
Contributor

I can absolutely observe no difference in counter names between 2.4.x, 2.5.3 and 2.5.12. Do you have a sample where this can be reproduced?

2.4.13

# HELP foo_total  
# TYPE foo_total counter
foo_total 1.0

2.5.3

# HELP foo_total  
# TYPE foo_total counter
foo_total 1.0


2.5.12

# HELP foo_total  
# TYPE foo_total counter
foo_total 1.0

@wilkinsona
Copy link
Member

wilkinsona commented Apr 8, 2022

CONTENT_TYPE_OPENMETRICS_100 should only be served if it's acceptable to the client (the Prometheus server in this case). In addition to a sample, it would also be useful to know what Accept header your Prometheus server is sending and why, assuming that it indicates that CONTENT_TYPE_OPENMETRICS_100 is acceptable, it's a problem for it to receive content in that format.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Apr 8, 2022
@mhalbritter
Copy link
Contributor

In #28130, there has been a change.

When sending Accept: application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1

Spring boot 2.5.3 answers with

HTTP/1.1 200 
Content-Type: text/plain;version=0.0.4;charset=utf-8
Content-Length: 7570
Date: Fri, 08 Apr 2022 12:49:42 GMT

# HELP bar_total  
# TYPE bar_total counter
bar_total 2.0

while 2.5.12 answers with

HTTP/1.1 200 
Content-Type: application/openmetrics-text;version=1.0.0;charset=utf-8
Content-Length: 7469
Date: Fri, 08 Apr 2022 12:50:21 GMT

# TYPE bar counter
# HELP bar  
bar_total 2.0

@wilkinsona
Copy link
Member

Thanks, Moritz. That behavior aligns with Prometheus's own TextFormat class so I don't think we should change it. @nandoFromSky I think we really need to know what accept header your server is sending and why the resulting response is a problem to make progress on this.

@ghost
Copy link
Author

ghost commented Apr 8, 2022

@mhalbritter its probably it, i will investigate what our prometheus server is doing and if its that it should be an easy work around while we attempt to migrate metrics to use _total in all our systems

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 8, 2022
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Apr 8, 2022
@scottfrederick scottfrederick changed the title Spring4Shell minor upgrade brings major breaking changes to Metrics Spring Boot minor upgrade brings major breaking changes to Metrics Apr 8, 2022
@ghost
Copy link
Author

ghost commented Apr 8, 2022

Prometheus afaik does not allow us to define the headers.
But, one can always override PrometheusScrapeEndpoint and TextOutputFormat to force the use of the TextFormat.write004.

This way we can still use the 0.9.0 prometheus client to avoid the _total and keep everything working normally.

Still need to run some other tests to see if there is any impact but seems like it should work

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 8, 2022
@wilkinsona
Copy link
Member

Thanks, @nandoFromSky. I’ll close this one for now. Please let us know if it doesn’t work as hoped and we can take another look.

@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Apr 9, 2022
@deepak-auto
Copy link

deepak-auto commented Jun 13, 2022

Hi @nandoFromSky and @wilkinsona, would you happen to know of a recommended approach to work around the _total suffix?

@wilkinsona
Copy link
Member

IIRC, you should be able to send a different accept header to get the metrics in a different format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants