Merge pull request #1084 from c9s/bhwu/avoid-init-metrics-twice

FIX: [grid2] avoid initializing metrics twice
This commit is contained in:
Yo-An Lin 2023-03-06 17:21:06 +08:00 committed by GitHub
commit bb80df096b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
package grid2 package grid2
import "github.com/prometheus/client_golang/prometheus" import (
"github.com/prometheus/client_golang/prometheus"
)
var ( var (
metricsGridNum *prometheus.GaugeVec metricsGridNum *prometheus.GaugeVec
@ -32,6 +34,10 @@ func mergeLabels(a, b prometheus.Labels) prometheus.Labels {
} }
func initMetrics(extendedLabels []string) { func initMetrics(extendedLabels []string) {
if metricsGridNum != nil {
return
}
metricsGridNum = prometheus.NewGaugeVec( metricsGridNum = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "bbgo_grid2_num", Name: "bbgo_grid2_num",
@ -110,4 +116,4 @@ func registerMetrics() {
metricsGridOrderPrices, metricsGridOrderPrices,
) )
metricsRegistered = true metricsRegistered = true
} }