client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Caffeine: allow specifying custom metric labels

Open aaabramov opened this issue 5 years ago • 1 comments

Allow library users to specify custom labels for CacheMetricsCollector. Please upvote this issue if you would like this feature to be merged.


Let's say we are having k8s cluster with 10 different apps. Each of it uses caffeine as a cache. But single prometheus scrapper.

Currently, the only way to distinguish cache metrics provided by this library between apps is to modify somehow cacheName parameter (either we can prefix it with domain, e.g. users_the_cache_name, dashboards_the_cache_name, etc. or with postfix). This makes creating Grafana dashboards pretty difficult as we have to rely on regexes of cache label.

In order to create cache dashboard for users service we have to write something like

sum(rate(caffeine_cache_miss_total{cache~="users_.*"}[5m])) by (cache)

I think 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);
sum(rate(caffeine_cache_miss_total{app="users-service"}[5m])) by (cache)

NOTE: Implemented in scope of https://github.com/prometheus/client_java/pull/602 but has some drawbacks (see PR comments).

aaabramov avatar Nov 17 '20 14:11 aaabramov

See #901 and #905 - same problem, other solution.

zorba128 avatar Dec 10 '23 20:12 zorba128