Skip to content

Commit

Permalink
fix(pruner): unregister callbck from meter on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Mar 27, 2024
1 parent ba66240 commit d5a9784
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pruner/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type metrics struct {

lastPruned metric.Int64ObservableGauge
failedPrunes metric.Int64ObservableGauge

clientReg metric.Registration
}

func (s *Service) WithMetrics() error {
Expand Down Expand Up @@ -44,18 +46,28 @@ func (s *Service) WithMetrics() error {
return nil
}

if _, err := meter.RegisterCallback(callback, lastPruned, failedPrunes); err != nil {
clientReg, err := meter.RegisterCallback(callback, lastPruned, failedPrunes)
if err != nil {
return err
}

s.metrics = &metrics{
prunedCounter: prunedCounter,
lastPruned: lastPruned,
failedPrunes: failedPrunes,
clientReg: clientReg,
}
return nil
}

func (m *metrics) close() error {
if m == nil {
return nil
}

return m.clientReg.Unregister()
}

func (m *metrics) observePrune(ctx context.Context, failed bool) {
if m == nil {
return
Expand Down
2 changes: 2 additions & 0 deletions pruner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (s *Service) Start(context.Context) error {
func (s *Service) Stop(ctx context.Context) error {
s.cancel()

s.metrics.close()

select {
case <-s.doneCh:
return nil
Expand Down

0 comments on commit d5a9784

Please sign in to comment.