You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue when using @Timed annotation with prometheus-metrics-instrumentation-dropwizard #1321
@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.
In the current client_java version the .total suffix is still dropped by AbstractDropwizardExports because it calls sanitizeMetricName, which removes the .total suffix.
My understanding was that this behavior was supposed to change so that Dropwizard metrics ending in .total are handled in a way that avoids name collisions. Is that correct, or is the .total suffix still intentionally dropped?
The issue is that when a Dropwizard metric like <servicepath>.uploadDocumentFile.total and a metric without the suffix both get sanitized to the same name (<servicepath>_uploadDocumentFile), the merge of snapshots later fails due to duplicate names with identical (empty) label sets.
This causes a failure in TextFormatUtil.mergeDuplicates, because it tries to combine metrics with the same name and identical (empty) labels, resulting in a DuplicateLabelsException.
So my question is: should .total still be stripped at this stage, or should the exporter avoid dropping it to prevent duplicate metric name collisions?
@YellowFlora You're right that .total is currently stripped, and that's working as designed per the OpenMetrics 1.0 spec. This will change as part of #1912 (OpenMetrics 2.0 support), which will stop treating _total/.total as reserved suffixes that get stripped during sanitization.
rather than filtering them out (we use async requests so the .total is more useful than the raw one), we map ".total" -> ".async" like so:
.customLabelMapper(
object:CustomLabelMapper(
listOf(MapperConfig(
// This config won't actually match what we want because the * glob stops at '.'s// but we do need a non-empty list of MapperConfigs to use a CustomLabelMapper"*.total", $$"${0}.total", mapOf())),
) {
overridefungetName(dropwizardName:String?): String {
// this one actually remaps **.total -> **.asyncreturnsuper.getName(dropwizardName?.replace("\\.total$".toRegex(), ".async"))
}
},
)
not sure if there's a less awkward way to set it up with the current code?
Activity
zeitlinger commentedon Apr 8, 2025
This will be fixed in prometheus/OpenMetrics#286 - which basically says that metric names are not changed or checked in client sdks
kpur-sbab commentedon Apr 10, 2025
Great thanks. We are doing this as a temporary fix for DW 4.x
YellowFlora commentedon Feb 18, 2026
Hello @zeitlinger,
In the current
client_javaversion the.totalsuffix is still dropped byAbstractDropwizardExportsbecause it callssanitizeMetricName, which removes the.totalsuffix.My understanding was that this behavior was supposed to change so that Dropwizard metrics ending in
.totalare handled in a way that avoids name collisions. Is that correct, or is the.totalsuffix still intentionally dropped?The issue is that when a Dropwizard metric like
<servicepath>.uploadDocumentFile.totaland a metric without the suffix both get sanitized to the same name (<servicepath>_uploadDocumentFile), the merge of snapshots later fails due to duplicate names with identical (empty) label sets.This causes a failure in
TextFormatUtil.mergeDuplicates, because it tries to combine metrics with the same name and identical (empty) labels, resulting in aDuplicateLabelsException.Example test illustrating the failure:
So my question is: should
.totalstill be stripped at this stage, or should the exporter avoid dropping it to prevent duplicate metric name collisions?zeitlinger commentedon Mar 6, 2026
@YellowFlora You're right that
.totalis currently stripped, and that's working as designed per the OpenMetrics 1.0 spec. This will change as part of #1912 (OpenMetrics 2.0 support), which will stop treating_total/.totalas reserved suffixes that get stripped during sanitization.josephlbarnett commentedon Mar 27, 2026
rather than filtering them out (we use async requests so the .total is more useful than the raw one), we map ".total" -> ".async" like so:
.customLabelMapper( object : CustomLabelMapper( listOf(MapperConfig( // This config won't actually match what we want because the * glob stops at '.'s // but we do need a non-empty list of MapperConfigs to use a CustomLabelMapper "*.total", $$"${0}.total", mapOf())), ) { override fun getName(dropwizardName: String?): String { // this one actually remaps **.total -> **.async return super.getName(dropwizardName?.replace("\\.total$".toRegex(), ".async")) } }, )not sure if there's a less awkward way to set it up with the current code?
WIP: prometheus metrics scraping
WIP: prometheus metrics scraping
josephlbarnett commentedon Jun 11, 2026
also fwiw, it seemed like a workaround was not needed in 1.6.1, but is needed again in 1.7.0, i think per #2100 and/or #2124