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

Add timeout on lifecycler heartbeat #6212

Merged
merged 2 commits into from
Sep 17, 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
10 changes: 6 additions & 4 deletions pkg/ring/lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (i *Lifecycler) loop(ctx context.Context) error {
// We are jittering for at least half of the time and max the time of the heartbeat.
// If we jitter too soon, we can have problems of concurrency with autoJoin leaving the instance on ACTIVE without tokens
time.AfterFunc(time.Duration(uint64(i.cfg.HeartbeatPeriod/2)+uint64(mathrand.Int63())%uint64(i.cfg.HeartbeatPeriod/2)), func() {
i.heartbeat()
i.heartbeat(ctx)
heartbeatTicker.Reset(i.cfg.HeartbeatPeriod)
})
defer heartbeatTicker.Stop()
Expand Down Expand Up @@ -530,7 +530,7 @@ func (i *Lifecycler) loop(ctx context.Context) error {
}

case <-heartbeatTickerChan:
i.heartbeat()
i.heartbeat(ctx)
case f := <-i.actorChan:
f()

Expand All @@ -541,9 +541,11 @@ func (i *Lifecycler) loop(ctx context.Context) error {
}
}

func (i *Lifecycler) heartbeat() {
func (i *Lifecycler) heartbeat(ctx context.Context) {
i.lifecyclerMetrics.consulHeartbeats.Inc()
if err := i.updateConsul(context.Background()); err != nil {
ctx, cancel := context.WithTimeout(ctx, i.cfg.HeartbeatPeriod)
defer cancel()
if err := i.updateConsul(ctx); err != nil {
level.Error(i.logger).Log("msg", "failed to write to the KV store, sleeping", "ring", i.RingName, "err", err)
}
}
Expand Down
Loading