Skip to content

Commit 2bb245a

Browse files
committed
fix: do not register storage metric collectors if it is not enabled
If discovery service storage is not enabled, we were still wrongly registering it as prometheus metrics collector, because the nil check was done against the interface. It had to be done on the concrete type instead. Signed-off-by: Utku Ozdemir <[email protected]>
1 parent b8da986 commit 2bb245a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

pkg/service/service.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func Run(ctx context.Context, options Options, logger *zap.Logger) error {
181181
return fmt.Errorf("failed to configure server: %w", err)
182182
}
183183

184-
if options.SnapshotsEnabled {
184+
if stateStorage != nil {
185185
eg.Go(func() error {
186186
return stateStorage.Start(ctx, clockwork.NewRealClock(), options.SnapshotInterval)
187187
})
@@ -295,7 +295,11 @@ func Run(ctx context.Context, options Options, logger *zap.Logger) error {
295295
}
296296

297297
if options.MetricsRegisterer != nil {
298-
collectors := []prom.Collector{state, srv, metrics, stateStorage}
298+
collectors := []prom.Collector{state, srv, metrics}
299+
300+
if stateStorage != nil {
301+
collectors = append(collectors, stateStorage)
302+
}
299303

300304
defer unregisterCollectors(options.MetricsRegisterer, collectors...)
301305

@@ -319,20 +323,12 @@ func recoveryHandler(logger *zap.Logger) grpc_recovery.RecoveryHandlerFunc {
319323

320324
func unregisterCollectors(registerer prom.Registerer, collectors ...prom.Collector) {
321325
for _, collector := range collectors {
322-
if collector == nil {
323-
continue
324-
}
325-
326326
registerer.Unregister(collector)
327327
}
328328
}
329329

330330
func registerCollectors(registerer prom.Registerer, collectors ...prom.Collector) (err error) {
331331
for _, collector := range collectors {
332-
if collector == nil {
333-
continue
334-
}
335-
336332
if err = registerer.Register(collector); err != nil {
337333
return fmt.Errorf("failed to register collector: %w", err)
338334
}

0 commit comments

Comments
 (0)