Skip to content

feat: add polling jitter to target manager intervals#433

Open
lvlcn-t wants to merge 4 commits into
feat/s3-oidc-authfrom
feat/s3-polling-jitter
Open

feat: add polling jitter to target manager intervals#433
lvlcn-t wants to merge 4 commits into
feat/s3-oidc-authfrom
feat/s3-polling-jitter

Conversation

@lvlcn-t
Copy link
Copy Markdown
Collaborator

@lvlcn-t lvlcn-t commented May 10, 2026

Motivation

When many sparrow instances share the same polling intervals, they
synchronize into a thundering herd — all hitting the backend at the same
instant. Adding jitter spreads requests over time, reducing peak load on
the S3/GitLab backend and improving resilience.

Stack: PR 4/4 — builds on #432 (OIDC auth).

Changes

  • Add helper.ApplyJitter(d, factor) in internal/helper/jitter.go with
    bounded minimum [d*(1-factor), d]
  • Guard against NaN and Inf factor inputs (treat as identity)
  • Add Jitter float64 field to General config struct with [0.0, 1.0]
    validation and ErrInvalidJitter sentinel
  • Wire jitter into manager.Reconcile() on all three timer resets
    (check, registration, update)
  • Add FuzzApplyJitter fuzz test (~3.7M executions, no failures) with
    property-based assertions (bounded minimum, never exceeds original,
    non-negative result)
  • Add deterministic TestApplyJitter_EdgeCases for NaN/Inf/zero
  • Add 4 validation test cases for jitter bounds
  • Document jitter in chart/values.yaml

For additional information look at the commits.

Tests done

  • Unit tests succeeded
  • Fuzz tests succeeded (~3.7M executions)
  • E2E tests succeeded

TODO

  • I've assigned this PR to myself
  • I've labeled this PR correctly

@lvlcn-t lvlcn-t self-assigned this May 10, 2026
@lvlcn-t lvlcn-t added feature Introduces a new feature area/target-manager Issues/PRs related to the TargetManager labels May 10, 2026
@lvlcn-t lvlcn-t force-pushed the feat/s3-polling-jitter branch from 1c41f4d to e45dd4e Compare May 10, 2026 19:19
@lvlcn-t lvlcn-t force-pushed the feat/s3-oidc-auth branch from e59bba7 to d64283c Compare May 10, 2026 19:19
@lvlcn-t lvlcn-t force-pushed the feat/s3-polling-jitter branch 2 times, most recently from c019974 to 878a529 Compare May 10, 2026 19:45
@lvlcn-t lvlcn-t force-pushed the feat/s3-oidc-auth branch from d64283c to 2d409cb Compare May 10, 2026 19:45
@lvlcn-t lvlcn-t force-pushed the feat/s3-polling-jitter branch from 878a529 to 2cf5259 Compare May 10, 2026 19:55
@lvlcn-t lvlcn-t force-pushed the feat/s3-oidc-auth branch from 2d409cb to 1d1af15 Compare May 10, 2026 19:55
Comment thread internal/helper/jitter.go Outdated
@lvlcn-t lvlcn-t requested a review from niklastreml May 14, 2026 18:00
@lvlcn-t lvlcn-t force-pushed the feat/s3-oidc-auth branch from 1d1af15 to b27be38 Compare May 14, 2026 18:28
lvlcn-t added 4 commits May 14, 2026 20:40
Apply configurable jitter to check, registration, and update timer
resets to prevent thundering-herd when many sparrow instances poll
the same backend simultaneously.

- Add helper.ApplyJitter with bounded minimum [d*(1-f), d]
- Add Jitter float64 field to General config with [0.0, 1.0] validation
- Wire jitter into manager.Reconcile timer resets
- Add jitter tests (helper bounds + validation cases)
- Document jitter in chart/values.yaml
Replace the hand-rolled 1000-iteration bounds check with a proper
Go fuzz test (FuzzApplyJitter) that generates random duration/factor
pairs and asserts invariant properties. Add NaN/Inf guards to
ApplyJitter to handle degenerate float inputs defensively.

- Add math.IsNaN/IsInf guard in ApplyJitter (treat as identity)
- Add FuzzApplyJitter with 8 seed corpus entries
- Keep deterministic TestApplyJitter_EdgeCases for NaN/Inf/zero
Signed-off-by: lvlcn-t <75443136+lvlcn-t@users.noreply.github.com>
@lvlcn-t lvlcn-t force-pushed the feat/s3-polling-jitter branch from 804409f to d847c29 Compare May 14, 2026 18:41
@lvlcn-t lvlcn-t force-pushed the feat/s3-oidc-auth branch from b27be38 to 2f9d8f3 Compare May 14, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/target-manager Issues/PRs related to the TargetManager feature Introduces a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants