Quarkus Configure Metrics for SmallRye Fault Tolerance

400 Views Asked by At

My Quarkus application is using Micrometer and Smallrye Fault Tolarance extensions, and I appreciate the fact that using the @CircuitBreaker annotation automatically adds metrics. However, the format and labels are kind of ugly and would make maintaining and operational dashboards and monitoring a pain as they seem to be autogenerated based on the package and class. Example: refactoring or moving them would basically break Prometheus query.

Is it possible to configure this with Quarkus?

This is what the metrics look like out of the box

ft_some_really_long_package_name_ClassName_methodName_circuitbreaker_halfOpen_total{} 0

What I would like to have is something like this

circuitbreaker_halfOpen_total{package="com.somepackage", class="SomeClass", method="SomeMethod"} 0

1

There are 1 best solutions below

0
On

hmmm. You should be able to do this with a MeterFilter, I think, but getting the string munging right (to split package/classname/methodName)

https://quarkus.io/guides/micrometer#using-meterfilter-to-configure-metrics

@Produces
@Singleton
public MeterFilter renameFaultToleranceMetrics() {
    return new MeterFilter() {
        @Override
        public Meter.Id map(Meter.Id id) {
            if (id.getName().endsWith("circuitbreaker_halfOpen_total")) {
                // Do things here to make a new list of tags based on string munging
              List<Tag> tags = ...
              return id.withName("circuitbreaker_halfOpen_total").replaceTags(tags);
            }
            return id;
        }
    };
}

An example is here: https://github.com/quarkusio/quarkus/blob/main/integration-tests/micrometer-mp-metrics/src/main/java/io/quarkus/it/micrometer/mpmetrics/RenameMeterFilterProducer.java