dbverify: attempts, landing-safe publish, no_assignment counts (#898)
Final fix wave, record and alert half. - no_assignment now counts toward the 3-run unverified alert (controller ruling on Astra P2-5); only not_reached and no_record hold the streak. - Verdict.AttemptedAt: a not_reached result is an attempt marker. Merge keeps the host's verdict and stamps the attempt, so the drill can put an abandoned host at the back of the next run (Fable P2-3). - PublishOver: inside each CAS attempt, drop hosts the caller knew that the record no longer has (removed by a landing move), so an overlapping run cannot resurrect them (Astra P2-4). Publish is PublishOver(nil). - metrics: a no_record host is never behind (Fable P2-2), and verify_coverage republishes its count when it changes (Astra P3). - alerting: storage_unavailable reason appended (value 11), with its copy record entry and pin; the text awaits Paul's approval.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
approved_member_backups_2a_copy_test.go+3 −0docs/superpowers/plans/member-backups-slice2a-copy.json+1 −0internal/alerting/alerting_test.go+6 −2internal/alerting/ruletext.go+1 −0internal/dbverify/dbverify.go+84 −20internal/dbverify/dbverify_test.go+131 −6internal/metrics/verify.go+14 −5internal/metrics/verify_test.go+19 −6
Intent
<task-notification> <task-id>a6db8b3211f158c85</task-id> <tool-use-id>toolu_01CHJZUAhYibyRFW9x6v2dAt</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/a6db8b3211f158c85.output</output-file> <status>completed</status> <summary>Agent "Implement slice 1 Task 5 (CLI)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE. The CLI golden file now has the two `instances backups` cases, and the commit is on member-backups-1 (not pushed). **Commit:** 5b0b481c "cli: golden cases for instances backups (#898)", on top of a055d094. **Re-record:** I used the `-record`/`-base` flags that `clireg_golden_test.go` defines, running `go test -count=1 . -run '^TestCLIGolden$' -record -base HEAD` with base a055d094. The diff adds exactly two lines, `instances backups | --zz-unknown-flag` and `instances backups | -h`, and changes no existing line. **Tests:** `go test . -run 'TestCLIGolden|TestCLIProjection'` passes. Both census tests (TestPlan14RootReadCensus and TestPlan9B8RecordWriteCensus) still pass. **Census:** unchanged. The golden file is test data and isn't covered by the census, so I didn't rerun census-propose. **Concerns:** none. Report (new "CI fix: TestCLIGolden" note): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups-1/.superpowers/sdd/2026-11-11-member-backups-slice1/task-5-report.md</result> <usage><subagent_tokens>221082</subagent_tokens><tool_uses>8</tool_uses><duration_ms>99247</duration_ms></usage> </task-notification>
<task-notification> <task-id>b4xebhv1x</task-id> <tool-use-id>toolu_01MPiLcZTWcjUrQxSv3irSgt</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/b4xebhv1x.output</output-file> <status>completed</status> <summary>Background command "Wait for slice 1 CI to finish" completed (exit code 0)</summary> </task-notification>
diff --git a/approved_member_backups_2a_copy_test.go b/approved_member_backups_2a_copy_test.go| index b6036afe1..287b4298c 100644 |
| --- a/approved_member_backups_2a_copy_test.go |
| +++ b/approved_member_backups_2a_copy_test.go |
| @@ -27,6 +27,9 @@ var memberBackups2aCopyIDs = []string{ |
| "verify.reason.nothing_replicated", "verify.reason.no_assignment", "verify.reason.restore_error", |
| "verify.reason.stale", "verify.reason.plan_moved", "verify.reason.record_unreadable", |
| "verify.reason.no_record", |
| + // The final fix wave (Fable P2-5): storage errors are unverified, not |
| + // failed. Pending Paul's approval of the text before merge. |
| + "verify.reason.storage_unavailable", |
| // The second review (approved-copy-2): the Rules section's lines. |
| "rules.when.verify_failed", "rules.th.verify_failed", |
| "rules.when.verify_unverified", "rules.th.verify_unverified", |
diff --git a/docs/superpowers/plans/member-backups-slice2a-copy.json b/docs/superpowers/plans/member-backups-slice2a-copy.json| index 85140680c..5fa87823b 100644 |
| --- a/docs/superpowers/plans/member-backups-slice2a-copy.json |
| +++ b/docs/superpowers/plans/member-backups-slice2a-copy.json |
| @@ -27,6 +27,7 @@ |
| {"id": "verify.reason.plan_moved", "file": "internal/alerting/ruletext.go", "text": "the copy was tidied up while the test was starting, on both tries"}, |
| {"id": "verify.reason.record_unreadable", "file": "internal/alerting/ruletext.go", "text": "the instance's details couldn't be read"}, |
| {"id": "verify.reason.no_record", "file": "internal/alerting/ruletext.go", "text": "there's no instance record for it"}, |
| + {"id": "verify.reason.storage_unavailable", "file": "internal/alerting/ruletext.go", "text": "the copy's storage couldn't be reached"}, |
| {"id": "rules.when.verify_failed", "file": "internal/console/alertpages.go", "text": "A nightly restore test of an instance's copy fails. Each instance is its own alert."}, |
| {"id": "rules.th.verify_failed", "file": "internal/console/alertpages.go", "text": "Fixed at one failed test. Not configurable."}, |
| {"id": "rules.when.verify_unverified", "file": "internal/console/alertpages.go", "text": "A restore test can't run for an instance three nights in a row. Each instance is its own alert."}, |
diff --git a/internal/alerting/alerting_test.go b/internal/alerting/alerting_test.go| index 11a08d5c4..dfca8311d 100644 |
| --- a/internal/alerting/alerting_test.go |
| +++ b/internal/alerting/alerting_test.go |
| @@ -416,8 +416,12 @@ func TestVerifyReasonValuesRoundTrip(t *testing.T) { |
| t.Errorf("%s: label %q %v", r.Code, l, ok) |
| } |
| } |
| - if len(VerifyReasons) != 10 { |
| - t.Errorf("%d reasons, want the 10 approved", len(VerifyReasons)) |
| + if len(VerifyReasons) != 11 { |
| + t.Errorf("%d reasons, want the 11 in the copy record", len(VerifyReasons)) |
| + } |
| + // Append only: a console reads the number a box of any version wrote. |
| + if v := VerifyReasonValue("storage_unavailable"); v != 11 { |
| + t.Errorf("storage_unavailable = %v, want 11, after every earlier reason", v) |
| } |
| if v := VerifyReasonValue("no_such_reason"); v != 0 { |
| t.Errorf("unknown code = %v, want 0", v) |
diff --git a/internal/alerting/ruletext.go b/internal/alerting/ruletext.go| index d169a7639..76f7ef2d8 100644 |
| --- a/internal/alerting/ruletext.go |
| +++ b/internal/alerting/ruletext.go |
| @@ -111,6 +111,7 @@ var VerifyReasons = []VerifyReason{ |
| {"plan_moved", "the copy was tidied up while the test was starting, on both tries"}, |
| {"record_unreadable", "the instance's details couldn't be read"}, |
| {"no_record", "there's no instance record for it"}, |
| + {"storage_unavailable", "the copy's storage couldn't be reached"}, |
| } |
| // VerifyReasonValue is code's alert value, 0 for a code VerifyReasons does |
diff --git a/internal/dbverify/dbverify.go b/internal/dbverify/dbverify.go| index 7ff0d9917..84ce3d015 100644 |
| --- a/internal/dbverify/dbverify.go |
| +++ b/internal/dbverify/dbverify.go |
| @@ -21,6 +21,7 @@ import ( |
| "fmt" |
| "os" |
| "path/filepath" |
| + "sort" |
| "time" |
| "github.com/carlosframework/platform/internal/boxself" |
| @@ -76,11 +77,15 @@ const ( |
| ) |
| // ReasonNotReached is an unverified verdict for a host the run did not |
| -// get to, or abandoned when it ran out of time; ReasonNoAssignment is one |
| -// for a group box's host that no usable assignment gave this box; |
| -// ReasonNoRecord is one for a host with no instance record when the test |
| -// began, so there was no instance to bind a test to. None of them learned |
| -// anything about the replica, so none moves UnverifiedRuns. |
| +// get to, or abandoned when it ran out of time; ReasonNoRecord is one for a |
| +// host with no record of any family when the test began, so there was no |
| +// instance to bind a test to. Neither learned anything about the replica, |
| +// so neither moves UnverifiedRuns. |
| +// |
| +// ReasonNoAssignment is one for a group box's host that no usable |
| +// assignment gave this box. It is an operational fault (a stopped agent or |
| +// a broken serving view), not budget exhaustion, so it counts toward |
| +// UnverifiedRuns like the drill's own reasons. |
| const ( |
| ReasonNotReached = "not_reached" |
| ReasonNoAssignment = "no_assignment" |
| @@ -119,6 +124,13 @@ type Verdict struct { |
| // VerifiedAt is when this verdict was reached, NOT when the replica |
| // was written. An old timestamp on a pass is itself a finding. |
| VerifiedAt time.Time `json:"verified_at,omitzero"` |
| + // AttemptedAt is when a run last started this host and abandoned it |
| + // (cut by the deadline or stopped) without a verdict. Merge keeps the |
| + // verdict the host had and stamps the attempt on it; the next decided |
| + // verdict clears it. The drill orders by the later of the two times, |
| + // so a host that cannot finish goes to the back of the next run rather |
| + // than taking every run's whole budget. |
| + AttemptedAt time.Time `json:"attempted_at,omitzero"` |
| // TXID and WrittenAt are the restored transaction and its header |
| // time; RestoredBytes is the restored database's size. |
| TXID uint64 `json:"txid,omitempty"` |
| @@ -134,8 +146,8 @@ type Verdict struct { |
| // The bookkeeping Merge keeps, whatever the caller set. |
| // |
| // UnverifiedRuns is how many runs in a row ended unverified, not |
| - // counting not_reached, no_assignment or no_record runs, which leave |
| - // it as it was; passed or failed sets it to 0. |
| + // counting not_reached or no_record runs, which leave it as it was; |
| + // passed or failed sets it to 0. |
| UnverifiedRuns int `json:"unverified_runs"` |
| // FirstSeen is the first run that counted this host, for this |
| // identity. |
| @@ -177,8 +189,13 @@ type Record struct { |
| // For each result, Merge keeps the host's bookkeeping: FirstSeen carries |
| // over, LastDecidedAt advances only on passed or failed, and |
| // UnverifiedRuns counts unverified runs in a row: passed or failed resets |
| -// it, not_reached, no_assignment and no_record hold it, any other reason |
| -// adds one. |
| +// it, not_reached and no_record hold it, any other reason (no_assignment |
| +// included) adds one. |
| +// |
| +// A not_reached result is an attempt, not a verdict: the run started the |
| +// host and abandoned it. The host keeps the verdict it had (or is added |
| +// not_reached, first seen now) with the result's AttemptedAt stamped on |
| +// it, now when the result has none. |
| // A result about a different identity than the prior verdict starts all |
| // three over. A result with no identity (zero) keeps the prior verdict's |
| // last known one; a prior with none is never "different". |
| @@ -193,6 +210,16 @@ func Merge(prior *Record, ref string, now time.Time, fleet []string, results map |
| } |
| r, visited := results[host] |
| switch { |
| + case visited && r.Result == ResultUnverified && r.Reason == ReasonNotReached: |
| + v := p |
| + if !had { |
| + v = Verdict{Result: ResultUnverified, Reason: ReasonNotReached, FirstSeen: now} |
| + } |
| + v.AttemptedAt = r.AttemptedAt.UTC() |
| + if r.AttemptedAt.IsZero() { |
| + v.AttemptedAt = now |
| + } |
| + rec.Hosts[host] = v |
| case visited: |
| rec.Hosts[host] = mergeOne(p, had, r, now) |
| case had: |
| @@ -223,6 +250,7 @@ func mergeOne(p Verdict, had bool, r Verdict, now time.Time) Verdict { |
| } |
| r.LastDecidedAt = p.LastDecidedAt |
| r.UnverifiedRuns = 0 |
| + r.AttemptedAt = time.Time{} |
| switch r.Result { |
| case ResultPassed, ResultFailed: |
| r.LastDecidedAt = r.VerifiedAt |
| @@ -230,7 +258,7 @@ func mergeOne(p Verdict, had bool, r Verdict, now time.Time) Verdict { |
| r.LastDecidedAt = now |
| } |
| case ResultUnverified: |
| - if r.Reason == ReasonNotReached || r.Reason == ReasonNoAssignment || r.Reason == ReasonNoRecord { |
| + if r.Reason == ReasonNotReached || r.Reason == ReasonNoRecord { |
| r.UnverifiedRuns = p.UnverifiedRuns // held: nothing was tried |
| } else { |
| r.UnverifiedRuns = p.UnverifiedRuns + 1 |
| @@ -332,27 +360,63 @@ func RemoveHost(ctx context.Context, s release.Store, ref, host string) error { |
| // record and nothing else. Three attempts on a lost CAS race, the recipe |
| // usage.UpsertEdgeDay and host.putReplacing both use. |
| func Publish(ctx context.Context, s release.Store, rec *Record) error { |
| + _, err := PublishOver(ctx, s, rec, nil) |
| + return err |
| +} |
| + |
| +// PublishOver is Publish for a writer whose rec was built from an earlier |
| +// read of the record: known is the hosts that read held. Inside each CAS |
| +// attempt it reads the record now in the bucket, and every host in known |
| +// that the record no longer has was removed by someone else since (a |
| +// landing move's RemoveHost, the record's only other writer): it is |
| +// deleted from rec, so the publish does not put it back, and returned in |
| +// dropped. Hosts not in known are rec's own news and are kept. A record |
| +// that is missing or does not parse tells nothing about removals: rec is |
| +// published as it is, as Publish always did. |
| +func PublishOver(ctx context.Context, s release.Store, rec *Record, known map[string]bool) (dropped []string, err error) { |
| key := KeyFor(rec.Box) |
| if key == "" { |
| - return fmt.Errorf("%w: %q", ErrInvalidRef, rec.Box) |
| - } |
| - body, err := json.Marshal(rec) |
| - if err != nil { |
| - return err |
| + return nil, fmt.Errorf("%w: %q", ErrInvalidRef, rec.Box) |
| } |
| for attempt := 0; attempt < 3; attempt++ { |
| - _, etag, err := s.Get(ctx, key) |
| + cur, etag, err := s.Get(ctx, key) |
| switch { |
| case errors.Is(err, os.ErrNotExist): |
| etag = "" |
| case err != nil: |
| - return fmt.Errorf("get %s: %w", key, err) |
| + return dropped, fmt.Errorf("get %s: %w", key, err) |
| + case len(known) > 0: |
| + var now Record |
| + if json.Unmarshal(cur, &now) == nil { |
| + for _, h := range sortedHosts(known) { |
| + if _, still := now.Hosts[h]; still { |
| + continue |
| + } |
| + if _, ok := rec.Hosts[h]; ok { |
| + delete(rec.Hosts, h) |
| + dropped = append(dropped, h) |
| + } |
| + } |
| + } |
| + } |
| + body, err := json.Marshal(rec) |
| + if err != nil { |
| + return dropped, err |
| } |
| if _, err := s.Put(ctx, key, body, etag); err == nil { |
| - return nil |
| + return dropped, nil |
| } else if !errors.Is(err, release.ErrCASConflict) { |
| - return fmt.Errorf("put %s: %w", key, err) |
| + return dropped, fmt.Errorf("put %s: %w", key, err) |
| } |
| } |
| - return fmt.Errorf("put %s: lost three CAS races", key) |
| + return dropped, fmt.Errorf("put %s: lost three CAS races", key) |
| +} |
| + |
| +func sortedHosts(set map[string]bool) []string { |
| + out := make([]string, 0, len(set)) |
| + for h := range set { |
| + out = append(out, h) |
| + } |
| + sort.Strings(out) |
| + return out |
| } |
diff --git a/internal/dbverify/dbverify_test.go b/internal/dbverify/dbverify_test.go| index fcf0c9621..5caf92150 100644 |
| --- a/internal/dbverify/dbverify_test.go |
| +++ b/internal/dbverify/dbverify_test.go |
| @@ -129,8 +129,9 @@ func TestMergeAddsNeverSeenFleetHostsAsNotReached(t *testing.T) { |
| } |
| } |
| -// The streak counts runs that tried and could not decide; a decision or a |
| -// run that never reached the host ends it. |
| +// The streak counts runs that tried and could not decide; a decision ends |
| +// it, and a run that never tried (not_reached, no_record) holds it, as |
| +// TestMergeNotReachedHoldsTheStreak shows. |
| func TestMergeUnverifiedRuns(t *testing.T) { |
| fleet := []string{"a.example.com"} |
| day := at("2026-08-01T03:00:00Z") |
| @@ -154,11 +155,11 @@ func TestMergeUnverifiedRuns(t *testing.T) { |
| } |
| } |
| -// A run that never reached the host (not_reached, no_assignment on a group |
| -// box, or no_record for a host with no instance record to bind a test to) |
| -// learned nothing: it neither adds to the streak nor ends it. |
| +// A run that never reached the host (not_reached, or no_record for a host |
| +// with no record of any family to bind a test to) learned nothing: it |
| +// neither adds to the streak nor ends it. |
| func TestMergeNotReachedHoldsTheStreak(t *testing.T) { |
| - for _, reason := range []string{ReasonNotReached, ReasonNoAssignment, ReasonNoRecord} { |
| + for _, reason := range []string{ReasonNotReached, ReasonNoRecord} { |
| fleet := []string{"a.example.com"} |
| day := at("2026-08-01T03:00:00Z") |
| var rec *Record |
| @@ -187,6 +188,57 @@ func TestMergeNotReachedHoldsTheStreak(t *testing.T) { |
| } |
| } |
| +// A group box's host that no usable assignment gave a box is an |
| +// operational fault, not budget exhaustion: three such nights in a row |
| +// raise the unverified alert like any other reason (controller ruling on |
| +// Astra's P2-5). |
| +func TestMergeNoAssignmentCounts(t *testing.T) { |
| + fleet := []string{"a.example.com"} |
| + day := at("2026-08-01T03:00:00Z") |
| + var rec *Record |
| + for i := 1; i <= 3; i++ { |
| + rec = Merge(rec, "box-a", day, fleet, map[string]Verdict{"a.example.com": unverified(Identity{}, ReasonNoAssignment, day)}) |
| + day = day.Add(24 * time.Hour) |
| + if got := rec.Hosts["a.example.com"].UnverifiedRuns; got != i { |
| + t.Fatalf("after %d no_assignment nights UnverifiedRuns = %d, want %d", i, got, i) |
| + } |
| + } |
| +} |
| + |
| +// A host the run started and abandoned (cut by the deadline, or stopped) |
| +// learned nothing, so it keeps the verdict it had, streak and all; but it |
| +// carries the attempt's time, so the next run does not start with it |
| +// again (Fable P2-3). A host with no verdict yet is not_reached, attempted. |
| +// The next decided verdict carries no attempt of its own. |
| +func TestMergeAttemptKeepsTheVerdictAndStampsIt(t *testing.T) { |
| + fleet := []string{"a.example.com", "new.example.com"} |
| + first := at("2026-08-01T03:00:00Z") |
| + rec := Merge(nil, "box-a", first, fleet[:1], map[string]Verdict{"a.example.com": passed(idA, first)}) |
| + was := rec.Hosts["a.example.com"] |
| + night := first.Add(24 * time.Hour) |
| + tried := night.Add(20 * time.Minute) |
| + attempt := Verdict{Result: ResultUnverified, Reason: ReasonNotReached, AttemptedAt: tried} |
| + rec = Merge(rec, "box-a", night, fleet, map[string]Verdict{"a.example.com": attempt, "new.example.com": attempt}) |
| + got := rec.Hosts["a.example.com"] |
| + want := was |
| + want.AttemptedAt = tried |
| + if got != want { |
| + t.Fatalf("an attempted host\n got %+v\nwant %+v", got, want) |
| + } |
| + if v := rec.Hosts["new.example.com"]; v.Result != ResultUnverified || v.Reason != ReasonNotReached || |
| + !v.AttemptedAt.Equal(tried) || !v.FirstSeen.Equal(night) || v.UnverifiedRuns != 0 { |
| + t.Fatalf("an attempted host with no verdict: %+v", v) |
| + } |
| + next := night.Add(24 * time.Hour) |
| + rec = Merge(rec, "box-a", next, fleet, map[string]Verdict{"a.example.com": passed(idA, next)}) |
| + if v := rec.Hosts["a.example.com"]; !v.AttemptedAt.IsZero() || !v.VerifiedAt.Equal(next) { |
| + t.Fatalf("a decided verdict after an attempt: %+v", v) |
| + } |
| + if v := rec.Hosts["new.example.com"]; !v.AttemptedAt.Equal(tried) { |
| + t.Fatalf("an untouched host lost its attempt: %+v", v) |
| + } |
| +} |
| + |
| // LastDecidedAt is the last time a restore was decided, passed or failed. |
| // Undecided nights leave it where it was, which is what lets coverage |
| // alert on a host that has been unverified for a week. |
| @@ -521,6 +573,79 @@ func TestRemoveHostOwnRecordOnly(t *testing.T) { |
| } |
| } |
| +// PublishOver drops what someone else removed since the caller last saw |
| +// the record: a host in known that the record in the bucket no longer has |
| +// was removed by a landing move (RemoveHost), and a publish built from an |
| +// older record must not put it back (Astra P2-4). The check runs inside |
| +// each CAS attempt, so a removal between the read and the write is seen on |
| +// the retry. Hosts the caller did not know about are kept: they are its |
| +// own news. |
| +func TestPublishOverKeepsRemovals(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + now := at("2026-10-07T09:00:00Z") |
| + start := Merge(nil, "box-a", now, []string{"a.example.com", "b.example.com"}, map[string]Verdict{ |
| + "a.example.com": passed(idA, now), "b.example.com": passed(Identity{}, now), |
| + }) |
| + if err := Publish(ctx, s, start); err != nil { |
| + t.Fatal(err) |
| + } |
| + known := map[string]bool{"a.example.com": true, "b.example.com": true} |
| + |
| + // The landing removes a.example.com between this publish's read and |
| + // its write: the put loses the CAS, rereads, and leaves a out. |
| + raced := false |
| + racing := releaseStoreFunc{Store: s, beforePut: func() { |
| + if raced { |
| + return |
| + } |
| + raced = true |
| + if err := RemoveHost(ctx, s, "box-a", "a.example.com"); err != nil { |
| + t.Fatal(err) |
| + } |
| + }} |
| + later := now.Add(10 * time.Minute) |
| + rec := Merge(start, "box-a", later, []string{"a.example.com", "b.example.com", "c.example.com"}, map[string]Verdict{ |
| + "a.example.com": passed(idA, later), "c.example.com": passed(Identity{}, later), |
| + }) |
| + dropped, err := PublishOver(ctx, racing, rec, known) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !raced { |
| + t.Fatal("the race was never run") |
| + } |
| + if !slices.Equal(dropped, []string{"a.example.com"}) { |
| + t.Fatalf("dropped %v, want the removed host", dropped) |
| + } |
| + got, err := Load(ctx, s, "box-a") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if want := []string{"b.example.com", "c.example.com"}; !slices.Equal(sortedKeys(got.Hosts), want) { |
| + t.Fatalf("published %v, want %v", sortedKeys(got.Hosts), want) |
| + } |
| + if _, ok := rec.Hosts["a.example.com"]; ok { |
| + t.Fatal("the caller's record still carries the removed host") |
| + } |
| + |
| + // With no record at all there is nothing anyone removed. |
| + empty := release.NewDirStore(t.TempDir()) |
| + dropped, err = PublishOver(ctx, empty, Merge(nil, "box-a", now, []string{"a.example.com"}, nil), known) |
| + if err != nil || len(dropped) != 0 { |
| + t.Fatalf("over no record: dropped %v, %v", dropped, err) |
| + } |
| +} |
| + |
| +func sortedKeys(m map[string]Verdict) []string { |
| + out := make([]string, 0, len(m)) |
| + for k := range m { |
| + out = append(out, k) |
| + } |
| + slices.Sort(out) |
| + return out |
| +} |
| + |
| // releaseStoreFunc is a release.Store whose Put first runs beforePut. |
| type releaseStoreFunc struct { |
| release.Store |
diff --git a/internal/metrics/verify.go b/internal/metrics/verify.go| index b3c931e86..57d217225 100644 |
| --- a/internal/metrics/verify.go |
| +++ b/internal/metrics/verify.go |
| @@ -24,12 +24,14 @@ const ( |
| // VerifyUnverifiedRuns is how many unverified runs in a row fire a host's |
| // verify_unverified rule. The record's streak already leaves out the runs |
| -// that tried nothing (not_reached, no_assignment, no_record). |
| +// that tried nothing (not_reached, no_record). |
| const VerifyUnverifiedRuns = 3 |
| // VerifyBehindAfter is how old a host's last decided verdict (passed or |
| // failed), or its first sighting if it has none, may be before the box's |
| -// verify_coverage rule fires. |
| +// verify_coverage rule fires. A host whose latest verdict is no_record is |
| +// never behind: with no record of any family to bind a test to, it can |
| +// never be decided, so counting it would keep the rule up for good. |
| const VerifyBehindAfter = 7 * 24 * time.Hour |
| // VerifyReading is one box's restore drill standing as the alert rules read |
| @@ -46,7 +48,8 @@ type VerifyReading struct { |
| // streak (dbverify.Verdict.UnverifiedRuns) and its latest reason code. |
| UnverifiedStreak map[string]int |
| UnverifiedReason map[string]string |
| - // Behind is the hosts past VerifyBehindAfter, sorted. |
| + // Behind is the hosts past VerifyBehindAfter, sorted, never a no_record |
| + // one. |
| Behind []string |
| } |
| @@ -86,7 +89,8 @@ func ReadVerify(path string, now time.Time) (*VerifyReading, error) { |
| if since.IsZero() { |
| since = vd.FirstSeen |
| } |
| - if !since.IsZero() && now.Sub(since) > VerifyBehindAfter { |
| + undecidable := vd.Unverified() && vd.Reason == dbverify.ReasonNoRecord |
| + if !undecidable && !since.IsZero() && now.Sub(since) > VerifyBehindAfter { |
| v.Behind = append(v.Behind, host) |
| } |
| } |
| @@ -109,7 +113,8 @@ func ReadVerify(path string, now time.Time) (*VerifyReading, error) { |
| // reason that changes while it fires is a firing event with the new value, |
| // as geoip's is: an event is what publishes the state, so without it the |
| // console would go on naming the old reason. verify_coverage fires while any |
| -// host is behind, its value how many. |
| +// host is behind, its value how many; a count that changes while it fires |
| +// is a firing event with the new count, for the same reason. |
| func evalVerify(rules map[string]RuleState, v *VerifyReading, at time.Time, box string) []Event { |
| present := map[string]bool{} |
| for _, h := range v.Hosts { |
| @@ -163,6 +168,10 @@ func evalVerify(rules map[string]RuleState, v *VerifyReading, at time.Time, box |
| case behind > 0 && !cur.Firing: |
| rules[verifyCoverageRule] = RuleState{Firing: true, Since: at, FiredAt: at, Value: float64(behind)} |
| changed = append(changed, Event{Rule: verifyCoverageRule, Firing: true, Value: float64(behind), Box: box}) |
| + case behind > 0 && cur.Value != float64(behind): |
| + cur.Value = float64(behind) |
| + rules[verifyCoverageRule] = cur |
| + changed = append(changed, Event{Rule: verifyCoverageRule, Firing: true, Value: float64(behind), Box: box}) |
| case behind == 0 && cur.Firing: |
| rules[verifyCoverageRule] = RuleState{} |
| changed = append(changed, Event{Rule: verifyCoverageRule, Firing: false, Box: box}) |
diff --git a/internal/metrics/verify_test.go b/internal/metrics/verify_test.go| index 42a70617a..1b4d41171 100644 |
| --- a/internal/metrics/verify_test.go |
| +++ b/internal/metrics/verify_test.go |
| @@ -133,10 +133,19 @@ func TestEvaluateVerifyCoverage(t *testing.T) { |
| if len(ev) != 1 || ev[0] != (Event{Rule: "verify_coverage", Firing: true, Value: 2, Box: "b"}) { |
| t.Fatalf("behind: %+v", ev) |
| } |
| + // The count follows the hosts behind while it fires (Astra P3): the |
| + // alert stays up, and the event publishes the new number. |
| st, ev = Evaluate(r, st, Observation{At: t0.Add(time.Hour), Verify: &VerifyReading{Box: "b", Hosts: []string{"a", "c"}, Behind: []string{"c"}}}) |
| - if len(ev) != 0 || !st.Rules["verify_coverage"].Firing { |
| + if len(ev) != 1 || ev[0] != (Event{Rule: "verify_coverage", Firing: true, Value: 1, Box: "b"}) || !st.Rules["verify_coverage"].Firing { |
| t.Fatalf("one host still behind: %v %+v", ev, st.Rules) |
| } |
| + if rs := st.Rules["verify_coverage"]; rs.Value != 1 || !rs.FiredAt.Equal(t0) { |
| + t.Fatalf("a recount moved the firing itself: %+v", rs) |
| + } |
| + st, ev = Evaluate(r, st, Observation{At: t0.Add(90 * time.Minute), Verify: &VerifyReading{Box: "b", Hosts: []string{"a", "c"}, Behind: []string{"c"}}}) |
| + if len(ev) != 0 { |
| + t.Fatalf("an unchanged count: %+v", ev) |
| + } |
| st, ev = Evaluate(r, st, Observation{At: t0.Add(2 * time.Hour)}) |
| if len(ev) != 0 || !st.Rules["verify_coverage"].Firing { |
| t.Fatalf("a nil reading changed the rule: %v", ev) |
| @@ -151,7 +160,7 @@ func TestEvaluateVerifyCoverage(t *testing.T) { |
| } |
| // The streak comes from the record as dbverify.Merge keeps it: not_reached |
| -// (and no_assignment, no_record) runs hold it, so a host the run never |
| +// (and no_record) runs hold it, so a host the run never |
| // reaches never fires verify_unverified, however many nights it goes on; |
| // only runs that tried and could not decide count. |
| func TestEvaluateVerifyNotReachedNeverCounts(t *testing.T) { |
| @@ -170,7 +179,7 @@ func TestEvaluateVerifyNotReachedNeverCounts(t *testing.T) { |
| st, ev = Evaluate(r, st, Observation{At: at, Verify: writeVerify(t, rec, at)}) |
| return ev |
| } |
| - for i, reason := range []string{"plan_moved", dbverify.ReasonNotReached, "plan_moved", dbverify.ReasonNoAssignment, dbverify.ReasonNotReached} { |
| + for i, reason := range []string{"plan_moved", dbverify.ReasonNotReached, "plan_moved", dbverify.ReasonNoRecord, dbverify.ReasonNotReached} { |
| if ev := night(i, reason); len(ev) != 0 { |
| t.Fatalf("night %d (%s): %+v, want nothing (flaky's streak is 2 at most)", i, reason, ev) |
| } |
| @@ -200,16 +209,20 @@ func TestReadVerifyBehind(t *testing.T) { |
| "new-never": {Result: dbverify.ResultUnverified, Reason: dbverify.ReasonNotReached, FirstSeen: now.Add(-week)}, |
| "old-never": {Result: dbverify.ResultUnverified, Reason: "moving", FirstSeen: now.Add(-week - time.Hour), UnverifiedRuns: 4}, |
| "failed-host": {Result: dbverify.ResultFailed, Reason: "restore_error", LastDecidedAt: now, FirstSeen: now}, |
| + // No record of any family: it can never be decided, so it is never |
| + // behind (Fable P2-2), however old. |
| + "orphan": {Result: dbverify.ResultUnverified, Reason: dbverify.ReasonNoRecord, FirstSeen: now.Add(-30 * week), |
| + LastDecidedAt: now.Add(-20 * week)}, |
| // A result this version does not know is never read as fine. |
| "odd-host": {Result: "exploded", LastDecidedAt: now, FirstSeen: now}, |
| }} |
| v := writeVerify(t, rec, now) |
| want := &VerifyReading{ |
| Box: "b", |
| - Hosts: []string{"at-boundary", "failed-host", "held", "new-never", "odd-host", "old-never", "past-boundary"}, |
| + Hosts: []string{"at-boundary", "failed-host", "held", "new-never", "odd-host", "old-never", "orphan", "past-boundary"}, |
| Failed: []string{"failed-host", "odd-host"}, |
| - UnverifiedStreak: map[string]int{"held": 1, "new-never": 0, "old-never": 4}, |
| - UnverifiedReason: map[string]string{"held": "not_reached", "new-never": "not_reached", "old-never": "moving"}, |
| + UnverifiedStreak: map[string]int{"held": 1, "new-never": 0, "old-never": 4, "orphan": 0}, |
| + UnverifiedReason: map[string]string{"held": "not_reached", "new-never": "not_reached", "old-never": "moving", "orphan": "no_record"}, |
| Behind: []string{"held", "old-never", "past-boundary"}, |
| } |
| if !reflect.DeepEqual(v, want) { |