Skip to content

Commit

Permalink
HPCC-31227 Address Prometheous histogram issues
Browse files Browse the repository at this point in the history
 - 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 <[email protected]>
  • Loading branch information
rpastrana committed Feb 9, 2024
1 parent 68e0dbd commit fcc03b0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions system/metrics/sinks/prometheus/prometheusSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ void PrometheusMetricSink::toPrometheusHistogram(const std::string &name, const
std::string PrometheusMetricSink::getPrometheusMetricName(const std::shared_ptr<IMetric> &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(), '.', '_');
Expand Down Expand Up @@ -240,16 +243,16 @@ const std::vector<std::string> &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
Expand Down

0 comments on commit fcc03b0

Please sign in to comment.