Skip to content

Commit

Permalink
avoid double init
Browse files Browse the repository at this point in the history
  • Loading branch information
essamhassan committed Mar 1, 2023
1 parent c4451fc commit b98bf41
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"

"github.com/Depado/ginprom"
Expand Down Expand Up @@ -50,10 +51,9 @@ import (
)

var prometheus *ginprom.Prometheus
var initOnce sync.Once

func initPrometheus(cfg config.GeneralConfig) {
// ensure metrics are registered once per instance to avoid registering
// metrics multiple times (panic)
prometheus = ginprom.New(ginprom.Namespace("service"), ginprom.Token(cfg.PrometheusAuthToken()))
}

Expand Down Expand Up @@ -98,8 +98,11 @@ type ChainlinkAppFactory struct{}

// NewApplication returns a new instance of the node with the given config.
func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg config.GeneralConfig, appLggr logger.Logger, db *sqlx.DB) (app chainlink.Application, err error) {
initPrometheus(cfg)
appLggr.Critical("Auth token:", cfg.PrometheusAuthToken())
// Avoid double initializations.
initOnce.Do(func() {
initPrometheus(cfg)
})

keyStore := keystore.New(db, utils.GetScryptParams(cfg), appLggr, cfg)

// Set up the versioning ORM
Expand Down

0 comments on commit b98bf41

Please sign in to comment.