From fcc03b0f65ae00cea2f69c48e6d50e171ba80c1a Mon Sep 17 00:00:00 2001 From: Rodrigo Pastrana Date: Fri, 9 Feb 2024 14:52:11 -0500 Subject: [PATCH] HPCC-31227 Address Prometheous histogram issues - Fixes invalid quote on le=+Inf bucket - Qualifies sum and count w/ metric name - Normalizes all names to lowercase per promtool suggestion Signed-off-by: Rodrigo Pastrana --- system/metrics/sinks/prometheus/prometheusSink.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/system/metrics/sinks/prometheus/prometheusSink.cpp b/system/metrics/sinks/prometheus/prometheusSink.cpp index dcb6929dab8..90a29294db9 100644 --- a/system/metrics/sinks/prometheus/prometheusSink.cpp +++ b/system/metrics/sinks/prometheus/prometheusSink.cpp @@ -180,6 +180,9 @@ void PrometheusMetricSink::toPrometheusHistogram(const std::string &name, const std::string PrometheusMetricSink::getPrometheusMetricName(const std::shared_ptr &pMetric) { std::string name = pMetric->queryName(); + // Convert to lower case - per promtool output: "metric names should be written in 'snake_case' not 'camelCase'" + std::transform(name.begin(), name.end(), name.begin(), + [](unsigned char c){ return std::tolower(c); }); //'.' is a known char used in HPCC metric names but invalid in Prometheus std::replace(name.begin(), name.end(), '.', '_'); @@ -240,16 +243,16 @@ const std::vector &PrometheusMetricSink::getHistogramLabels(const s // Add the inf label std::string infLabel(name); - infLabel.append("_bucket{\"le=+Inf\"}"); + infLabel.append("_bucket{le=\"+Inf\"}"); labels.emplace_back(infLabel); // Sum and count - std::string sumLabel; - sumLabel.append("_sum"); + std::string sumLabel(name); + sumLabel.append("_sum{}"); labels.emplace_back(sumLabel); - std::string countLabel; - countLabel.append("_count"); + std::string countLabel(name); + countLabel.append("_count{}"); labels.emplace_back(countLabel); // Insert the labels for reuse