From df744efa0d5640ade5d6e0f7581c1d8385f729b4 Mon Sep 17 00:00:00 2001 From: Luis Pigueiras Date: Wed, 1 Apr 2026 21:21:20 +0200 Subject: [PATCH] cmetrics: prevent appending .0 to scientific notation to le bucket labels `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 --- lib/cmetrics/src/cmt_encode_prometheus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cmetrics/src/cmt_encode_prometheus.c b/lib/cmetrics/src/cmt_encode_prometheus.c index b5f76149c75..8e3bfd07531 100644 --- a/lib/cmetrics/src/cmt_encode_prometheus.c +++ b/lib/cmetrics/src/cmt_encode_prometheus.c @@ -373,7 +373,11 @@ static cfl_sds_t bucket_value_to_string(double val) len = snprintf(str, 64, "%g", val); cfl_sds_len_set(str, len); - if (!strchr(str, '.')) { + /* + * Append .0 only when there is no decimal point and the number + * is not in scientific notation. + */ + if (!strchr(str, '.') && !strchr(str, 'e')) { cfl_sds_cat_safe(&str, ".0", 2); }