Skip to content

[RFC] Remove quartz/clock from silence and nflog, and drop the dependency#5376

Open
ultrotter wants to merge 2 commits into
prometheus:mainfrom
ultrotter:noquartz1
Open

[RFC] Remove quartz/clock from silence and nflog, and drop the dependency#5376
ultrotter wants to merge 2 commits into
prometheus:mainfrom
ultrotter:noquartz1

Conversation

@ultrotter

@ultrotter ultrotter commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This is only used by tests, and we can instead use testing/synctest to get stable mocked time and time.Sleep for instant time advancement in testing/synctest.

Add synctest to TestSilencesSnapshot as it needs stable times even if it doesn't advance them

Pull Request Checklist

Please check all the applicable boxes.

Which user-facing changes does this PR introduce?

NONE

This is only used by tests, and we can instead use testing/synctest to
get stable mocked time and time.Sleep for instant time advancement in
testing/synctest.

Add synctest to TestSilencesSnapshot as it needs stable times even if it doesn't advance them

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
@ultrotter ultrotter requested a review from a team as a code owner July 6, 2026 14:37
Signed-off-by: Guido Trotter <guido@hudson-trading.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Removes the quartz clock dependency from silence and nflog code, updates benchmarks and tests to use real wall-clock time, and adds a test.SyncTestRun helper for synchronized subtests.

Changes

Quartz clock removal and synctest migration

Layer / File(s) Summary
SyncTestRun test helper
test/util.go
Adds SyncTestRun, which wraps t.Run in synctest.Test.
Production clock removal
go.mod, silence/silence.go, nflog/nflog.go
Removes the quartz dependency and clock fields, and switches time handling to time.Now, time.NewTicker, and time.Since.
Benchmark updates to use real time
silence/silence_bench_test.go
Replaces quartz mock clocks with time.Now across benchmarks and removes the internal clock assignment in benchmarkGC.
GC and snapshot tests converted to real time
silence/silence_test.go
Updates GC, snapshot, and maintenance tests to use real timestamps, time.Sleep, synctest.Test, and test.SyncTestRun.
Silence set/state tests converted to real time
silence/silence_test.go
Refactors silence set, active-silence, failure, and query-state tests to use synctest.Test, s.nowUTC, and time.Sleep.
Expiration, silencer, and annotation tests converted to real time
silence/silence_test.go
Converts silence expiration, silencer, log, and annotation tests to synctest.Test with sleep-driven progression.
nflog tests migrated to real time
nflog/nflog_test.go
Rewrites nflog tests to remove quartz mocks, use time.Now/time.Sleep, and coordinate maintenance with synctest.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Maintenance
  participant Ticker as time.Ticker
  participant Log as nflog.Log
  participant Silences

  Maintenance->>Ticker: time.NewTicker(interval)
  Ticker-->>Maintenance: tick
  Maintenance->>Silences: run maintenance
  Maintenance->>Log: time.Since(start) for completion log
Loading

Related Issues: None specified.

Related PRs: None specified.

Suggested labels: testing, refactor, dependencies

Suggested reviewers: None specified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes removing quartz/clock usage and dropping the dependency in silence and nflog.
Description check ✅ Passed The description follows the template reasonably well, includes checklist items, an issue reference, and the release-notes block.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
silence/silence_bench_test.go (1)

140-140: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Inconsistent expiry-window margins after switching to real time.

benchmarkMutes/benchmarkMutesParallel had their EndsAt windows bumped from 1 minute to 24 hours when moving off the mock clock (Lines 95, 107, 511), presumably to avoid silences expiring mid-run under real wall-clock time. BenchmarkMutesIncremental, benchmarkQuery, benchmarkQueryParallel, and benchmarkQueryWithConcurrentAdds follow the identical pattern (compute now once, then loop with b.Loop()/b.RunParallel() for the benchtime duration) but were left with only a 1-hour window (Lines 163, 173, 216, 227, 282, 347, 426, 461). With real time now driving expiry, a sufficiently long -benchtime/-count run (e.g., CI stability runs) could let these silences actually expire mid-benchmark, silently skewing QState(SilenceStateActive) results.

Consider extending these windows to match the 24-hour margin applied elsewhere for consistency and to remove this residual flakiness risk.

Also applies to: 163-163, 173-173, 216-216, 227-227, 261-261, 282-282, 328-328, 347-347, 407-407, 426-426, 461-461

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@silence/silence_bench_test.go` at line 140, Extend the silence expiry windows
in the benchmark helpers that use a single cached time value, since
`BenchmarkMutesIncremental`, `benchmarkQuery`, `benchmarkQueryParallel`, and
`benchmarkQueryWithConcurrentAdds` still use a 1-hour `EndsAt` margin while the
real-time benchmarks elsewhere were widened to 24 hours. Update the `EndsAt`
calculations in those benchmark setup blocks to match the 24-hour buffer used by
`benchmarkMutes`/`benchmarkMutesParallel`, keeping the existing `now :=
time.Now()` pattern intact so `QState(SilenceStateActive)` remains stable across
long benchmark runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@silence/silence_bench_test.go`:
- Line 140: Extend the silence expiry windows in the benchmark helpers that use
a single cached time value, since `BenchmarkMutesIncremental`, `benchmarkQuery`,
`benchmarkQueryParallel`, and `benchmarkQueryWithConcurrentAdds` still use a
1-hour `EndsAt` margin while the real-time benchmarks elsewhere were widened to
24 hours. Update the `EndsAt` calculations in those benchmark setup blocks to
match the 24-hour buffer used by `benchmarkMutes`/`benchmarkMutesParallel`,
keeping the existing `now := time.Now()` pattern intact so
`QState(SilenceStateActive)` remains stable across long benchmark runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0fd80bec-27c6-4118-ac50-c6645df8d5ae

📥 Commits

Reviewing files that changed from the base of the PR and between 963ed72 and 9b1ad02.

📒 Files selected for processing (4)
  • silence/silence.go
  • silence/silence_bench_test.go
  • silence/silence_test.go
  • test/util.go

@ultrotter ultrotter changed the title [RFC/silence] Remove quartz/clock from silence [RFC] Remove quartz/clock from silence and nflog, and drop the dependency Jul 6, 2026
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.

Elimitate "quartz" and use normal golang time

2 participants