Commit 2d0f508
authored
fix: restore reserved suffix stripping in
Fixes #2087.
Supersedes #2094 with the same fix on a clean, signed-off commit so the
DCO
check can pass.
`sanitizeMetricName()` was simplified in 1.6.0 to return its input
unchanged
because any non-empty UTF-8 string is now a valid metric name. That
silently
broke downstream tools — notably the JMX Exporter and the simpleclient
bridge —
that call `sanitizeMetricName()` to normalize external names before
passing them
to snapshot builders.
The missing stripping means a JMX attribute that produces
`kafka_consumer_request_total` as a raw name is no longer sanitized to
`kafka_consumer_request`. With `inferCounterTypeFromName: true` this
triggers
unintended counter-type inference; with it `false` the metric is stored
under the
wrong name, breaking exact-name registry lookups.
## Changes
- Restore `RESERVED_METRIC_NAME_SUFFIXES` and the iterative
suffix-stripping loop
in `PrometheusNaming.sanitizeMetricName()`.
- Keep the exact-match case, for example `"_total"` -> `"total"`, in a
dedicated
pre-pass before the stripping loop.
- Update `PrometheusNamingTest` and `MetricMetadataTest` expectations.
- Add regression coverage for the JMX Exporter scenario and dot-variant
corner
case, for example `.total`.
```java
// Before fix: suffix preserved -> metric stored as "kafka_consumer_request_total"
PrometheusNaming.sanitizeMetricName("kafka_consumer_request_total");
// After fix: suffix stripped -> metric stored as "kafka_consumer_request"
PrometheusNaming.sanitizeMetricName("kafka_consumer_request_total");
```
`Counter.builder().name("events_total")` is unaffected because the
builder API
does not go through `sanitizeMetricName()`.
## Validation
- `mise run build`
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>PrometheusNaming.sanitizeMetricName() (#2124)1 parent b62b5d0 commit 2d0f508
3 files changed
Lines changed: 152 additions & 17 deletions
File tree
- prometheus-metrics-model/src
- main/java/io/prometheus/metrics/model/snapshots
- test/java/io/prometheus/metrics/model/snapshots
prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/PrometheusNaming.java
Lines changed: 82 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
20 | 31 | | |
21 | 32 | | |
22 | 33 | | |
| |||
35 | 46 | | |
36 | 47 | | |
37 | 48 | | |
38 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
39 | 52 | | |
40 | 53 | | |
41 | 54 | | |
| |||
153 | 166 | | |
154 | 167 | | |
155 | 168 | | |
156 | | - | |
157 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
158 | 185 | | |
159 | 186 | | |
160 | 187 | | |
161 | 188 | | |
162 | 189 | | |
163 | 190 | | |
164 | 191 | | |
165 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
166 | 213 | | |
167 | 214 | | |
168 | 215 | | |
| |||
179 | 226 | | |
180 | 227 | | |
181 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
182 | 260 | | |
183 | 261 | | |
184 | 262 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
44 | 46 | | |
45 | | - | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
50 | 53 | | |
51 | | - | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| 59 | + | |
56 | 60 | | |
57 | | - | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
Lines changed: 62 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | | - | |
32 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
33 | 62 | | |
34 | 63 | | |
35 | 64 | | |
36 | 65 | | |
37 | 66 | | |
38 | 67 | | |
| 68 | + | |
39 | 69 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
43 | 73 | | |
44 | 74 | | |
45 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
46 | 99 | | |
47 | 100 | | |
48 | 101 | | |
| |||
0 commit comments