RegistryFactory to register Metric changes from Helidon 3 to Helidon 4

104 views Asked by At

In Helidon Nima (version : 4.0.0-RC1), I see that RegistryFactory is removed from io.helidon.metrics and pushed to io.helidon.microprofile.metrics and made it private for outside modules. I see that only RegistryFactoryManager is public and has instance method onCreate() but that returns void. can someone please help with the alternative for the code snippet below. RegistryFactory.getInstance().getRegistry(type);

I see that MetricRegistry support from org.eclipse.microprofile.* is completely removed and added io.helidon.metrics.api.*, is there any reason for this ?

1

There are 1 answers

0
Tim Quinn On

There is a reason.

In earlier releases of Helidon the Helidon SE metrics API relied on the MicroProfile Metrics API and other MP metrics elements. In 4.0 we have introduced a neutral Helidon metrics API that does not depend on the MP metrics API. You might see some similarities to and inspiration from the Micrometer API but the APIs are not identical.

Here's a doc page on SE metrics in 4.0. https://helidon.io/docs/latest/index.html#/se/metrics/metrics that should help.

In answer to your specific question, in 4.0 "registry types" are now called "scopes" (that is consistent with the latest MP metrics spec) and in SE there is (typically) one meter registry, not one for each different scope. The scope is an attribute of each meter you register.

Here's a brief example of how to use the new API to register a new meter or retrieve a previously-registered one:

MeterRegistry meterRegistry = Metrics.globalRegistry();
Counter myCounter = meterRegistry.getOrCreate(Counter.builder("myCounter"));

If you wanted to register or look up the counter in a particular scope, you'd specify that on the builder:

MeterRegistry meterRegistry = Metrics.globalRegistry();
Counter myCounter = meterRegistry.getOrCreate(Counter.builder("myCounter")
                                        .scope("MyCustomScope"));

Helidon continues to support the built-in scopes application, base, and vendor with the default, if you don't specify it, being application.

Rather than continue on at length here, check out the doc and the JavaDoc on the relevant types.