Fixing clash problem when counter clashes with previous registered histogram

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
This commit is contained in:
Pedro Tanaka 2022-08-26 11:29:31 +02:00
parent 30c3e31574
commit 7afa060ce4
No known key found for this signature in database
GPG key ID: D0D8389DA4EE060B

View file

@ -19,6 +19,7 @@ import (
"hash"
"hash/fnv"
"sort"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
@ -165,6 +166,15 @@ func (r *Registry) GetCounter(metricName string, labels prometheus.Labels, help
return nil, fmt.Errorf("metric with name %s is already registered", metricName)
}
histogramSuffixes := []string{"_bucket", "_count", "_sum"}
for _, suffix := range histogramSuffixes {
if strings.HasSuffix(metricName, suffix) {
if r.MetricConflicts(strings.TrimSuffix(metricName, suffix), metrics.CounterMetricType) {
return nil, fmt.Errorf("metric with name %s is already registered", metricName)
}
}
}
var counterVec *prometheus.CounterVec
if vh == nil {
metricsCount.WithLabelValues("counter").Inc()