-
Notifications
You must be signed in to change notification settings - Fork 805
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
Custom labels for caffeine cache #602
Custom labels for caffeine cache #602
Conversation
List<String> labelNames = new ArrayList<String>(customLabels.size() + 1) {{ | ||
add("cache"); | ||
addAll(customLabels); | ||
}}; |
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.
Should we initialize this this List each time? Maybe simply initialize it once as instance field?
f822e96
to
9a23f2b
Compare
5e0662f
to
6628056
Compare
6628056
to
fee3fb4
Compare
… is!) useful in microservice environment where service caches are being used in different domains. Using custom labels, users will be able to distinguish different cache metrics without [pre/post]fixing `cache` (`cacheName`) parameter. Also upgrades caffeine cache to v2.8.6 This feature keeps backwards binary & source compatibility. Signed-off-by: Andrii Abramov <[email protected]>
fee3fb4
to
be04709
Compare
for (Map.Entry<String, String> entry : customLabels.entrySet()) { | ||
add(entry.getValue()); | ||
} | ||
}}; |
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 may be a good idea to store label inside children
value. This would require adding custom class as a value but since it is internal we can implement this without breaking changes.
Can you expand on what you mean by different domains here? |
Sure. Currently, the only way to distinguish cache metrics provided by this library between apps is to modify somehow In order to create cache dashboard for
That's why I decided it would be easier for users to specify their own labels and create Grafana dashboard like this: Map<String, String> labels = new HashMap<String, String>() {{
put("app", "users-service");
}};
CacheMetricsCollector coll = new CacheMetricsCollector(labels);
This PR is more like a proposal, I am totally open to discussion 👨💻 |
What happens if there's different libraries in the application that are using different label names with this? We can't make any assumptions in that regard. |
Is it an issue in this case? Wouldn't we expose different metrics in this case? I am not so strong enough in prometheus but I would expect to have different metric rows from prometheus, e.g.:
Or am I missing something? Anyway, we are simply allowing users to take control of what is exposed. We are not making any decisions for them. |
Yes, you'd break downstream PromQL and depending on implementation could also produce invalid exposition (what happens if two libraries clash on labels?). If you're varying instrumentation labels, then the metric name must also change. |
Thanks, now I see. But this could happen without this library? We are not introducing some sort of "failure injection". It's user's responsibility to keep an eye on such things. We are just providing an instrument (facade, if you want) to make life easier. |
My point is that the user can't, as they don't have full control of all their libraries. If you have code like this, you have to presume that other unknown parts of your application are using it in arbitrary ways, and then considering if it's possible for you to write correct code given that. For this proposal as it stands it isn't. |
I see your point. What is your proposal to solve the issue? Playing around with Well, it is still possible to inherit |
Given that there has only been one request for this thus far, I think it would be best to handle it on your side for now. Any form of wrapper that adjusts the metric name and labels should do the trick. |
Sadly, but decision is up to you. I will create issue referencing this PR to get community feedback. |
@brian-brazil closing this for now, described proposal in #603 |
Adds an option to specify custom labels for metrics. This may be (and is!) useful in microservice environment where service caches are being used in different domains. Using custom labels, users will be able to distinguish different cache metrics without [pre/post]fixing
cache
(cacheName
) parameter.Also upgrades caffeine cache to v2.8.6
This feature keeps backwards binary & source compatibility.