Handle duplicate registrations

This commit is contained in:
Abdul Rabbani 2022-05-25 10:12:38 -04:00
parent 217e6cb4d6
commit 0d624176de
2 changed files with 13 additions and 3 deletions

View File

@ -25,9 +25,15 @@ import (
var _ = Describe("Healthcheck", func() { var _ = Describe("Healthcheck", func() {
var ( var (
BC *beaconclient.BeaconClient
errBc *beaconclient.BeaconClient
)
BeforeEach(func() {
BC = beaconclient.CreateBeaconClient(context.Background(), "http", "localhost", 5052, 10) BC = beaconclient.CreateBeaconClient(context.Background(), "http", "localhost", 5052, 10)
errBc = beaconclient.CreateBeaconClient(context.Background(), "http", "blah-blah", 1010, 10) errBc = beaconclient.CreateBeaconClient(context.Background(), "http", "blah-blah", 1010, 10)
)
})
Describe("Connecting to the lighthouse client", Label("integration"), func() { Describe("Connecting to the lighthouse client", Label("integration"), func() {
Context("When the client is running", func() { Context("When the client is running", func() {
It("We should connect successfully", func() { It("We should connect successfully", func() {

View File

@ -20,6 +20,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
) )
//Create a metric struct and register each channel with prometheus //Create a metric struct and register each channel with prometheus
@ -44,7 +45,7 @@ func CreateBeaconClientMetrics() *BeaconClientMetrics {
} }
func prometheusRegisterHelper(name string, help string, varPointer *uint64) { func prometheusRegisterHelper(name string, help string, varPointer *uint64) {
prometheus.MustRegister(prometheus.NewCounterFunc( err := prometheus.Register(prometheus.NewCounterFunc(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "beacon_client", Namespace: "beacon_client",
Subsystem: "", Subsystem: "",
@ -55,6 +56,9 @@ func prometheusRegisterHelper(name string, help string, varPointer *uint64) {
func() float64 { func() float64 {
return float64(atomic.LoadUint64(varPointer)) return float64(atomic.LoadUint64(varPointer))
})) }))
if err != nil && err.Error() != "duplicate metrics collector registration attempted" {
loghelper.LogError(err).WithField("name", name).Error("Unable to register counter.")
}
} }
// A structure utilized for keeping track of various metrics. Currently, mostly used in testing. // A structure utilized for keeping track of various metrics. Currently, mostly used in testing.