Skip to content

Caffeine: allow specifying custom metric labels #603

Open
@aaabramov

Description

@aaabramov

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 #602 but has some drawbacks (see PR comments).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions