Issue when using @Timed annotation with prometheus-metrics-instrumentation-dropwizard
@Timed annotation, which can be annotated on the methods generates dropwizard metrics with .total as a suffix.
This is not compatible with prometheus-metrics-instrumentation-dropwizard to export dropwizard metrics.
Since the io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports class has a method fromSnapshotAndCount which sanitizes the metric name withPrometheusNaming.sanitizeMetricName(dropwizardName).
As a result it causes duplicate metric name exception when prometheus endpoint is invoked.
Original reference here: https://github.com/dropwizard/dropwizard/issues/10030 #
This will be fixed in https://github.com/prometheus/OpenMetrics/issues/286 - which basically says that metric names are not changed or checked in client sdks
Great thanks. We are doing this as a temporary fix for DW 4.x
prometheusRegistry.register(new DropwizardExports(environment.metrics(),
(name, metric) -> !(metric instanceof Timer) || !name.matches(".*[._]total.*")));
environment.admin()
.addServlet("prometheusMetrics", new PrometheusMetricsServlet(prometheusRegistry))
.addMapping("/prometheusMetrics");