-
Notifications
You must be signed in to change notification settings - Fork 1k
Add MeterFilter.forMeters utility method #6594
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
Add MeterFilter.forMeters utility method #6594
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>
067e2a7
to
d659b8b
Compare
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 |
I introduced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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>
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>
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.