From 793d16bbee8d0a1fe5e1ff886a23a39aa2dececd Mon Sep 17 00:00:00 2001 From: Sharang Gupta Date: Wed, 28 Oct 2026 18:34:33 +0000 Subject: [PATCH] fix(dropwizard5): use locale-independent placeholder keys in GraphiteNamePattern extractParameters formatted the "${n}" keys with the default locale, so under a locale such as ar-EG the keys used Arabic-Indic digits and CustomLabelMapper left "${0}" unreplaced in mapped names and labels. Build the keys with string concatenation instead. Signed-off-by: Sharang Gupta --- .../dropwizard5/labels/GraphiteNamePattern.java | 2 +- .../labels/GraphiteNamePatternTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePattern.java b/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePattern.java index 7ec0445d07..d2bc415234 100644 --- a/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePattern.java +++ b/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePattern.java @@ -71,7 +71,7 @@ Map extractParameters(final String metricName) { final Map params = new HashMap(); if (matcher.find()) { for (int i = 1; i <= matcher.groupCount(); i++) { - params.put(String.format("${%d}", i - 1), matcher.group(i)); + params.put("${" + (i - 1) + "}", matcher.group(i)); } } diff --git a/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePatternTest.java b/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePatternTest.java index aa3e20e6b0..75cdca092f 100644 --- a/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePatternTest.java +++ b/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePatternTest.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -132,6 +133,19 @@ void extractParameters() { .isEqualTo(expected); } + @Test + void extractParameters_WHEN_DefaultLocaleHasNonAsciiDigits_THEN_ShouldUseAsciiKeys() { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.forLanguageTag("ar-EG")); + try { + GraphiteNamePattern pattern = new GraphiteNamePattern("org.test.controller.*.status.*"); + Assertions.assertThat(pattern.extractParameters("org.test.controller.gather.status.400")) + .containsOnlyKeys("${0}", "${1}"); + } finally { + Locale.setDefault(defaultLocale); + } + } + @Test void extractParameters_WHEN_emptyStringInDottedMetricsName_THEN_ShouldReturnEmptyString() { GraphiteNamePattern pattern;