Commit 5a5106c
authored
feat: move suffix handling to scrape time (#1955)
## Summary
Moves metric name suffix handling (`_total`, `_info`, unit suffixes)
from creation time to scrape time. Closes #1941, part of #1942.
- **OM1**: smart-appends suffixes (skips if already present)
- **Registry**: detects cross-format name collisions at registration
time
### Key changes
- Remove all reserved metric name suffixes from `PrometheusNaming`
- Store original user-provided name separately from exposition base
name in `MetricMetadata` (`originalName` vs `expositionBaseName`)
- Smart-append logic in OM1/protobuf writers for `_total` and `_info`
- Two-layer collision detection in `PrometheusRegistry`
(base name + exposition names)
### Key table
| User provides | OM1 |
|---|---|
| `Counter("events")` | `events_total` |
| `Counter("events_total")` | `events_total` |
| `Counter("req").unit(BYTES)` | `req_bytes_total` |
| `Counter("req_bytes").unit(BYTES)` | `req_bytes_total` |
| `Gauge("events_total")` | `events_total` |
### PR stack
1. **This PR** — core model + OM1/protobuf writers
2. OTel `preserve_names` (stacked on this)
3. OM2 writer no-suffix (stacked on this)
## Test plan
- [x] `mise run compile` passes
- [x] New tests for `MetricMetadata` 5-arg constructor and
field accessors
- [x] New `PrometheusRegistryTest` covers collision detection
- [x] Existing snapshot tests updated
Part of #1912.
---------
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>1 parent 165c921 commit 5a5106c
File tree
17 files changed
+657
-192
lines changed- prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics
- prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/internal
- prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats
- prometheus-metrics-model/src
- main/java/io/prometheus/metrics/model
- registry
- snapshots
- test/java/io/prometheus/metrics/model
- registry
- snapshots
17 files changed
+657
-192
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | | - | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
50 | 68 | | |
51 | 69 | | |
52 | 70 | | |
| |||
68 | 86 | | |
69 | 87 | | |
70 | 88 | | |
| 89 | + | |
71 | 90 | | |
72 | 91 | | |
73 | 92 | | |
| |||
82 | 101 | | |
83 | 102 | | |
84 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
85 | 123 | | |
86 | 124 | | |
87 | 125 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
300 | 305 | | |
301 | 306 | | |
302 | 307 | | |
| |||
Lines changed: 46 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
145 | 148 | | |
146 | | - | |
147 | | - | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | | - | |
| 152 | + | |
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
| |||
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
277 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
278 | 282 | | |
279 | | - | |
280 | | - | |
| 283 | + | |
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
| |||
363 | 366 | | |
364 | 367 | | |
365 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
366 | 375 | | |
367 | | - | |
368 | | - | |
| 376 | + | |
369 | 377 | | |
370 | 378 | | |
371 | 379 | | |
| |||
436 | 444 | | |
437 | 445 | | |
438 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
439 | 461 | | |
440 | 462 | | |
441 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
442 | 469 | | |
443 | | - | |
| 470 | + | |
444 | 471 | | |
445 | 472 | | |
446 | 473 | | |
447 | 474 | | |
448 | 475 | | |
449 | | - | |
| 476 | + | |
450 | 477 | | |
451 | 478 | | |
452 | 479 | | |
453 | 480 | | |
454 | 481 | | |
455 | 482 | | |
456 | | - | |
| 483 | + | |
457 | 484 | | |
458 | 485 | | |
459 | 486 | | |
460 | 487 | | |
461 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
462 | 496 | | |
Lines changed: 51 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
160 | 165 | | |
161 | 166 | | |
162 | 167 | | |
163 | | - | |
| 168 | + | |
164 | 169 | | |
165 | 170 | | |
166 | | - | |
167 | | - | |
| 171 | + | |
168 | 172 | | |
169 | 173 | | |
170 | 174 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
178 | | - | |
| 182 | + | |
| 183 | + | |
179 | 184 | | |
180 | | - | |
181 | | - | |
| 185 | + | |
182 | 186 | | |
183 | 187 | | |
184 | 188 | | |
| |||
321 | 325 | | |
322 | 326 | | |
323 | 327 | | |
324 | | - | |
| 328 | + | |
| 329 | + | |
325 | 330 | | |
326 | | - | |
327 | | - | |
| 331 | + | |
328 | 332 | | |
329 | 333 | | |
330 | 334 | | |
| |||
433 | 437 | | |
434 | 438 | | |
435 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
436 | 478 | | |
437 | 479 | | |
438 | 480 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
0 commit comments