Skip to content

chore: implement phase 2 - #2780

Open
Tofel wants to merge 3 commits into
dx-5122-alerts-assertion-p1from
dx-5122-alerts-assertion-p2
Open

chore: implement phase 2#2780
Tofel wants to merge 3 commits into
dx-5122-alerts-assertion-p1from
dx-5122-alerts-assertion-p2

Conversation

@Tofel

@Tofel Tofel commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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) and source_fake_test.go (concurrency safety).

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-testing-framework/grafana-alertcheck

View full report

@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p2 branch from bbd2ebe to 799df17 Compare September 1, 2026 11:25
// 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@Tofel Tofel Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

better safe than sorry, we don't want to risk subtle behaviour changes.

@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p2 branch from 4159c2f to 3894d9b Compare September 2, 2026 09:45
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p2 branch from 3894d9b to 96ebd78 Compare September 4, 2026 15:03
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p2 branch from 96ebd78 to be0dd37 Compare September 7, 2026 09:35
@Tofel
Tofel marked this pull request as ready for review September 7, 2026 09:36
@Tofel
Tofel requested a review from a team as a code owner September 7, 2026 09:36
Copilot AI lite review requested due to automatic review settings September 7, 2026 09:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 httpSource implementing Source, 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.

Comment thread grafana-alertcheck/internal/gate/source.go Outdated
Comment thread grafana-alertcheck/internal/gate/source_fake_test.go
Comment thread grafana-alertcheck/internal/gate/source.go
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p2 branch from be0dd37 to 6f29f79 Compare September 7, 2026 09:46
Fix retry-error conflation, measure full poll latency, and harden Source test doubles for concurrency.
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p2 branch from 6f29f79 to ba93502 Compare September 7, 2026 15:02
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.

2 participants