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

Problem with prometheus metrics and mongodb #40128

Closed
gnom7 opened this issue Mar 28, 2024 · 4 comments
Closed

Problem with prometheus metrics and mongodb #40128

gnom7 opened this issue Mar 28, 2024 · 4 comments

Comments

@gnom7
Copy link

gnom7 commented Mar 28, 2024

I noticed that common tags are not applied on service that uses MongoDB. In debugging I see that for some reason MongoMetricsConnectionPoolListener logic kicks (and interacts with MeterRegistry) before MetricsAutoConfiguration had a chance to configure and apply MeterRegistryPostProcessor (spring boot v3.2.3).

Might be related to #26665

For now I just disabled (exclude = [MongoMetricsAutoConfiguration::class]) mongo metrics and it fixes behavior.

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

Thanks for the report. If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Mar 28, 2024
@gnom7
Copy link
Author

gnom7 commented Mar 28, 2024

I have tried to create small repro using spring initializr, but unfortunately basic project doesn't help.

Not sure what exactly causes out of order processing in my application, it looks like this:
MongoAutoConfiguration -> PrometheusMetricsExportAutoConfiguration -> MongoMetricsAutoConfiguration -> MetricsAutoConfiguration

One thought was that premature execution of MongoAutoConfiguration (which in turn causes metrics to be initialized via MongoMetricsConnectionPoolListener when mongo's connection pool gets created) was caused by Mongock which applies MongoDB migrations at the application startup, but adding Mongock with some migrations to the repro project doesn't help either.

BTW #26665 (comment) this workaround also works in my case, so no need to disable mongo metrics in the end.

@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 Mar 28, 2024
@mhalbritter
Copy link
Contributor

mhalbritter commented Mar 28, 2024

A breakpoint in org.springframework.boot.autoconfigure.AutoConfigurationSorter#getInPriorityOrder on the return orderedClassNames; may help with debugging. orderedClassNames contains the list of auto-configurations in the order they will be loaded.

I suspect something in the application is using the MeterRegistry quite early and breaks stuff (see this comment).

@mhalbritter mhalbritter added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 28, 2024
@gnom7
Copy link
Author

gnom7 commented Mar 28, 2024

You are right, after I have carefully investigated call stack from the MongoAutoConfiguration#mongo I was able to find the place where mongo repository was injected eagerly in some early stages of application startup. Making that injection lazy helped.

Thanks @mhalbritter

@gnom7 gnom7 closed this as completed Mar 28, 2024
@scottfrederick scottfrederick closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
@scottfrederick scottfrederick removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants