Skip to content

feat(consumers): Auto-restart on single-partition lag - #8386

Open
sentry-junior[bot] wants to merge 8 commits into
masterfrom
feat/partition-stall-watchdog
Open

feat(consumers): Auto-restart on single-partition lag#8386
sentry-junior[bot] wants to merge 8 commits into
masterfrom
feat/partition-stall-watchdog

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Automatically resolve single-partition consumer lag by failing the pod healthcheck so Kubernetes restarts the member and Kafka rebalances.

Why

We saw one assigned partition fall far behind peers while offsets still moved slowly. Kafka does not rebalance in that case. GLOBAL subscription schedulers wait on the slow partition and shed stale work.

A hard "no commits at all" check is not enough. The observed failure was throughput collapse, not a hung poll loop.

What

Option-gated watchdog in the Snuba rust healthcheck (--health-check-file required):

  1. Hard stall (consumer.partition_stall_timeout_secs > 0): partition has in-flight work and no commit progress past the timeout.
  2. Relative slowdown (default on when the timeout is set): over one timeout-sized window, a partition's commit rate is below consumer.partition_slow_ratio of the median sibling rate on this assignment while still receiving work. Default ratio is 0.25. Set ratio to 0 for hard-stall only.

Either failure stops touching the health file. The k8s liveness probe restarts the pod and Kafka reassigns the partitions.

Enabling the stall timeout auto-selects the Snuba healthcheck even if --health-check is still arroyo.

Naming / docs

  • Renamed experimental_healthcheckconsumer.commit_progress_healthcheck (consumer-level commit/idle progress).
  • Kept experimental_healthcheck as a legacy alias.
  • Documented strategy implementations and progress modes in docs/source/architecture/consumer.rst (Healthchecks).

Enable

Via sentry-options (no deploy flag change if health-check file is already set):

  • consumer.partition_stall_timeout_secs: start around 300
  • consumer.partition_slow_ratio: default 0.25 (optional)
  • consumer.commit_progress_healthcheck: optional consumer-level mode

Follow-up outside this PR: rename the key in getsentry/sentry-options-automator (experimental_healthcheck: falseconsumer.commit_progress_healthcheck: false). Safe either way while the alias exists.

Limits

  • Relative check needs ≥2 active partitions on the same pod. Single-partition members only get the hard-stall check.
  • Quiet assignments (median sibling rate under 50 offsets/s) skip relative slowdown to avoid false positives.
  • Restart helps when the owning member is the problem. If the partition is inherently hot/data-path broken, lag can follow the reassignment.
  • Python consumers still use the arroyo poll-only healthcheck.

Test plan

  • cargo test --lib strategies::healthcheck (9 tests, including legacy alias + relative slowdown)
  • Enable options in a non-prod region on a multi-partition rust consumer with health-check file
  • Confirm healthy steady state still touches /tmp/health.txt
  • Confirm a collapsed partition fails liveness and lag moves after restart

Requested by PDPM.

--

View Junior Session in Sentry

sentry-junior Bot and others added 3 commits August 23, 2026 20:55
Add an option-gated watchdog in the Snuba rust healthcheck that tracks
submit vs commit progress per partition. When a partition has in-flight
work without commit progress past the timeout, stop touching the health
file so the k8s liveness probe restarts the pod and Kafka rebalances.

Co-Authored-By: PDPM <pierre.massat@sentry.io>
Extend the stall watchdog so it also fails health when one assigned
partition's commit rate falls far below the median sibling rate while
still receiving work. That covers the single-partition lag case where
offsets still move slowly and a hard commit stall never fires.

Co-Authored-By: PDPM <pierre.massat@sentry.io>

Co-Authored-By: PDPM <pierre.massat@sentry.io>
@sentry-junior sentry-junior Bot changed the title feat(consumers): Restart on per-partition commit stall feat(consumers): Auto-restart on single-partition lag Aug 23, 2026
getsantry Bot and others added 3 commits August 23, 2026 21:28
Rename experimental_healthcheck to consumer.commit_progress_healthcheck
so the name matches consumer-level commit/idle progress checks. Keep the
old key as a legacy alias. Document strategy and progress modes in the
consumer architecture docs.

Co-Authored-By: PDPM <pierre.massat@sentry.io>
@phacops
phacops marked this pull request as ready for review August 23, 2026 23:25
@phacops
phacops requested a review from a team as a code owner August 23, 2026 23:25
Comment thread rust_snuba/src/strategies/healthcheck.rs Outdated
Compare each partition to the median of the other active partitions on
the assignment. An inclusive median diluted the slow partition on small
assignments, so the default 0.25 ratio missed the two-partition collapse
case.

Co-Authored-By: PDPM <pierre.massat@sentry.io>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9abdb3a. Configure here.

Comment thread rust_snuba/src/strategies/healthcheck.rs
Keep leave-one-out sibling medians for the ratio comparison, but gate the
whole assignment on an inclusive median quiet floor so one hot partition
cannot fail mostly-quiet peers. Also satisfy clippy::question_mark on the
slow-ratio option helper.

Co-Authored-By: PDPM <pierre.massat@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant