chore: implement phase 2 - #2780
Conversation
📊 API Diff Results
|
bbd2ebe to
799df17
Compare
| // skewHardLimit is one of §5's filled-in values (basis: §16; §22.11 asserts | ||
| // 120s errors, 30s does not). It belongs in schedule.go's named-constants | ||
| // block once P4 exists; defined here because P2 needs it first. | ||
| const skewHardLimit = 60 * time.Second |
There was a problem hiding this comment.
Clock skew is only ever needed to place the runner-defined window edges [from, to+grace] onto Grafana's own timeline, so it's a single-point reconciliation, not a factor in any duration-based check. The 60s hard limit is therefore a sanity gate, not a correction: skew is estimated as serverDate − (t_send+t_recv)/2 with error RTT/2, and that estimation is only trusted while the two clocks are in rough agreement. Past 60s the offset is treated as a broken or misconfigured clock, so the gate fails closed rather than align fine-grained window work against a clock it no longer trusts.
| // verified against (§2.7 control 2, §21.5): >= 13.0.0, < 14.0.0. | ||
| var ( | ||
| supportedGrafanaMin = grafanaVersion{13, 0, 0} | ||
| supportedGrafanaMax = grafanaVersion{14, 0, 0} // exclusive |
There was a problem hiding this comment.
better safe than sorry, we don't want to risk subtle behaviour changes.
4159c2f to
3894d9b
Compare
3894d9b to
96ebd78
Compare
96ebd78 to
be0dd37
Compare
There was a problem hiding this comment.
🟡 Changes recommended
It introduces unbounded response-body reads in the HTTP source and the “goroutine-safe” fake returns internal slices without defensive copies, both of which can lead to reliability/concurrency issues.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces the Phase 2 “Source” layer for the Grafana alert gate, including stricter transport vs hard-error classification, full end-to-end poll latency measurement, and concurrency-hardened test doubles.
Changes:
- Add a production
httpSourceimplementingSource, including Grafana version parsing/range enforcement, Date/skew validation, and retry-with-backoff for retryable transport failures. - Add comprehensive unit tests for skew/date-header hard failures, retry exhaustion semantics, and timing arithmetic (skew bound + full-body latency).
- Expand Prometheus duration parsing negative test coverage with additional invalid inputs.
File summaries
| File | Description |
|---|---|
| grafana-alertcheck/internal/gate/source.go | Adds Source + httpSource, request timing/skew logic, and transport retry/backoff behavior. |
| grafana-alertcheck/internal/gate/source_test.go | Adds end-to-end tests for version/state/definitions, retry behavior, and timing/skew calculations. |
| grafana-alertcheck/internal/gate/source_fake_test.go | Adds goroutine-safe fake clock(s) and scripted fake Source for higher-phase tests. |
| grafana-alertcheck/internal/gate/duration_test.go | Adds more invalid-duration inputs to strengthen parser error coverage. |
Review details
Suppressed comments (1)
grafana-alertcheck/internal/gate/source_fake_test.go:132
- RuleState returns next.obs (including obs.Rules) directly. Since the last scripted entry repeats, any caller mutation of the returned slice can leak into future calls and also create cross-goroutine races; copy the Rules slice before returning.
next := q[0]
if len(q) > 1 {
f.states[title] = q[1:]
}
return next.obs, next.err
}
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
be0dd37 to
6f29f79
Compare
Fix retry-error conflation, measure full poll latency, and harden Source test doubles for concurrency.
6f29f79 to
ba93502
Compare
Fixes retry-error conflation, measures full poll latency, and hardens the Source test doubles for concurrent use.
Review focus:
source.go(error vs retry classification, latency timing) andsource_fake_test.go(concurrency safety).