From ae66cad32cfd2d277c80eb17ae8f51a3c9c6d8a3 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Wed, 6 Mar 2019 15:50:52 +0100 Subject: [PATCH] Multiply also the sum in the prometheus multiplier option --- metricbeat/helper/prometheus/metric.go | 5 +++++ metricbeat/helper/prometheus/prometheus_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/metricbeat/helper/prometheus/metric.go b/metricbeat/helper/prometheus/metric.go index 22dd721861de..c726e4ab99b3 100644 --- a/metricbeat/helper/prometheus/metric.go +++ b/metricbeat/helper/prometheus/metric.go @@ -289,6 +289,10 @@ func (o opMultiplyBuckets) Process(field string, value interface{}, labels commo if !ok { return field, value, labels } + sum, ok := histogram["sum"].(float64) + if !ok { + return field, value, labels + } multiplied := common.MapStr{} for k, v := range bucket { if f, err := strconv.ParseFloat(k, 64); err == nil { @@ -299,5 +303,6 @@ func (o opMultiplyBuckets) Process(field string, value interface{}, labels commo } } histogram["bucket"] = multiplied + histogram["sum"] = sum * o.multiplier return field, histogram, labels } diff --git a/metricbeat/helper/prometheus/prometheus_test.go b/metricbeat/helper/prometheus/prometheus_test.go index 97fce8c1c6a6..0bcdc3ba3ff2 100644 --- a/metricbeat/helper/prometheus/prometheus_test.go +++ b/metricbeat/helper/prometheus/prometheus_test.go @@ -356,7 +356,7 @@ func TestPrometheus(t *testing.T) { "1000": uint64(3), "+Inf": uint64(5), }, - "sum": 4.31, + "sum": 4310.0, }, }, },