Skip to content

Commit

Permalink
Revert "clean code (apache#1858)" (apache#1860)
Browse files Browse the repository at this point in the history
This reverts commit 8bea4b3.
  • Loading branch information
AlexStocks committed Apr 24, 2022
1 parent 8bea4b3 commit 303958b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions metrics/prometheus/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
ocprom "contrib.go.opencensus.io/exporter/prometheus"

"github.com/prometheus/client_golang/prometheus"
prom "github.com/prometheus/client_golang/prometheus"
)

import (
Expand Down Expand Up @@ -216,9 +217,9 @@ func newPrometheusReporter(reporterConfig *metrics.ReporterConfig) metrics.Repor
providerRTGaugeVec: newGaugeVec(providerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
}

prometheus.DefaultRegisterer.MustRegister(reporterInstance.consumerRTGaugeVec, reporterInstance.providerRTGaugeVec)
prom.DefaultRegisterer.MustRegister(reporterInstance.consumerRTGaugeVec, reporterInstance.providerRTGaugeVec)
metricsExporter, err := ocprom.NewExporter(ocprom.Options{
Registry: prometheus.DefaultRegisterer.(*prometheus.Registry),
Registry: prom.DefaultRegisterer.(*prom.Registry),
})
if err != nil {
logger.Errorf("new prometheus reporter with error = %s", err)
Expand Down Expand Up @@ -249,7 +250,7 @@ func (reporter *PrometheusReporter) setGauge(gaugeName string, toSetValue float6
// gauge
if val, exist := reporter.userGauge.Load(gaugeName); !exist {
newGauge := newGauge(gaugeName, reporter.namespace)
_ = prometheus.DefaultRegisterer.Register(newGauge)
_ = prom.DefaultRegisterer.Register(newGauge)

reporter.userGauge.Store(gaugeName, newGauge)
newGauge.Set(toSetValue)
Expand All @@ -266,7 +267,7 @@ func (reporter *PrometheusReporter) setGauge(gaugeName string, toSetValue float6
keyList = append(keyList, k)
}
newGaugeVec := newGaugeVec(gaugeName, reporter.namespace, keyList)
_ = prometheus.DefaultRegisterer.Register(newGaugeVec)
_ = prom.DefaultRegisterer.Register(newGaugeVec)
reporter.userGaugeVec.Store(gaugeName, newGaugeVec)
newGaugeVec.With(labelMap).Set(toSetValue)
} else {
Expand All @@ -281,7 +282,7 @@ func (reporter *PrometheusReporter) incCounter(counterName string, labelMap prom
// counter
if val, exist := reporter.userCounter.Load(counterName); !exist {
newCounter := newCounter(counterName, reporter.namespace)
_ = prometheus.DefaultRegisterer.Register(newCounter)
_ = prom.DefaultRegisterer.Register(newCounter)
reporter.userCounter.Store(counterName, newCounter)
newCounter.Inc()
} else {
Expand All @@ -297,7 +298,7 @@ func (reporter *PrometheusReporter) incCounter(counterName string, labelMap prom
keyList = append(keyList, k)
}
newCounterVec := newCounterVec(counterName, reporter.namespace, keyList)
_ = prometheus.DefaultRegisterer.Register(newCounterVec)
_ = prom.DefaultRegisterer.Register(newCounterVec)
reporter.userCounterVec.Store(counterName, newCounterVec)
newCounterVec.With(labelMap).Inc()
} else {
Expand All @@ -312,7 +313,7 @@ func (reporter *PrometheusReporter) incSummary(summaryName string, toSetValue fl
// summary
if val, exist := reporter.userSummary.Load(summaryName); !exist {
newSummary := newSummary(summaryName, reporter.namespace)
_ = prometheus.DefaultRegisterer.Register(newSummary)
_ = prom.DefaultRegisterer.Register(newSummary)
reporter.userSummary.Store(summaryName, newSummary)
newSummary.Observe(toSetValue)
} else {
Expand All @@ -328,7 +329,7 @@ func (reporter *PrometheusReporter) incSummary(summaryName string, toSetValue fl
keyList = append(keyList, k)
}
newSummaryVec := newSummaryVec(summaryName, reporter.namespace, keyList)
_ = prometheus.DefaultRegisterer.Register(newSummaryVec)
_ = prom.DefaultRegisterer.Register(newSummaryVec)
reporter.userSummaryVec.Store(summaryName, newSummaryVec)
newSummaryVec.With(labelMap).Observe(toSetValue)
} else {
Expand Down

0 comments on commit 303958b

Please sign in to comment.