Repository navigation
Commit e319d3b
authored
fix(config): keep metric name case in metric-specific properties (#2588)
## Problem
Since 1.5.0, metric-specific properties are ignored when the metric name
has an uppercase letter. With
```properties
io.prometheus.metrics.myLatency.histogram_classic_upper_bounds=.005, .01, .015
```
a histogram named `myLatency` keeps the default buckets.
`normalizePropertyKey()`, added in #1828 to accept camelCase property
names, lowercases the whole key including the metric name. The settings
are stored under `my_latency`, while `StatefulMetric` looks them up as
`myLatency` and gets `null`. There is no "Unknown property" error
because the key was consumed. In 1.4.3 the same config (with
`histogramClassicUpperBounds`) applies to `myLatency`; I ran both
versions to check. An automated review comment on #1828 pointed this
out, but metric names are still lowercased on main.
## Fix
In `io.prometheus.metrics.<metric>.<property>` keys only the property
name is normalized, so
`io.prometheus.metrics.myLatency.histogramNativeOnly` becomes
`io.prometheus.metrics.myLatency.histogram_native_only`. Default metric
keys and exporter keys are normalized as before, and environment
variables are not affected.
A key written with uppercase letters for a lowercase metric, like
`io.prometheus.metrics.My_metric.histogram_native_only` for `my_metric`,
no longer applies. That matches 1.4.x.
## How tested
New
`PrometheusPropertiesLoaderTest.metricSpecificPropertiesShouldKeepMetricNameCase`
fails on main with a `NullPointerException` because
`getMetricProperties("myLatency")` returns `null`, and passes with this
change. I also added a case to
`normalizePropertyKeyShouldConvertCamelCaseToSnakeCase`.
`prometheus-metrics-config` (62 tests, coverage check) and
`prometheus-metrics-core` (178 tests) pass on JDK 25. google-java-format
1.37.0 and checkstyle are clean on the changed files. I did not run
`mise run lint` or the exporter modules.
@zeitlinger this changes the key normalization from #1828.
Signed-off-by: Tanishq Choudhary <tanishqchoudhary007@gmail.com>1 parent b347b8d commit e319d3b
2 files changed
Lines changed: 28 additions & 0 deletions
File tree
- prometheus-metrics-config/src
- main/java/io/prometheus/metrics/config
- test/java/io/prometheus/metrics/config
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
216 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
| |||
160 | 176 | | |
161 | 177 | | |
162 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
163 | 183 | | |
164 | 184 | | |
165 | 185 | | |
| |||
0 commit comments