Skip to content

Commit bc16164

Browse files
committed
fix(cmetrics): prevent appending .0 to scientific notation in bucket_value_to_string
`bucket_value_to_string` used %g to format histogram bucket boundaries, which switches to scientific notation for values >= 1e6. The subsequent check for a missing decimal point would then append ".0", producing malformed labels like "1e+06.0" that Prometheus rejects with: ``` bucket label "le" is missing or has a malformed value of "1e+08.0" ``` Skip the ".0" suffix when the string already contains 'e', since scientific notation is valid in Prometheus `le` labels without it. Fixes #11651 Signed-off-by: Luis Pigueiras <luis.pigueiras@cern.ch>
1 parent 32a3cbb commit bc16164

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/cmetrics/src/cmt_encode_prometheus.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ static cfl_sds_t bucket_value_to_string(double val)
373373
len = snprintf(str, 64, "%g", val);
374374
cfl_sds_len_set(str, len);
375375

376-
if (!strchr(str, '.')) {
376+
/*
377+
* Append .0 only when there is no decimal point and the number
378+
* is not in scientific notation.
379+
*/
380+
if (!strchr(str, '.') && !strchr(str, 'e')) {
377381
cfl_sds_cat_safe(&str, ".0", 2);
378382
}
379383

0 commit comments

Comments
 (0)