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

Warn when a MeterFilter is configured after a meter is registered #4917

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

shakuzen
Copy link
Member

@shakuzen shakuzen commented Apr 2, 2024

In normal usage we would expect this should not happen, but there is nothing enforcing or encouraging it to not happen. This warns users via logging that it is happening and advises to correct it, if possible. Otherwise, we want to learn about why it is not fixable. The problem with configuring MeterFilters after a Meter has been registered is that such filters will not be applied to previously registered meters. This can result in a mix of metrics with all filters applied and only some filters applied, which is potentially hard to notice.

@shakuzen shakuzen added enhancement A general enhancement module: micrometer-core An issue that is related to our core module labels Apr 2, 2024
@shakuzen shakuzen added this to the 1.13.0-RC1 milestone Apr 2, 2024
@shakuzen shakuzen force-pushed the warn-filter-config branch 4 times, most recently from d1e60fd to 17acc78 Compare April 2, 2024 08:35
@lenin-jaganathan
Copy link
Contributor

FFT:

  1. Should we deal with the composite meter registries differently?
  2. How would this likely affect the parent and child registries and the addition of meter filters in composite registries.

@shakuzen
Copy link
Member Author

shakuzen commented Apr 4, 2024

Thanks for the review. I didn't particularly think about composite registries. What kind of scenarios are you thinking might require special attention?

@lenin-jaganathan
Copy link
Contributor

Thanks for the review. I didn't particularly think about composite registries. What kind of scenarios are you thinking might require special attention?

One particular case I am aware of is with Metrics.globalRegistry. We use spring-boot actuator for wiring up the registries and then add them to the global one. There are third-party libraries that add metrics directly to the global registries and sometimes this happens before we add any meter filters.

Why we add filters to global registry?
This is to avoid overusing memory when third party libraries / users add meters directly to the global registry.

@shakuzen
Copy link
Member Author

shakuzen commented Apr 8, 2024

Thanks for the feedback. That's good to be aware of.

There are third-party libraries that add metrics directly to the global registries and sometimes this happens before we add any meter filters.

If whatever is configuring everything (e.g. Spring Boot auto-config) can be made to not do what will result in registering meters until after filters have been configured, this should be solvable. It's just made harder by there being a "hidden" dependency on the global MeterRegistry that e.g. Spring Boot doesn't and can't automatically know about.

It's not clear what we can/should change about this pull request for this yet, so let's get this into RC1 and collect feedback. Let's try to figure out as many of these scenarios as we can in the upcoming month before GA based on testing with the RC1 version. Hopefully we can find a good solution for these.

In normal usage we would expect this should not happen, but there is nothing enforcing or encouraging it to not happen. This warns users via logging that it is happening and advises to correct it, if possible. Otherwise, we want to learn about why it is not fixable. The problem with configuring MeterFilters after a Meter has been registered is that such filters will not be applied to previously registered meters. This can result in a mix of metrics with all filters applied and only some filters applied, which is potentially hard to notice.
@shakuzen shakuzen merged commit 4d8f217 into micrometer-metrics:main Apr 8, 2024
6 checks passed
@shakuzen shakuzen deleted the warn-filter-config branch April 8, 2024 03:21
izeye added a commit to izeye/micrometer that referenced this pull request Jun 24, 2024
@izeye izeye mentioned this pull request Jun 24, 2024
izeye added a commit to izeye/micrometer that referenced this pull request Jun 24, 2024
shakuzen pushed a commit that referenced this pull request Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants