Repository navigation
Add MeterFilter.forMeters utility method - #6594
Merged
shakuzen merged 2 commits intoAug 12, 2025
Merged
Conversation
I have noticed that I often want to configure MeterFilters only for a selection of meters that start with a given prefix. For example, I might want to ignore tags for a selection of metrics, but not for all of them. The "normal" approach would be to write a custom MeterFilter that checks the name before filtering. The new utility method helps with this task. Signed-off-by: Peter Jeschke <peter@jeschke.dev>
peterjeschke
force-pushed
the
feature/forPrefix
branch
from
August 7, 2025 19:43
067e2a7 to
d659b8b
Compare
Member
|
Thank you for the PR! I'm thinking if it would make sense making this a bit more general: static MeterFilter forMeters(Predicate<Meter.Id> predicate, MeterFilter delegate) { ... }Using private static final String MAGIC_PREFIX = "test2;
MeterFilter.forPrefix("test", MeterFilter.ignoreTags("ignored"));
MeterFilter.forPrefix(MAGIC_PREFIX, MeterFilter.ignoreTags("ignored"));While private static final Predicate<Meter.Id> MAGIC_PREFIX_SELECTOR = id -> id.getName().startsWith("test2");
MeterFilter.forMeters(id -> id.getName().startsWith("test"), MeterFilter.ignoreTags("ignored"));
MeterFilter.forMeters(MAGIC_PREFIX_SELECTOR, MeterFilter.ignoreTags("ignored"));
MeterFilter.forMeters(startsWith("test"), MeterFilter.ignoreTags("ignored")); // you implement startsWith it but it's a one-liner |
Member
|
I introduced |
shakuzen
approved these changes
Aug 12, 2025
shakuzen
left a comment
Member
There was a problem hiding this comment.
It seems nice for convenience. It's a bit inefficient to override all the methods and use the predicate if the delegate only implements one of the methods, but in practice I suppose this shouldn't be much of an issue thanks to the pre-filter cache we have in place. For calls that don't hit the cache, using this may be less efficient than more directly implemented filters.
peterjeschke
added a commit
to peterjeschke/micrometer
that referenced
this pull request
Aug 17, 2025
A follow-up to micrometer-metrics#6594, this adds the most likely predicates for usage with MeterFilter.forMeters Signed-off-by: Peter Jeschke <peter@jeschke.dev>
peterjeschke
added a commit
to peterjeschke/micrometer
that referenced
this pull request
Aug 17, 2025
A follow-up to micrometer-metrics#6594, this adds the most likely predicates for usage with MeterFilter.forMeters Signed-off-by: Peter Jeschke <peter@jeschke.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have noticed that I often want to configure MeterFilters only for a selection of meters that start with a given prefix. For example, I might want to ignore tags for a selection of metrics, but not for all of them. The "normal" approach would be to write a custom MeterFilter that checks the name before filtering. The new utility method helps with this task.