diff --git a/service/telemetry.go b/service/telemetry.go index 1dbdab6480a..053e5cdf961 100644 --- a/service/telemetry.go +++ b/service/telemetry.go @@ -17,6 +17,7 @@ package service import ( "net/http" "strings" + "sync" "unicode" "contrib.go.opencensus.io/exporter/prometheus" @@ -41,11 +42,20 @@ type collectorTelemetryExporter interface { } type colTelemetry struct { - views []*view.View - server *http.Server + views []*view.View + server *http.Server + doInitOnce sync.Once } -func (tel *colTelemetry) init(asyncErrorChannel chan<- error, ballastSizeBytes uint64, logger *zap.Logger) error { +func (tel *colTelemetry) init(asyncErrorChannel chan<- error, ballastSizeBytes uint64, logger *zap.Logger) (err error) { + tel.doInitOnce.Do( + func() { + err = tel.initOnce(asyncErrorChannel, ballastSizeBytes, logger) + }, + ) + return +} +func (tel *colTelemetry) initOnce(asyncErrorChannel chan<- error, ballastSizeBytes uint64, logger *zap.Logger) error { level := configtelemetry.GetMetricsLevelFlagValue() metricsAddr := telemetry.GetMetricsAddr()