-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Issue observed with Spring cache + micrometer + caffeine #5793
Comments
Cross posted from: https://micrometer-metrics.slack.com/archives/C662HUJC9/p1734628357662449
There is a trace, I think what you meant is there is no span for cache miss. If so, this is not a Micrometer question I think but probably a Spring Framework issue to instrument Also, please look into my answer on Slack, let me copy it to here:
@GetMapping("/getAnimal")
public String getAnimal(@RequestParam String name) {
observationRegistry.getCurrent().keyValue("cached", "true");
return personService.getAnimal(name);
}
@Cacheable("AnimalCache")
public String getAnimal(String name) {
observationRegistry.getCurrent().keyValue("cached", "false");
return this.restClient.post()
...;
} You can also create a “getAnimal” observation and do the same on it instead of using the http observation.
Where is this metric coming from, are you using |
Thank you for the detailed answer @jonatan-ivanov I created an enhancement request and crossing my fingers. spring-projects/spring-framework#34219 Regarding the metrics, could you please help elaborate on CaffeineCacheMetrics? I could come up with four implementations so far. Could you please let me know if there are any official ways to configure Caffeine with micrometer metrics? Try 1: Found
Try 2: Found https://docs.micrometer.io/micrometer/reference/reference/cache.html
Try 4:
|
You need to call |
If you're using Spring Boot, you should refer to their documentation. Namely, this section for metrics and this section for Spring Boot's auto-configuration of Caffeine.
You creating your own |
Describe the bug
Hello team,
I would like to reach out to report a bug with springboot, spring cache, micrometer and caffeine.
To Reproduce
Here is the code:
(mock an expensive downstream service)
As you can see, this is a straightforward piece of code, where there is the use of cacheable to cache an expensive http call.
The code is working, because the second call would get the data directly from the cache (checked there is no more call on the downstream service, the response comes very fast)
Expected behavior
Expected behavior 1, for traces:
For the traces, while it is technically correct that there is no trace for the network call, since it did not happen.
Can this be enhanced by showing a trace that it went to the cache?
Expected behavior 2, for metrics:
Since there is a call which "cache miss" and another call which "cache hit", I would expect to see some counter incremented.
However, the line stays flat. May I ask what the value stays at 0, despite having cache miss and cache hit?
Additional context
[Add any other context about the problem here, e.g. related issues.]
https://micrometer-metrics.slack.com/archives/C662HUJC9/p1734628357662449
Environment
The text was updated successfully, but these errors were encountered: