Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not register storage metric collectors if it is not enabled #71

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func Run(ctx context.Context, options Options, logger *zap.Logger) error {
return fmt.Errorf("failed to configure server: %w", err)
}

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

if options.MetricsRegisterer != nil {
collectors := []prom.Collector{state, srv, metrics, stateStorage}
collectors := []prom.Collector{state, srv, metrics}

if stateStorage != nil {
collectors = append(collectors, stateStorage)
}

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

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

func unregisterCollectors(registerer prom.Registerer, collectors ...prom.Collector) {
for _, collector := range collectors {
if collector == nil {
continue
}

registerer.Unregister(collector)
}
}

func registerCollectors(registerer prom.Registerer, collectors ...prom.Collector) (err error) {
for _, collector := range collectors {
if collector == nil {
continue
}

if err = registerer.Register(collector); err != nil {
return fmt.Errorf("failed to register collector: %w", err)
}
Expand Down