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

Add Prefix Support for Metric Names in CacheMeterBinder #4047

Closed
fartzy opened this issue Aug 26, 2023 · 7 comments
Closed

Add Prefix Support for Metric Names in CacheMeterBinder #4047

fartzy opened this issue Aug 26, 2023 · 7 comments

Comments

@fartzy
Copy link

fartzy commented Aug 26, 2023

Please describe the feature request.
I would like to modify the CacheMeterBinder abstract class to support prefixing metric names. As of now, the metric names are hard coded when the metrics are created in the public final void bindTo(MeterRegistry registry) method and then registered. Specifically, I propose adding a method getMetricNamePrefix() which returns a prefix string that can be added to the front of all metric names in - which will be in modifying the bindTo() method. This allows for better customization and adaptability in various system settings.

Rationale
Without the proposed feature, it is impossible to rename metrics without deleting the existing cache metrics in the bindImplementationSpecificMetrics() method and re-registering them with new, prefixed names. This capability is particularly useful for specialized systems like ActiveMQ-Artemis, which adhere to unique metric naming conventions. For instance, these cache metrics could be applied to the authorization and authentication caches utilized for access control within the message broker. Deleting, recreating, and re-registering metrics is an inefficient way to align metric names. As such, the ability to add prefixes to metrics is essential for the seamless integration of Micrometer's cache metrics with ActiveMQ-Artemis or any other systems that prefer strict naming conventions for metrics. This feature would eliminate the need to delete and re-register cache metrics, thereby simplifying cache metric management.

Additional context
Backwards Compatibility: This change is backward compatible because the default prefix is an empty string. This ensures that, by default, the existing metric names will not change, effectively appending an empty string to the current metric name.
Test Coverage: I have also added a CacheMetricsBehaviorTest class to verify this new functionality.
Customization: This feature enhances Micrometer's flexibility by allowing users to define custom metric name prefixes for cache metrics which can be particularly useful in enterprise or specialized settings.

fartzy pushed a commit to fartzy/micrometer that referenced this issue Aug 26, 2023
fartzy pushed a commit to fartzy/micrometer that referenced this issue Aug 26, 2023
fartzy pushed a commit to fartzy/micrometer that referenced this issue Aug 26, 2023
fartzy pushed a commit to fartzy/micrometer that referenced this issue Aug 26, 2023
@jonatan-ivanov
Copy link
Member

Hey @fartzy,
Have you considered using a MeterFilter and changing the names of the meters you want to?

@jonatan-ivanov jonatan-ivanov added waiting for feedback We need additional information before we can continue and removed waiting-for-triage labels Dec 14, 2023
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@shakuzen
Copy link
Member

I think this is similar to the issue we had with ExecutorServiceMetrics (#1919) and Prometheus users where multiple instances of the binder (CacheMeterBinder in this case) will exist but there may be some extra tags that differ. If there's no way to change the name, they'll run into #877. Outside of the Prometheus registry, that shouldn't be an issue, since CacheMeterBinder takes a cacheName that is supposed to uniquely identify the cache, allowing multiple caches to be monitored with the same meter names.

That would still leave the strict naming convention concern. I'm not familiar with this in Artemis so I can't speak to it specifically. I understand the desire for say Artemis metrics to come under an artemis. prefix, but in the case of these generic metrics for things like caches or http, there is power that will be lost in them diverging from the common name chosen. With the common name, dashboards and queries can be used for any implementation because the meter names are known up front, and the cacheName tag can be used to identify and filter by specific caches. If the same metrics were renamed with an artemis prefix, then dashboards and metrics queries need to be written specifically for artemis separately from the generic cache metrics.

On the suggestion for MeterFilter, end users can configure a MeterFilter, but it would be odd and unexpected I think for a library (like Artemis) to register a MeterFilter. At least I don't think I anticipate such usage or know of it anywhere else currently.

So I think that leaves us with: Artemis (or other libraries in their position) should copy CacheMeterBinder code to change the meter names used, or we should allow a prefix to be specified as suggested. If we resolved #877, that would take away significant reason to go with the prefix option. In the absence of resolution on #877, it feels more necessary we allow prefixing.

Copy link

github-actions bot commented Jan 2, 2024

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@fartzy
Copy link
Author

fartzy commented Jan 9, 2024

I am going to try to checkout MeterFilter and see if it can be used. I'm not sure just by reading the code if it will be work properly for what is being done with Artemis though. Is there any more thought given to what @shakuzen said though?

Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
@jonatan-ivanov jonatan-ivanov removed waiting for feedback We need additional information before we can continue feedback-reminder labels Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants