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

Cannot use MicronautCaffeineCacheMetrics.monitor if there is caches section in application.yml #309

Closed
markjfisher opened this issue Nov 4, 2021 · 5 comments · Fixed by #320

Comments

@markjfisher
Copy link

Expected Behavior

Upgrading an existing application from 2.x to 3.x should not fail when using both MicronautCaffeineCacheMetrics.monitor and a caches section (with cacheable functions in the application).

Actual Behaviour

Application fails to startup with error message:

Caused by: java.lang.IllegalArgumentException: Collector already registered that provides name: cache_eviction_weight
	at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:54)
	at io.prometheus.client.Collector.register(Collector.java:175)
	at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$16(PrometheusMeterRegistry.java:479)

Steps To Reproduce

Download the example application provided, and run it.

Removing the "caches" entries from application.yml will stop it failing, but then doesn't provide statistics on the prometheus endpoint.

Environment Information

JDK 11, Linux various.

Example Application

https://github.com/markjfisher/mn-cache-graphql-monitor

Version

3.1.3

@markjfisher
Copy link
Author

I raised this in gitter, but can't find a way of linking, but the search is from:"mark fisher" sent:[2021-11-04 TO 2021-11-05]

@jameskleeh
Copy link
Contributor

Try changing OtherService to the following:

        CaffeineCacheMetrics.monitor(
            meterRegistry,
            cache,
            "graphQLDocumentCache"
        )

Note you have to use the com.github.benmanes.caffeine.cache imports

@markjfisher
Copy link
Author

Excellent, I can now see the values in prometheus, and no errors.

cache_evictions_total{cache="graphQLDocumentCache",} 0.0
cache_evictions_total{cache="delivery-service",} 0.0

@jameskleeh
Copy link
Contributor

@graemerocher Do you understand the need for https://github.com/micronaut-projects/micronaut-micrometer/blob/master/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/cache/MicronautCaffeineCacheMetrics.java ? We relocate caffeine in core but I don't think any of the caches we create are setup for metrics

@graemerocher
Copy link
Contributor

Should be deprecated and removed. Also the JAR jared version of caffeine should be removed IMO

@jameskleeh jameskleeh transferred this issue from micronaut-projects/micronaut-core Nov 5, 2021
@jameskleeh jameskleeh linked a pull request Nov 20, 2021 that will close this issue
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 a pull request may close this issue.

3 participants