Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/design/reconciler-backfill.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ A crash between the claim and the record loses one observation. Appendix A accep
A new package, `internal/reconcile`, runs one goroutine from `main` beside the worker (`cmd/github-metrics/main.go:124-130`).

- Schedule: an incremental run at startup and then every 15 minutes. A sweep once a day at 03:00 UTC. A `time.Ticker` drops ticks while a run is busy, so runs never overlap, and the sweep waits for a running incremental run to finish.
- Run bound: each run gets a context with a 14-minute deadline, so it can't overlap the next tick.
- Run bound: each incremental run gets a context with a 14-minute deadline to keep it from overlapping the next tick. A sweep gets a 45-minute deadline to read the full repair window at the shared request rate.
- Repository list: page through `/installation/repositories`, capped at 10 pages. The client stores a tag on receipt (`internal/ghclient/ghclient.go:332-343`), and a page-one tag can't see a change confined to page two. So the reconciler sends the tag only when the last full list fit on one page and every page succeeded. For a longer list, or after any failed page, it calls `etags.Set(url, "")` and reads every page in full, at one request per 100 repositories. A `304` then reuses the cached list only in the one-page case. The response shape of that endpoint, and whether a narrowed token may call it, are unverified. Each repository is processed in turn, with no concurrency, since the budget paces every request anyway (`internal/budget/budget.go:36-38`).
- Incremental walk: list `sort=updated&direction=desc` at `budget.Incremental`. Stop at the first item whose `updated_at` is before the stop time, which is the later of the watermark minus a 5-minute overlap and now minus 24 hours. Older milestones can't be recorded anyway, so the 24-hour floor bounds a first run and a run after an outage. Stop after 50 pages (5,000 PRs updated inside the window, far past this installation's scale) and mark the repository truncated: the watermark doesn't advance, the run logs the repository and counts `truncated`, and the next sweep walks that repository with a 200-page cap. Because each repair is idempotent through the claim, a repeated walk costs requests and never double-counts.
- The walk relies on a close or a merge moving `updated_at`, which GitHub's sort order implies but nobody here has verified.
- Per item: skip an item whose `closed_at` is null. Otherwise build a `ClosedPR`. REST can't tell a first close from a later one, and appendix A says the first end wins (`docs/architecture/appendix-a-trace-and-metric-catalog.md:135`). So before a repair would record `ended`, it reads the PR's issue events (`GET /repos/{o}/{r}/issues/{n}/events`, up to 3 pages of 100, one call per page, at `budget.Incremental`) and takes the `created_at` of the earliest `closed` event as the first end time, whatever later reopens and closes follow. The repair sets `ended_at` to that time and the ended state to `merged` when a `merged` event shares its `created_at`, and to `closed` otherwise. That time goes through the same gates as any other. The repair records `merged` from `merged_at`, which is the single merge, and `ended` at the first close in its own state, so a PR that closed, reopened and merged counts its cycle time at the first close with `state=closed`, and a later webhook delivery of either the close or the merge returns `already_counted`. If the events run past 3 pages, or hold no `closed` event, the repair records `merged` only, leaves `ended` unclaimed with outcome `ambiguous`, and the PR is read again whenever the walk reaches it, which happens when it is updated again or while a sweep covers its 24-hour window. Then call `RecordClosed`. Limitation: a PR closed and reopened between two runs, with its close delivery missed, shows a null `closed_at` and its `ended` milestone is never repaired.
- Per item: skip an item whose `closed_at` is null. Otherwise build a `ClosedPR`. REST can't tell a first close from a later one, and appendix A says the first end wins (`docs/architecture/appendix-a-trace-and-metric-catalog.md:135`). So before a repair would record `ended`, it reads the PR's issue events (`GET /repos/{o}/{r}/issues/{n}/events`, up to 3 pages of 100, one call per page, at the priority of the walk: `budget.Incremental` in an incremental run and `budget.Sweep` in a sweep) and takes the `created_at` of the earliest `closed` event as the first end time, whatever later reopens and closes follow. The repair sets `ended_at` to that time and the ended state to `merged` when a `merged` event shares its `created_at`, and to `closed` otherwise. That time goes through the same gates as any other. The repair records `merged` from `merged_at`, which is the single merge, and `ended` at the first close in its own state, so a PR that closed, reopened and merged counts its cycle time at the first close with `state=closed`, and a later webhook delivery of either the close or the merge returns `already_counted`. If the events run past 3 pages, or hold no `closed` event, the repair records `merged` only, leaves `ended` unclaimed with outcome `ambiguous`, and the PR is read again whenever the walk reaches it, which happens when it is updated again or while a sweep covers its 24-hour window. Then call `RecordClosed`. Limitation: a PR closed and reopened between two runs, with its close delivery missed, shows a null `closed_at` and its `ended` milestone is never repaired.
- Watermark: a `watermarks` bucket keyed by repository full name holds the newest `updated_at` seen. It advances only after the walk reached the stop time and every item returned without an error.
- `ETag` use: only the first page sends a tag. A `304` there means the repository is unchanged since the last clean walk in this process, so it's done. Before each later page the reconciler calls `etags.Set(url, "")`, because page contents shift as PRs update, so a later page never answers `304`.
- `ETag` clear: whenever a repository's walk doesn't finish cleanly (truncated, deadline, `ErrGaveUp`, a decode or store error), the reconciler clears the first-page tag with `etags.Set(url, "")`, so the next run reads the page in full instead of getting a `304` that hides the gap (`docs/architecture/11-risks-and-technical-debt.md:11`). Tags stay in memory as today. Moving them into the store, as D4 lists, is later work.
Expand Down