Skip to content

Add ability to filter out metric by id name #5616

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ibilley7
Copy link
Contributor

@ibilley7 ibilley7 commented Jun 4, 2025

Users might want to the ability to filter out metrics that are not necessary for them to view. Created a static getMeterFilter function in MeterRegistryFactory to filter out metrics user does not want to see. Created new Property GENERAL_MICROMETER_ID_FILTERS, and filters specified via this property will be added to meter registries created in MeterInfoImpl

Closes issue #4599

Users might want to the ability to filter out metrics that are not necessary for them to view. Created a static getMeterFilter function in MeterRegistryFactory to filter out metrics user does not want to see. Created new Property GENERAL_MICROMETER_ID_FILTERS, and filters specified via this property will be added to meter registries created in MeterInfoImpl

Closes issue apache#4599
@DomGarguilo DomGarguilo added this to the 4.0.0 milestone Jun 4, 2025
@lbschanno
Copy link
Contributor

This PR is failing checks because we need to specifically allow the MeterFilter class within the apilyzer configuration. You need to insert the following:

<allow>io[.]micrometer[.]core[.]instrument[.]config[.]MeterFilter</allow>

to core/pom.xml, directly below where there is a similar statement for MeterRegistry, line 301, so that we then have the following:

 <allows>
                <allow>io[.]micrometer[.]core[.]instrument[.]MeterRegistry</allow>
                <allow>io[.]micrometer[.]core[.]instrument[.]config[.]MeterFilter</allow>
                <allow>io[.]opentelemetry[.]api[.]OpenTelemetry</allow>
                ...

ibilley7 and others added 3 commits June 12, 2025 14:05
…csInfoImpl.java. Moved MeterRegistryFactoryTest.java test cases into the MetricsInfoImplTest.java file and changed variable types to reflect the new location of the code.
…csInfoImpl.java. Moved MeterRegistryFactoryTest.java test cases into the MetricsInfoImplTest.java file and changed variable types to reflect the new location of the code.
Copy link
Member

@DomGarguilo DomGarguilo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good. I am wondering if we should switch the filtering from a "deny list" to an "accept list" i.e. instead of defining which meters we want to filter out, we define a filter for only the meters we want to see. I don't think it makes a huge difference but might make things more intuitive or safer but I'm open to considering others opinions on this.

*/
public static MeterFilter getMeterFilter(String patternList) {
requireNonNull(patternList, "patternList must not be null");
Preconditions.checkArgument(!patternList.isEmpty(), "patternList must not be empty");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should allow an empty value here. The default value is currently an empty String anyways. We could just handle an empty string as no filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't passing an empty string through the function defeat the purpose of getMeterFilter?

…erFilter function in MetricsInfoImpl, trimmed whitespace from patternList, set finalPredicate to id->false instead of null to OR the predicates together without having to set the first predicate equal to finalPredicate and so that the return statement doesn't have to include reuireNonNullElseGet
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

Successfully merging this pull request may close these issues.

4 participants