I'm using Spring Boot 2.7 with Micrometer 1.11.2. My application spans worker threads, which are responsible to handle background jobs. Each worker thread is using Spring beans (i.e. Repositories) and also tries to register meter.
meterRegistry.get(metricName)
.tags(tags)
.timer();
In case two concurrent threads try to register the same meter (same name and same labels) the application hangs because of a deadlock.
This behaviour is reported and unfortunatelly open (see https://github.com/micrometer-metrics/micrometer/issues/1551).
First approach was to register all my custom meters / metrics before worker threads are started. But since the threads are also using spring repositories (what leads to registering meters for spring_data_repository_* metrics) it doesn't work.
Does anybody know a workaround with using Micrometer?
Another idea would be using Prometheus client directly, but this doesn't look like the Spring Boot way.
Best regards Alex
Spring Boot 2.7 reached its end of it's OSS support timeframe, please upgrade to 3.x. The matching version of Micrometer to Boot 2.7 is Micrometer 1.9. Micrometer 1.11 should work too but 1.9 was the tested version with Boot 2.7.
Please check the docs how to register
Meters properly, please either useTimer.builder(...)orregisty.timer(...): https://docs.micrometer.io/micrometer/reference/concepts/timers.htmlI think this should work, and the issue that #1551 demonstrates is different. Otherwise a lot of users would have the same issue just by using an mvc controller that processes concurrent requests. I might be mistaken and this is the same issue you are hitting, do you have a reproducer we can take a look at? (You can add a comment with the reproducer to the issue.)