fix panic in multiple metrics with the same name and different labels
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
fe897ee428
commit
13843fbcf4
@ -103,10 +103,10 @@ func (m *prometheusMeter) Counter(name string, labels ...string) meter.Counter {
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
nm := m.buildMetric(name, labels...)
|
nm := m.buildName(name)
|
||||||
c, ok := m.counter[nm]
|
c, ok := m.counter[nm]
|
||||||
if !ok {
|
if !ok {
|
||||||
nc := prometheus.NewGauge(prometheus.GaugeOpts{Name: m.buildName(name), ConstLabels: m.mapLabels(labels...)})
|
nc := prometheus.NewGauge(prometheus.GaugeOpts{Name: nm, ConstLabels: m.mapLabels(labels...)})
|
||||||
m.set.MustRegister(nc)
|
m.set.MustRegister(nc)
|
||||||
c = prometheusCounter{c: nc}
|
c = prometheusCounter{c: nc}
|
||||||
m.counter[nm] = c
|
m.counter[nm] = c
|
||||||
@ -119,10 +119,10 @@ func (m *prometheusMeter) FloatCounter(name string, labels ...string) meter.Floa
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
nm := m.buildMetric(name, labels...)
|
nm := m.buildName(name)
|
||||||
c, ok := m.floatCounter[nm]
|
c, ok := m.floatCounter[nm]
|
||||||
if !ok {
|
if !ok {
|
||||||
nc := prometheus.NewGauge(prometheus.GaugeOpts{Name: m.buildName(name), ConstLabels: m.mapLabels(labels...)})
|
nc := prometheus.NewGauge(prometheus.GaugeOpts{Name: nm, ConstLabels: m.mapLabels(labels...)})
|
||||||
m.set.MustRegister(nc)
|
m.set.MustRegister(nc)
|
||||||
c = prometheusFloatCounter{c: nc}
|
c = prometheusFloatCounter{c: nc}
|
||||||
m.floatCounter[nm] = c
|
m.floatCounter[nm] = c
|
||||||
@ -135,10 +135,10 @@ func (m *prometheusMeter) Gauge(name string, fn func() float64, labels ...string
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
nm := m.buildMetric(name, labels...)
|
nm := m.buildName(name)
|
||||||
c, ok := m.gauge[nm]
|
c, ok := m.gauge[nm]
|
||||||
if !ok {
|
if !ok {
|
||||||
nc := prometheus.NewGauge(prometheus.GaugeOpts{Name: m.buildName(name), ConstLabels: m.mapLabels(labels...)})
|
nc := prometheus.NewGauge(prometheus.GaugeOpts{Name: nm, ConstLabels: m.mapLabels(labels...)})
|
||||||
m.set.MustRegister(nc)
|
m.set.MustRegister(nc)
|
||||||
c = prometheusGauge{c: nc}
|
c = prometheusGauge{c: nc}
|
||||||
m.gauge[nm] = c
|
m.gauge[nm] = c
|
||||||
@ -151,10 +151,10 @@ func (m *prometheusMeter) Histogram(name string, labels ...string) meter.Histogr
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
nm := m.buildMetric(name, labels...)
|
nm := m.buildName(name)
|
||||||
c, ok := m.histogram[nm]
|
c, ok := m.histogram[nm]
|
||||||
if !ok {
|
if !ok {
|
||||||
nc := prometheus.NewHistogram(prometheus.HistogramOpts{Name: m.buildName(name), ConstLabels: m.mapLabels(labels...)})
|
nc := prometheus.NewHistogram(prometheus.HistogramOpts{Name: nm, ConstLabels: m.mapLabels(labels...)})
|
||||||
m.set.MustRegister(nc)
|
m.set.MustRegister(nc)
|
||||||
c = prometheusHistogram{c: nc}
|
c = prometheusHistogram{c: nc}
|
||||||
m.histogram[nm] = c
|
m.histogram[nm] = c
|
||||||
@ -167,10 +167,10 @@ func (m *prometheusMeter) Summary(name string, labels ...string) meter.Summary {
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
nm := m.buildMetric(name, labels...)
|
nm := m.buildName(name)
|
||||||
c, ok := m.summary[nm]
|
c, ok := m.summary[nm]
|
||||||
if !ok {
|
if !ok {
|
||||||
nc := prometheus.NewSummary(prometheus.SummaryOpts{Name: m.buildName(name), ConstLabels: m.mapLabels(labels...)})
|
nc := prometheus.NewSummary(prometheus.SummaryOpts{Name: nm, ConstLabels: m.mapLabels(labels...)})
|
||||||
m.set.MustRegister(nc)
|
m.set.MustRegister(nc)
|
||||||
c = prometheusSummary{c: nc}
|
c = prometheusSummary{c: nc}
|
||||||
m.summary[nm] = c
|
m.summary[nm] = c
|
||||||
@ -183,11 +183,11 @@ func (m *prometheusMeter) SummaryExt(name string, window time.Duration, quantile
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
nm := m.buildMetric(name, labels...)
|
nm := m.buildName(name)
|
||||||
c, ok := m.summary[nm]
|
c, ok := m.summary[nm]
|
||||||
if !ok {
|
if !ok {
|
||||||
nc := prometheus.NewSummary(prometheus.SummaryOpts{
|
nc := prometheus.NewSummary(prometheus.SummaryOpts{
|
||||||
Name: m.buildName(name),
|
Name: nm,
|
||||||
ConstLabels: m.mapLabels(labels...),
|
ConstLabels: m.mapLabels(labels...),
|
||||||
MaxAge: window,
|
MaxAge: window,
|
||||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||||
|
Loading…
Reference in New Issue
Block a user