Skip to content

Commit

Permalink
add log to basic lifecycler changeState
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Xu <[email protected]>
  • Loading branch information
wenxu1024 committed Dec 12, 2023
1 parent f9c26d0 commit b3a2a1f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/ring/basic_lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,21 @@ func (l *BasicLifecycler) heartbeat(ctx context.Context) {
// changeState of the instance within the ring. This function is guaranteed
// to be called within the lifecycler main goroutine.
func (l *BasicLifecycler) changeState(ctx context.Context, state InstanceState) error {
oldState := l.GetState()
err := l.updateInstance(ctx, func(_ *Desc, i *InstanceDesc) bool {
// No-op if the state hasn't changed.
if i.State == state {
return false
}

i.State = state
return true
})

if err != nil {
level.Warn(l.logger).Log("msg", "failed to change instance state in the ring", "from", l.GetState(), "to", state, "err", err)
level.Info(l.logger).Log("msg", "failed to change instance state in the ring", "from", oldState, "to", state, "ring", l.ringName, "err", err)
} else {
level.Info(l.logger).Log("msg", "successfully changed instance state from", "old_state", oldState, "to", state, "ring", l.ringName)
}

return err
}

Expand Down

0 comments on commit b3a2a1f

Please sign in to comment.