Originally reported in https://github.com/micrometer-metrics/micrometer/issues/546.

@crmky reports:

My application uses micrometer-core 1.03 with micrometer-spring-legacy. When it starts, there are three MeterRegistry beans get created:

  • A PrometheusMeterRegistry bean comes with micrometer-registry-prometheus.
  • A customized implementation based on DropwizardMeterRegistry.
  • A CompositeMeterRegistry bean created by micrometer-spring-legacy. And it contains the previous two registries.

The problem is all of those beans are added into globalRegistry in Metrics class by MeterRegistryPostProcessor. The hierarchy becomes:

Global Registry
  PrometheusMeterRegistry
  DropwizardMeterRegistry
  CompositeMeterRegistry
    PrometheusMeterRegistry
    DropwizardMeterRegistry

If I defined a counter in global registry, the counter value in PrometheusMeterRegistry and DropwizardMeterRegistry will be updated twice.

Comment From: jkschneider

I think we'll fix this more generally in CompositeCounter, etc instead. Should be able to do so without much performance impact.

Comment From: wThomas84

Hello,

for me it seems there is still a bug, regarding auto configuration of the MeterRegistry and the static Metrics' globalRegistry. Or maybe I do not know/see something where I would be happy to get corrected. Having a DatadogMeterRegistry and a JmxMeterRegistry auto configured I see that also a CompositeMeterRegistry is created that contains both, the DatadogMeterRegistry and the JmxMeterRegistry. Each time a MeterRegistry is configured it gets processed by the MeterRegistryConfigurer which puts the registry into Metrics.globalRegistry. This effectively results in the object tree the OP described:


Metrics.globalRegistry@01          // with 'new' initailized CompositeMeterRegistry
          |--  DatadogMeterRegistry@02
          |-- JmxMeterRegistry@03
          |-- CompositeMeterRegistry@04     // By spring auto config created CompositeMeterRegistry
                               |--  DatadogMeterRegistry@02
                               |-- JmxMeterRegistry@03

This doesn't look right; I am asking myself if this is intended and if so, why? Is there maybe some documentation, that I haven't found yet, clarifying this?

I would rather expect the CompositeMeterRegistry@04 to be the globalRegistry with its children.

How is it enforced that a measurement of a meter is only done once for the multiple occurring MeterRegistries?

Thanks and best regards Thomas

Comment From: wilkinsona

As indicated above in the comment by @jkschneider, this should be taken care of in Micrometer. If you believe that's not the case, please open a Micrometer issue with a small sample that illustrates the problem.