diff --git a/SETUP.rst b/SETUP.rst index 1e591ee6..6fdf5384 100644 --- a/SETUP.rst +++ b/SETUP.rst @@ -378,7 +378,9 @@ without becoming an outage: for how long in the last hour, day, week and month, every hour of the last 30 days in which it was unavailable, and every period of the last 90 days with its reason. The bot only notices while it runs, so the times are as precise as its polling -cycles. +cycles. For Patchwork, the windows also show the share of the bot's +requests that worked, retries included, which tells how it felt to use +it even when the bot got through. The bot cannot notice that it does not run itself, for example when GitHub disables Actions on the bot repository. The pages warn when diff --git a/cmd/leadtest/main.go b/cmd/leadtest/main.go index 4b4ed84d..e347a015 100644 --- a/cmd/leadtest/main.go +++ b/cmd/leadtest/main.go @@ -342,6 +342,9 @@ func buildPipeline(cfg *config.Config, st *state.Store, workDir string, Token: cfg.Secrets.PatchworkToken, MinDelay: cfg.Patchwork.MinDelay.D(), Logger: log, + OnTry: func(failed bool) { + st.Availability.CountPatchworkTry(failed, time.Now()) + }, }) if err != nil { return nil, err diff --git a/internal/httpx/client.go b/internal/httpx/client.go index 265425b4..dbe4e355 100644 --- a/internal/httpx/client.go +++ b/internal/httpx/client.go @@ -83,6 +83,13 @@ type Options struct { HTTPClient *http.Client Logger *slog.Logger Sleep func(ctx context.Context, d time.Duration) error + + // OnTry, when set, is called after each try of a request. A try + // fails on a network error, a timeout or a transient status: 5xx, + // 429 or a rate-limited 403. Other statuses, 404 included, are the + // bot's mistake and count as working. Tries ended by the context + // or by bot protection are not reported. + OnTry func(failed bool) } type Client struct { @@ -259,6 +266,9 @@ func (c *Client) Do(ctx context.Context, r Request) (*Response, error) { if ctx.Err() != nil { return nil, ctx.Err() } + if c.opts.OnTry != nil && !errors.Is(err, ErrBotProtection) { + c.opts.OnTry(err != nil || isTransientStatus(resp)) + } var retryAfter time.Duration retry := false switch { diff --git a/internal/httpx/ontry_test.go b/internal/httpx/ontry_test.go new file mode 100644 index 00000000..00d7b8a6 --- /dev/null +++ b/internal/httpx/ontry_test.go @@ -0,0 +1,130 @@ +// Copyright 2026 LeadTestKit Authors +// SPDX-License-Identifier: Apache-2.0 + +package httpx + +import ( + "context" + "net/http" + "reflect" + "sync" + "sync/atomic" + "testing" +) + +// tryRecorder records the tries a client reports. +type tryRecorder struct { + mu sync.Mutex + tries []bool +} + +func (r *tryRecorder) onTry(failed bool) { + r.mu.Lock() + r.tries = append(r.tries, failed) + r.mu.Unlock() +} + +func (r *tryRecorder) check(t *testing.T, want ...bool) { + t.Helper() + r.mu.Lock() + defer r.mu.Unlock() + if len(want) == 0 && len(r.tries) == 0 { + return + } + if !reflect.DeepEqual(r.tries, want) { + t.Fatalf("tries = %v, want %v", r.tries, want) + } +} + +// statuses answers with the given status codes in turn, then 200. +func statuses(codes ...int) http.HandlerFunc { + var n atomic.Int32 + return func(w http.ResponseWriter, r *http.Request) { + if i := int(n.Add(1)) - 1; i < len(codes) { + w.WriteHeader(codes[i]) + return + } + w.Write([]byte(`{}`)) + } +} + +func TestOnTryTransientThenSuccess(t *testing.T) { + var rec tryRecorder + c, srv := testClient(t, statuses(502, 502), Options{Attempts: 3, OnTry: rec.onTry}) + if _, err := c.Get(context.Background(), srv.URL); err != nil { + t.Fatal(err) + } + rec.check(t, true, true, false) +} + +func TestOnTryClientErrors(t *testing.T) { + for _, tc := range []struct { + name string + codes []int + retry int + want []bool + }{ + {"404", []int{404}, 0, []bool{false}}, + {"400", []int{400}, 0, []bool{false}}, + {"404 retried", []int{404}, 1, []bool{false, false}}, + } { + t.Run(tc.name, func(t *testing.T) { + var rec tryRecorder + c, srv := testClient(t, statuses(tc.codes...), Options{OnTry: rec.onTry}) + c.Do(context.Background(), Request{URL: srv.URL, NotFoundRetries: tc.retry}) + rec.check(t, tc.want...) + }) + } +} + +func TestOnTryNetworkError(t *testing.T) { + var rec tryRecorder + c, srv := testClient(t, statuses(), Options{Attempts: 2, OnTry: rec.onTry}) + srv.Close() + if _, err := c.Get(context.Background(), srv.URL); err == nil { + t.Fatal("no error from a closed server") + } + rec.check(t, true, true) +} + +func TestOnTryCanceled(t *testing.T) { + var rec tryRecorder + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + c, srv := testClient(t, func(w http.ResponseWriter, r *http.Request) { + cancel() + w.WriteHeader(502) + }, Options{OnTry: rec.onTry}) + c.Get(ctx, srv.URL) + rec.check(t) +} + +func TestOnTryBotProtection(t *testing.T) { + if !curlAvailable() { + t.Skip("curl not installed") + } + var rec tryRecorder + c, srv := testClient(t, func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html") + w.Write([]byte(`
`)) + }, Options{CurlFirst: true, Attempts: 2, OnTry: rec.onTry}) + c.Get(context.Background(), srv.URL) + rec.check(t) +} + +func TestOnTryRateLimited(t *testing.T) { + var rec tryRecorder + var n atomic.Int32 + c, srv := testClient(t, func(w http.ResponseWriter, r *http.Request) { + if n.Add(1) == 1 { + w.Header().Set("X-RateLimit-Remaining", "0") + w.WriteHeader(403) + return + } + w.Write([]byte(`{}`)) + }, Options{OnTry: rec.onTry}) + if _, err := c.Get(context.Background(), srv.URL); err != nil { + t.Fatal(err) + } + rec.check(t, true, false) +} diff --git a/internal/pages/pages_test.go b/internal/pages/pages_test.go index 47bf7d8b..6311cc9a 100644 --- a/internal/pages/pages_test.go +++ b/internal/pages/pages_test.go @@ -59,6 +59,7 @@ func TestRender(t *testing.T) { st.Meta.Outages = map[string]*state.Outage{state.OutageRuns: { Since: state.FormatTime(now), Reason: "no workflow run started"}} st.Availability.Unavailable(state.ServicePatchwork, "lorem", now) + st.Availability.CountPatchworkTry(true, now) if err := st.Save(); err != nil { t.Fatal(err) } @@ -97,7 +98,8 @@ func TestRender(t *testing.T) { var avail state.Availability b, _ = os.ReadFile(filepath.Join(out, "data", "availability.json")) if err := json.Unmarshal(b, &avail); err != nil || - avail.Failing[state.ServicePatchwork].Reason != "lorem" { + avail.Failing[state.ServicePatchwork].Reason != "lorem" || + len(avail.PatchworkHourlyTries) != 1 || avail.PatchworkHourlyTries[0].Failed != 1 { t.Errorf("availability = %s, %v", b, err) } b, err = os.ReadFile(filepath.Join(out, "data", "history", "2026-03.json")) diff --git a/internal/pages/site/app.js b/internal/pages/site/app.js index 23f8cdd4..18510b0e 100644 --- a/internal/pages/site/app.js +++ b/internal/pages/site/app.js @@ -589,6 +589,39 @@ function downtime(list, service, seconds) { sum + Math.max(0, Math.min(p.to, now) - Math.max(p.from, start)), 0); } +// recordedTime is the part of the last seconds since the bot started +// recording availability, in seconds. +function recordedTime(data, seconds) { + const now = Date.now() / 1000; + return now - Math.max(now - seconds, data.since ? Date.parse(data.since) / 1000 : -Infinity); +} + +// successRate counts the tries of a service in the hours and UTC days +// that overlap the last seconds, or is null without any. Only Patchwork +// is counted. +function successRate(data, service, seconds) { + if (service !== "patchwork") return null; + const start = Date.now() / 1000 - seconds; + const counts = (data.patchwork_hourly_tries || []).map(b => + ({ end: Date.parse(b.hour) / 1000 + 3600, b })).concat( + (data.patchwork_daily_tries || []).map(b => + ({ end: Date.parse(b.day + "T00:00:00Z") / 1000 + 86400, b }))); + const r = counts.filter(c => c.end > start).reduce((r, c) => + ({ tries: r.tries + c.b.tries, failed: r.failed + (c.b.failed || 0) }), { tries: 0, failed: 0 }); + return r.tries ? r : null; +} + +// formatRate shows the share of tries that worked in whole percent, +// rounded down so that it only shows 100% when none failed. +function formatRate(r) { + return Math.floor(100 * (r.tries - r.failed) / r.tries) + "%"; +} + +// rateColor goes from yellow when most tries worked to red when none did. +function rateColor(r) { + return "hsl(" + Math.round(50 * (r.tries - r.failed) / r.tries) + ", 90%, 45%)"; +} + async function showAvailability() { const path = "data/availability.json"; if (!cache.has(path)) { @@ -615,21 +648,31 @@ function renderAvailability() { const used = index.services || MAIN_SERVICES; const services = used.concat(Object.keys(SERVICES).filter(s => !used.includes(s) && list.some(p => p.service === s))); - const summary = el("table", { class: "avail" }, - el("tr", {}, el("th", {}, "Service"), el("th", {}, "Now"), - WINDOWS.map(([name]) => el("th", {}, name)), el("th", {}, TIMELINE_DAYS + " days")), + const summary = el("table", { class: "avail summary" }, + el("tr", {}, el("th", { class: "fit" }, "Service"), el("th", { class: "fit" }, "Now"), + WINDOWS.map(([name]) => el("th", { class: "fit center" }, name)), el("th"), + el("th", { class: "center" }, TIMELINE_DAYS + " days")), services.map(service => { const failing = (data.failing || {})[service]; return el("tr", {}, - el("td", {}, SERVICES[service] || service), - el("td", { class: failing ? "down" : "up" }, + el("td", { class: "fit" }, SERVICES[service] || service), + el("td", { class: failing ? "fit down" : "fit up" }, failing ? ["unavailable for ", span(failing.since)] : "available"), WINDOWS.map(([, seconds]) => { const down = downtime(list, service, seconds); - return el("td", { class: down ? "num down" : "num muted", - title: (100 - 100 * down / seconds).toFixed(2) + "% available" }, - duration(down)); - }), + const rate = successRate(data, service, seconds); + const recorded = recordedTime(data, seconds); + const parts = []; + if (recorded > 0) parts.push(Math.max(0, 100 - 100 * down / recorded).toFixed(2) + + "% of the time recorded available"); + if (rate) parts.push(formatRate(rate) + " of " + rate.tries + " tries worked"); + const title = parts.join(", ") || null; + return el("td", { class: "fit window", title }, el("div", {}, + el("span", { class: down ? "down" : "muted" }, + rate && !down ? "0m" : duration(down)), + rate ? el("span", rate.failed ? { class: "rate", style: "color: " + rateColor(rate) } : + { class: "rate muted" }, formatRate(rate)) : null)); + }), el("td"), el("td", { class: "timeline" }, el("div", { class: "days" }, timeline(list, service, data)))); })); @@ -656,7 +699,8 @@ function renderAvailability() { "the hours in which the service was unavailable, the higher the longer, red for an ", "outage. Times are as the bot saw them: from ", "the first request that failed to the first that worked, as precise as its ", - "polling cycles. The bot keeps them for 90 days."), + "polling cycles. The bot keeps them for 90 days. The percentage is the share ", + "of the bot's requests to Patchwork, retries included, that worked: the lower, the redder."), rows.length ? el("div", { class: "wide" }, pager(), el("table", { class: "avail periods" }, el("tr", {}, ["Service", "From", "To", "Duration", "", "Reason"].map(h => diff --git a/internal/pages/site/style.css b/internal/pages/site/style.css index 6a2d3bb4..4164924b 100644 --- a/internal/pages/site/style.css +++ b/internal/pages/site/style.css @@ -121,10 +121,15 @@ a:hover .badge { background: color-mix(in srgb, currentColor 20%, transparent); .avail th, .avail td { padding: 4px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; } .avail .num { text-align: right; font-variant-numeric: tabular-nums; } +.avail .window { font-variant-numeric: tabular-nums; } +.avail .window div { display: flex; justify-content: space-between; gap: 2ch; } .avail .up { color: var(--success); } .avail .down { color: var(--fail); } .avail .reason { white-space: normal; overflow-wrap: anywhere; } .avail .timeline { width: 40%; min-width: 200px; } +/* The columns as narrow as their contents, the space left before the bar. */ +.avail.summary th.center { text-align: center; } +.avail.summary .fit { width: 1%; padding: 4px 1.25ch; } .days { position: relative; height: 16px; border-radius: 3px; overflow: hidden; background: var(--row); } .days span { position: absolute; bottom: 0; } diff --git a/internal/pipeline/availability.go b/internal/pipeline/availability.go index 3cbe854f..842fa781 100644 --- a/internal/pipeline/availability.go +++ b/internal/pipeline/availability.go @@ -19,6 +19,13 @@ import ( // kept for the pages. const availabilityKept = 90 * 24 * time.Hour +// The counts of tries are kept by hour for triesHourly, then by day, for +// triesKept in all. +const ( + triesHourly = 7 * 24 * time.Hour + triesKept = 31 * 24 * time.Hour +) + func serviceName(service string) string { switch service { case state.ServicePatchwork: diff --git a/internal/pipeline/outage_test.go b/internal/pipeline/outage_test.go index bfdfcb2d..26afaca1 100644 --- a/internal/pipeline/outage_test.go +++ b/internal/pipeline/outage_test.go @@ -775,3 +775,17 @@ func TestRefusedReportsRetriedHourly(t *testing.T) { t.Fatalf("report failure = %+v", f) } } + +func TestStepPrunesTries(t *testing.T) { + e := newEnv(t, "") + a := e.p.Store.Availability + a.CountPatchworkTry(true, e.now.Add(-31*24*time.Hour-time.Hour)) + a.CountPatchworkTry(false, e.now.Add(-30*24*time.Hour)) + e.p.Step(context.Background(), false) + day := e.now.Add(-30 * 24 * time.Hour).UTC().Format("2006-01-02") + if len(a.PatchworkHourlyTries) != 0 || len(a.PatchworkDailyTries) != 1 || + a.PatchworkDailyTries[0].Day != day || a.PatchworkDailyTries[0].Tries != 1 { + t.Fatalf("tries after the step: %d hours, days %+v", + len(a.PatchworkHourlyTries), a.PatchworkDailyTries) + } +} diff --git a/internal/pipeline/pipeline.go b/internal/pipeline/pipeline.go index 2decd9ac..aa40fa7d 100644 --- a/internal/pipeline/pipeline.go +++ b/internal/pipeline/pipeline.go @@ -238,6 +238,7 @@ func (p *Pipeline) Step(ctx context.Context, final bool) { p.steps++ p.pwDown, p.checksDown, p.pwSkipLogged = nil, nil, nil p.Store.Availability.Prune(p.now().Add(-availabilityKept)) + p.Store.Availability.PrunePatchworkTries(p.now(), triesHourly, triesKept) if p.Store.Availability.Since == "" { p.Store.Availability.Since = state.FormatTime(p.now()) } diff --git a/internal/pw/client.go b/internal/pw/client.go index 8eb3bea3..1572d020 100644 --- a/internal/pw/client.go +++ b/internal/pw/client.go @@ -37,6 +37,8 @@ type Options struct { Token string MinDelay time.Duration Logger *slog.Logger + // OnTry is passed to the HTTP client made when HTTP is nil. + OnTry func(failed bool) HTTP *httpx.Client } @@ -83,6 +85,7 @@ func New(opts Options) (*Client, error) { Authorization: auth, AuthHost: u.Hostname(), Logger: opts.Logger, + OnTry: opts.OnTry, }) } base := strings.TrimRight(opts.APIURL, "/") diff --git a/internal/pw/client_test.go b/internal/pw/client_test.go index cfd1f8f3..620b56e0 100644 --- a/internal/pw/client_test.go +++ b/internal/pw/client_test.go @@ -335,3 +335,23 @@ func TestWalkEventsFetchErrorKeepsCursor(t *testing.T) { t.Errorf("cursor %d err %v", cursor, err) } } + +func TestNewReportsTries(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Write([]byte(`{"id":1}`)) + })) + defer srv.Close() + var tries []bool + c, err := New(Options{APIURL: srv.URL + "/api", Logger: slog.New(slog.DiscardHandler), + OnTry: func(failed bool) { tries = append(tries, failed) }}) + if err != nil { + t.Fatal(err) + } + if _, err := c.GetPatch(context.Background(), 1); err != nil { + t.Fatal(err) + } + if len(tries) != 1 || tries[0] { + t.Fatalf("tries = %v", tries) + } +} diff --git a/internal/state/availability.go b/internal/state/availability.go index 5741fa45..eec8a1a6 100644 --- a/internal/state/availability.go +++ b/internal/state/availability.go @@ -31,6 +31,12 @@ type Availability struct { Failing map[string]*Period `json:"failing"` // Periods are the ended periods, oldest first. Periods []*Period `json:"periods"` + // PatchworkHourlyTries counts the HTTP tries to Patchwork by hour for + // the last days, oldest first. + PatchworkHourlyTries []*HourTries `json:"patchwork_hourly_tries,omitempty"` + // PatchworkDailyTries counts them by UTC day before that, oldest + // first. + PatchworkDailyTries []*DayTries `json:"patchwork_daily_tries,omitempty"` } type Period struct { @@ -42,6 +48,25 @@ type Period struct { Outage bool `json:"outage,omitempty"` } +// HourTries counts the tries of requests during an hour, each retry a +// try of its own. +type HourTries struct { + // Hour is the start of the hour, in UTC. + Hour string `json:"hour"` + Tries int `json:"tries"` + Failed int `json:"failed,omitempty"` +} + +// DayTries counts the tries of requests during a UTC day. +type DayTries struct { + // Day is the date, as 2006-01-02. + Day string `json:"day"` + Tries int `json:"tries"` + Failed int `json:"failed,omitempty"` +} + +const dayFormat = "2006-01-02" + func newAvailability() *Availability { return &Availability{Schema: SchemaVersion, Failing: map[string]*Period{}} } @@ -79,3 +104,55 @@ func (a *Availability) Prune(before time.Time) { } a.Periods = keep } + +// CountPatchworkTry counts a try of a request to Patchwork. +func (a *Availability) CountPatchworkTry(failed bool, now time.Time) { + hour := FormatTime(now.UTC().Truncate(time.Hour)) + n := len(a.PatchworkHourlyTries) + if n == 0 || a.PatchworkHourlyTries[n-1].Hour != hour { + a.PatchworkHourlyTries = append(a.PatchworkHourlyTries, &HourTries{Hour: hour}) + n++ + } + t := a.PatchworkHourlyTries[n-1] + t.Tries++ + if failed { + t.Failed++ + } +} + +// PrunePatchworkTries merges the hours of each UTC day that ended more +// than hourly before now into a count for the day, and forgets the +// counts older than kept. +func (a *Availability) PrunePatchworkTries(now time.Time, hourly, kept time.Duration) { + merged, forgotten := now.Add(-hourly), now.Add(-kept) + hours := a.PatchworkHourlyTries[:0] + for _, t := range a.PatchworkHourlyTries { + start := ParseTime(t.Hour).UTC() + if start.Before(forgotten) { + continue + } + day := start.Truncate(24 * time.Hour) + if day.Add(24 * time.Hour).After(merged) { + hours = append(hours, t) + continue + } + key := day.Format(dayFormat) + n := len(a.PatchworkDailyTries) + if n == 0 || a.PatchworkDailyTries[n-1].Day != key { + a.PatchworkDailyTries = append(a.PatchworkDailyTries, &DayTries{Day: key}) + n++ + } + d := a.PatchworkDailyTries[n-1] + d.Tries += t.Tries + d.Failed += t.Failed + } + a.PatchworkHourlyTries = hours + days := a.PatchworkDailyTries[:0] + for _, d := range a.PatchworkDailyTries { + start, err := time.Parse(dayFormat, d.Day) + if err == nil && start.Add(24*time.Hour).After(forgotten) { + days = append(days, d) + } + } + a.PatchworkDailyTries = days +} diff --git a/internal/state/availability_test.go b/internal/state/availability_test.go index bdbcb5e8..1cd6ca10 100644 --- a/internal/state/availability_test.go +++ b/internal/state/availability_test.go @@ -4,6 +4,11 @@ package state import ( + "encoding/json" + "os" + "path/filepath" + "reflect" + "strings" "testing" "time" ) @@ -44,3 +49,95 @@ func TestAvailability(t *testing.T) { t.Fatalf("after pruning: %+v", a) } } + +func TestCountPatchworkTry(t *testing.T) { + dir := t.TempDir() + s, err := Load(dir) + if err != nil { + t.Fatal(err) + } + t0 := time.Date(2026, 3, 10, 12, 59, 0, 0, time.UTC) + a := s.Availability + a.CountPatchworkTry(true, t0) + a.CountPatchworkTry(false, t0.Add(30*time.Second)) + a.CountPatchworkTry(true, t0.Add(2*time.Minute)) + if err := s.Save(); err != nil { + t.Fatal(err) + } + + s, err = Load(dir) + if err != nil { + t.Fatal(err) + } + want := []*HourTries{ + {Hour: "2026-03-10T12:00:00Z", Tries: 2, Failed: 1}, + {Hour: "2026-03-10T13:00:00Z", Tries: 1, Failed: 1}, + } + if got := s.Availability.PatchworkHourlyTries; !reflect.DeepEqual(got, want) { + t.Fatalf("tries = %s", toJSON(got)) + } +} + +func TestPrunePatchworkTries(t *testing.T) { + a := newAvailability() + a.PatchworkHourlyTries = []*HourTries{ + {Hour: "2026-02-10T05:00:00Z", Tries: 9, Failed: 9}, + {Hour: "2026-03-12T22:00:00Z", Tries: 2, Failed: 1}, + {Hour: "2026-03-12T23:00:00Z", Tries: 3}, + {Hour: "2026-03-13T09:00:00Z", Tries: 4}, + {Hour: "2026-03-13T11:00:00Z", Tries: 5, Failed: 2}, + } + a.PatchworkDailyTries = []*DayTries{ + {Day: "2026-02-16", Tries: 7}, + {Day: "2026-02-17", Tries: 8, Failed: 1}, + {Day: "2026-03-12", Tries: 1}, + } + now := time.Date(2026, 3, 20, 10, 30, 0, 0, time.UTC) + a.PrunePatchworkTries(now, 7*24*time.Hour, 31*24*time.Hour) + wantDays := []*DayTries{ + {Day: "2026-02-17", Tries: 8, Failed: 1}, + {Day: "2026-03-12", Tries: 6, Failed: 1}, + } + if !reflect.DeepEqual(a.PatchworkDailyTries, wantDays) { + t.Fatalf("days = %s", toJSON(a.PatchworkDailyTries)) + } + wantHours := []*HourTries{ + {Hour: "2026-03-13T09:00:00Z", Tries: 4}, + {Hour: "2026-03-13T11:00:00Z", Tries: 5, Failed: 2}, + } + if !reflect.DeepEqual(a.PatchworkHourlyTries, wantHours) { + t.Fatalf("hours = %s", toJSON(a.PatchworkHourlyTries)) + } +} + +func TestAvailabilityWithoutTries(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, AvailabilityFile) + err := os.WriteFile(path, []byte(`{"schema":14,"failing":{},"periods":[]}`), 0o644) + if err != nil { + t.Fatal(err) + } + s, err := Load(dir) + if err != nil { + t.Fatal(err) + } + a := s.Availability + if len(a.PatchworkHourlyTries) != 0 || len(a.PatchworkDailyTries) != 0 { + t.Fatalf("tries = %s", toJSON(a)) + } + if err := s.Save(); err != nil { + t.Fatal(err) + } + b, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if strings.Contains(string(b), "patchwork_") { + t.Fatalf("saved: %s", b) + } +} + +func toJSON(v any) string { + b, _ := json.Marshal(v) + return string(b) +} diff --git a/internal/state/schema.go b/internal/state/schema.go index 0e96f25a..1d9ef56b 100644 --- a/internal/state/schema.go +++ b/internal/state/schema.go @@ -17,7 +17,7 @@ import ( // even an added field: older versions refuse unknown fields, and a // version mismatch tells the user what to do. TestSchemaFields fails // when the structure changes without a bump. -const SchemaVersion = 14 +const SchemaVersion = 15 const ( kindMeta = "meta" diff --git a/internal/state/testdata/schema-15.txt b/internal/state/testdata/schema-15.txt new file mode 100644 index 00000000..221d364a --- /dev/null +++ b/internal/state/testdata/schema-15.txt @@ -0,0 +1,152 @@ +availability.failing{}.outage bool +availability.failing{}.reason string +availability.failing{}.service string +availability.failing{}.since string +availability.failing{}.until string +availability.patchwork_daily_tries[].day string +availability.patchwork_daily_tries[].failed int +availability.patchwork_daily_tries[].tries int +availability.patchwork_hourly_tries[].failed int +availability.patchwork_hourly_tries[].hour string +availability.patchwork_hourly_tries[].tries int +availability.periods[].outage bool +availability.periods[].reason string +availability.periods[].service string +availability.periods[].since string +availability.periods[].until string +availability.schema int +availability.since string +meta.archives{}.failing string +meta.archives{}.last_month string +meta.archives{}.months{} int +meta.archives{}.retry{}.attempts int +meta.archives{}.retry{}.cause string +meta.archives{}.retry{}.first string +meta.archives{}.retry{}.last_error string +meta.archives{}.retry{}.next string +meta.archives{}.retry{}.op string +meta.archives{}.retry{}.outage string +meta.discovery_start string +meta.events{} int +meta.instance.patchwork string +meta.instance.project string +meta.instance.test_repo string +meta.outages{}.alert_failing string +meta.outages{}.alerted string +meta.outages{}.checks bool +meta.outages{}.next_probe string +meta.outages{}.reason string +meta.outages{}.since string +meta.schema int +meta.stats.jobs_per_patch float64 +meta.tools_synced string +series.schema int +series.series[].base.branch string +series.series[].base.git_url string +series.series[].base.sha string +series.series[].base.why string +series.series[].branch string +series.series[].checked string +series.series[].cover_id int +series.series[].date string +series.series[].decisions[].action string +series.series[].decisions[].detail string +series.series[].decisions[].run_url string +series.series[].decisions[].time string +series.series[].decisions[].workflow_url string +series.series[].depends_on int +series.series[].discovered string +series.series[].failure.attempts int +series.series[].failure.cause string +series.series[].failure.first string +series.series[].failure.last_error string +series.series[].failure.next string +series.series[].failure.op string +series.series[].failure.outage string +series.series[].finished string +series.series[].hold bool +series.series[].id int +series.series[].name string +series.series[].patches[].comments_pending bool +series.series[].patches[].comments_seen int +series.series[].patches[].decisions[].action string +series.series[].patches[].decisions[].detail string +series.series[].patches[].decisions[].run_url string +series.series[].patches[].decisions[].time string +series.series[].patches[].decisions[].workflow_url string +series.series[].patches[].failure.attempts int +series.series[].patches[].failure.cause string +series.series[].patches[].failure.first string +series.series[].patches[].failure.last_error string +series.series[].patches[].failure.next string +series.series[].patches[].failure.op string +series.series[].patches[].failure.outage string +series.series[].patches[].id int +series.series[].patches[].msgid string +series.series[].patches[].name string +series.series[].patches[].number int +series.series[].patches[].pushed string +series.series[].patches[].recheck bool +series.series[].patches[].recheck_checks[] string +series.series[].patches[].retry bool +series.series[].patches[].runs[].attempt int +series.series[].patches[].runs[].auto_reruns int +series.series[].patches[].runs[].check_failure.attempts int +series.series[].patches[].runs[].check_failure.cause string +series.series[].patches[].runs[].check_failure.first string +series.series[].patches[].runs[].check_failure.last_error string +series.series[].patches[].runs[].check_failure.next string +series.series[].patches[].runs[].check_failure.op string +series.series[].patches[].runs[].check_failure.outage string +series.series[].patches[].runs[].completed string +series.series[].patches[].runs[].conclusion string +series.series[].patches[].runs[].correlation_id string +series.series[].patches[].runs[].details string +series.series[].patches[].runs[].failure.attempts int +series.series[].patches[].runs[].failure.cause string +series.series[].patches[].runs[].failure.first string +series.series[].patches[].runs[].failure.last_error string +series.series[].patches[].runs[].failure.next string +series.series[].patches[].runs[].failure.op string +series.series[].patches[].runs[].failure.outage string +series.series[].patches[].runs[].file string +series.series[].patches[].runs[].final.check string +series.series[].patches[].runs[].final.email string +series.series[].patches[].runs[].final.message_id string +series.series[].patches[].runs[].id int64 +series.series[].patches[].runs[].kind string +series.series[].patches[].runs[].min_attempt int +series.series[].patches[].runs[].pending.check string +series.series[].patches[].runs[].pending.email string +series.series[].patches[].runs[].pending.message_id string +series.series[].patches[].runs[].reply.check string +series.series[].patches[].runs[].reply.email string +series.series[].patches[].runs[].reply.message_id string +series.series[].patches[].runs[].reply_failure.attempts int +series.series[].patches[].runs[].reply_failure.cause string +series.series[].patches[].runs[].reply_failure.first string +series.series[].patches[].runs[].reply_failure.last_error string +series.series[].patches[].runs[].reply_failure.next string +series.series[].patches[].runs[].reply_failure.op string +series.series[].patches[].runs[].reply_failure.outage string +series.series[].patches[].runs[].result string +series.series[].patches[].runs[].status string +series.series[].patches[].runs[].updated string +series.series[].patches[].runs[].url string +series.series[].patches[].runs[].workflow string +series.series[].patches[].sender.email string +series.series[].patches[].sender.name string +series.series[].patches[].sha string +series.series[].patches[].status string +series.series[].patches[].subject string +series.series[].reapply bool +series.series[].reason string +series.series[].retry bool +series.series[].skip string +series.series[].started string +series.series[].status string +series.series[].submitter.email string +series.series[].submitter.name string +series.series[].total int +series.series[].version int +series.series[].web_url string