Metrics not appearing in prometheus endpoint
See original GitHub issueWe have a funny behavior that started appearing with RC8, if we go back to RC7 it disappears: The common Spring metrics do not appear in the Prometheus endpoint like jvm_memory_committed_bytes
, system_cpu_count
, etc.
Even more funny, the behavior is only happening in one of two of our projects, even though most dependencies are the same - we use Spring Boot 1.5.10, Spring Cloud Edgware.SR2, Micrometer 1.0.2.
The problem seems to lie in the order the auto configurations are applied:
In the project that has no issues, io.micrometer.spring.autoconfigure.MetricsAutoConfiguration#meterRegistryPostProcessor
is executed first, then io.micrometer.spring.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration#prometheusMeterRegistry
. Therefore the postprocessor is instantiated first and finally registers all Spring metrics.
In the project that is not working, the order is swapped and the postprocessor does not get invoked with the PrometheusMeterRegistry
bean.
This is funny, as PrometheusMetricsExportAutoConfiguration
is annotated with @AutoConfigureAfter({MetricsAutoConfiguration.class})
.
The documentation on @AutoConfigureAfter
is non existent but if I understand the kind of only resource in the internet correctly (https://stackoverflow.com/questions/42284478/autoconfigureafter-not-working-as-desired) it is just used to create the dependency graph but does not necessarily influence the order of creation? In that case, adding an (unused) parameter with type MeterRegistryPostProcessor
to the factory method io.micrometer.spring.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration#prometheusMeterRegistry
might not be too elegant but already solve the issue?
Thanks Marco
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:13 (5 by maintainers)
Top GitHub Comments
We had similar issue on our side. In our case we have
BeanPostProcessor
, which replacesRestTemplate
of oauth2RemoteTokenServices
(in order to enable timeouts and zipkin tracing), so all JVM metrics were missing.In our case we used following hack similar to one from @marcoschulte (as MeterRegistryPostProcessor is package private now)
We hope this would go away in our case with support of server-oauth2 in next spring security, as this hack is quite fragile…
Dependency graph looked like this:
OurBeanPostProcessor
->restTemplateBuilder
->metricsRestTemplateCustomizer
->prometheusMeterRegistry
which causedprometheusMeterRegistry
to be created too early when most ofMeterBinder
s are not yet there…Btw. for anyone else having this issue, this fixes it for now: