From cce95f6980082766064bf36cdcc1d9b3cf2e14a7 Mon Sep 17 00:00:00 2001 From: Clayton O'Neill Date: Wed, 15 May 2019 09:01:35 -0400 Subject: [PATCH] Check for histogram conflict on main name While it doesn't report it as a metric, when collecting, the registry considers the base metric name to below to the histogram that's registered. This means that we need to prevent other metrics from registering anything under this name, in addition to checking for the bucket, sum and count suffixes. Signed-off-by: Clayton O'Neill --- exporter.go | 3 +++ exporter_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/exporter.go b/exporter.go index 220198d..bf2b4bd 100644 --- a/exporter.go +++ b/exporter.go @@ -262,6 +262,9 @@ func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, mc histogramVec, ok := c.Elements[mapKey] if !ok { + if mc.metricConflicts(metricName, HistogramMetricType) { + return nil, fmt.Errorf("metric with name %s is already registered", metricName) + } if mc.metricConflicts(metricName+"_sum", HistogramMetricType) { return nil, fmt.Errorf("metric with name %s is already registered", metricName) } diff --git a/exporter_test.go b/exporter_test.go index 9abfa27..06089bd 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -235,6 +235,20 @@ func TestConflictingMetrics(t *testing.T) { }, }, }, + { + name: "counter vs histogram", + expected: []float64{1}, + in: Events{ + &CounterEvent{ + metricName: "histogram_test1", + value: 1, + }, + &TimerEvent{ + metricName: "histogram.test1", + value: 2, + }, + }, + }, { name: "counter vs histogram sum", expected: []float64{1},