Repository navigation
feat(on-call): a private calendar feed per schedule, and docs for schedules and chains #3023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
5551306
fix(alerts): five ways a page was lost or left open
Makisuo 16ff264
wip(on-call): gaps, departed members and chain tiers
Makisuo dd837a1
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo dcb5e52
fix(alerts): close the gaps a review found in the lost-page fixes
Makisuo 2fc74cd
fix(on-call): a step that reaches nobody no longer goes unnoticed
Makisuo c7882c1
feat(web): warn about coverage gaps and departed people on on-call sc…
Makisuo 4d2c6f2
fix(slo): burn alerts that hold through an outage and do not fire on …
Makisuo fa3074e
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo 53f50c4
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo 6878c1d
fix(on-call): review fixes for gap handling
Makisuo 6e20154
Merge branch 'alerts/oncall-gaps-ui' into alerts/oncall-gaps
Makisuo d0cf95b
style(on-call): format the member notifier
Makisuo b66923d
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo b6e28fb
wip(alerts): manual resolve and time to acknowledge
Makisuo 9606c97
fix(slo): review fixes for the burn and budget alerts
Makisuo 10224cc
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 3c2ac87
feat(mcp): resolve_alert_incident resolves an open incident by hand
Makisuo 47fa2ac
feat(web): SLO pages show capped tiers, the spent budget alert and SL…
Makisuo d9b69e8
Merge branch 'slo/alert-correctness-ui' into slo/alert-correctness
Makisuo d59ac62
fix(web): tier readings count recorded spans, as the evaluator does
Makisuo 0ea2bf2
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo 31ab3d2
fix(alerts): all-clears on rule delete cover every paged destination …
Makisuo 9b5fe37
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo 294bf0c
fix(on-call): review fixes for chains that reach nobody
Makisuo 62f53d0
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo bde33d7
style(alerts): format after the merge
Makisuo a28c54b
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 4ab0b4b
feat(alerts): resolve an incident by hand from the dashboard, and sho…
Makisuo 96645b0
fix(alerts): review fixes for the resolve by hand
Makisuo a198643
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo 7bdf929
test(browser): wire goldens follow the SDK version
Makisuo 443b627
ci: size the ai test lanes at 1.5s per file
Makisuo 04fbd34
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo e2ee2c0
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo 30842bd
test(slo): record the new SLO SQL and check the recorded span count a…
Makisuo fd675ab
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 2e2868e
feat(on-call): a private calendar feed per schedule
Makisuo 18c432a
test(domain): the v2 incident contract fixture carries first_acknowle…
Makisuo 841bb01
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 6f2e730
feat(web): the schedule page makes, replaces and turns off its calend…
Makisuo e848ac9
docs(alerting): on-call schedules and escalation chains
Makisuo ed9e402
fix(on-call): review fixes for the calendar feed
Makisuo 79284af
Merge remote-tracking branch 'origin/fix/browser-wire-golden-version'…
Makisuo 65189b8
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo 1629cf9
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo c1cd272
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo af24040
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 7562fd3
fix(alerts): second round of review fixes for lost pages
Makisuo afe24b5
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo 682a4de
fix(on-call): say that a departed person's shifts go uncovered when n…
Makisuo fe6ce9c
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo 4d2eade
fix(slo): review fixes for budget recovery, incident thresholds and s…
Makisuo f329c2d
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo b0ac455
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 9902564
fix(alerts): review fixes for resolve by hand
Makisuo 76cfa39
fix(on-call): review fixes for the calendar feed
Makisuo b01a24b
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo e0c7c20
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo 5c1845d
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo 351b5a2
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo e11c5a6
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 3e3f024
fix(mcp): the coverage warning names the gap window the server report…
Makisuo 720bcae
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo 5b9f480
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo dc16334
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 6864371
fix(alerts): a skipped post earns no all-clear on rule deletion, and …
Makisuo dc2e03d
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo 17e9b68
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo 8c3cefa
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 20ba262
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 90b70b8
fix(alerts): relink an all-clear that outlives its rule while in flig…
Makisuo f200c3d
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo 7f6e404
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo 5be044e
fix(slo): a held tier says it has no events or too few to judge, and …
Makisuo 247ed8d
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 4f38875
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo bb67f9c
fix(slo): a budget incident names no group, though it is stored with …
Makisuo ad35090
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 9afebef
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 07e6937
fix(on-call): a calendar link someone else turned off stops showing a…
Makisuo b2a2041
test(on-call): leaving the calendar feed question sends nothing, and …
Makisuo 8e578e2
Merge main after #3013 was squash-merged
Makisuo 4f208e8
Merge remote-tracking branch 'origin/main' into slo/alert-correctness
Makisuo 0059290
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo 16b682a
Merge main after #3017 was squash-merged
Makisuo 4b8b434
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo 4d8d519
Merge main after #3018 was squash-merged
Makisuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { afterAll, describe, expect, it } from "@effect/vitest" | ||
| import { AlertMemberDirectoryUnavailableError, AlertPersistenceError } from "@maple/domain/http" | ||
| import { Effect, Layer, Option } from "effect" | ||
| import { HttpRouter } from "effect/http" | ||
| import { OnCallSchedulesService } from "@maple/backend/services/alerts/OnCallSchedulesService" | ||
| import { ShareRateLimiter } from "@maple/backend/services/auth/ShareRateLimiter" | ||
| import { onCallCalendarFeedUrl, OnCallCalendarRouter } from "./oncall-calendar.http" | ||
|
|
||
| const TOKEN = "mcal_known" | ||
| const CALENDAR = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nEND:VCALENDAR\r\n" | ||
| const asked: Array<string> = [] | ||
|
|
||
| /** One feed exists, behind `TOKEN`; `mcal_down` and `mcal_nodir` stand for two things being down. */ | ||
| const schedules = Layer.mock(OnCallSchedulesService)({ | ||
| calendarFeed: (token) => { | ||
| asked.push(token) | ||
| if (token === "mcal_down") | ||
| return Effect.fail(new AlertPersistenceError({ message: "Alert persistence failed" })) | ||
| if (token === "mcal_nodir") | ||
| return Effect.fail( | ||
| new AlertMemberDirectoryUnavailableError({ message: "No answer", cause: "timeout" }), | ||
| ) | ||
| return Effect.succeed(token === TOKEN ? Option.some(CALENDAR) : Option.none()) | ||
| }, | ||
| }) | ||
|
|
||
| const limited = { now: false } | ||
| const checked: Array<{ readonly tokenHashPrefix: string; readonly ip: string | undefined }> = [] | ||
| const rateLimiter = Layer.succeed(ShareRateLimiter, { | ||
| check: (input) => { | ||
| checked.push(input) | ||
| return Effect.succeed(limited.now ? ("limited" as const) : ("allowed" as const)) | ||
| }, | ||
| }) | ||
|
|
||
| const { handler, dispose } = HttpRouter.toWebHandler( | ||
| OnCallCalendarRouter.pipe(Layer.provide(Layer.merge(schedules, rateLimiter))), | ||
| { disableLogger: true }, | ||
| ) | ||
| afterAll(() => dispose()) | ||
|
|
||
| const get = (path: string, method = "GET") => | ||
| handler(new Request(`https://api.maple.test${path}`, { method })) | ||
|
|
||
| describe("OnCallCalendarRouter", () => { | ||
| it("serves the calendar behind a known link as text/calendar, kept out of shared caches and indexes", async () => { | ||
| const response = await get(new URL(onCallCalendarFeedUrl("https://api.maple.test", TOKEN)).pathname) | ||
| expect(response.status).toBe(200) | ||
| expect(response.headers.get("content-type")).toBe("text/calendar; charset=utf-8") | ||
| expect(response.headers.get("cache-control")).toBe("private, max-age=300") | ||
| expect(response.headers.get("x-robots-tag")).toBe("noindex") | ||
| expect(await response.text()).toBe(CALENDAR) | ||
| }) | ||
|
|
||
| it("answers an unknown link, and a path without the .ics ending, with the same bare 404", async () => { | ||
| const unknown = await get("/calendar/oncall/mcal_guess.ics") | ||
| expect(unknown.status).toBe(404) | ||
| expect(await unknown.text()).toBe("Not found") | ||
| expect(unknown.headers.get("cache-control")).toBe("no-store") | ||
| const before = asked.length | ||
| const noSuffix = await get(`/calendar/oncall/${TOKEN}`) | ||
| expect(noSuffix.status).toBe(404) | ||
| // Not a feed path at all: the service is never asked. | ||
| expect(asked).toHaveLength(before) | ||
| }) | ||
|
|
||
| it("says to come back later when the database cannot be read, without saying why", async () => { | ||
| const response = await get("/calendar/oncall/mcal_down.ics") | ||
| expect(response.status).toBe(503) | ||
| expect(response.headers.get("retry-after")).toBe("60") | ||
| expect(await response.text()).toBe("Temporarily unavailable") | ||
| }) | ||
|
|
||
| it("answers 503, not a feed without names, when the member directory is down", async () => { | ||
| const response = await get("/calendar/oncall/mcal_nodir.ics") | ||
| expect(response.status).toBe(503) | ||
| expect(response.headers.get("retry-after")).toBe("300") | ||
| expect(response.headers.get("content-type")).not.toContain("text/calendar") | ||
| }) | ||
|
|
||
| it("refuses a link polled too fast before reading anything, keyed by a hash of the link", async () => { | ||
| limited.now = true | ||
| const before = asked.length | ||
| const response = await get(`/calendar/oncall/${TOKEN}.ics`) | ||
| limited.now = false | ||
| expect(response.status).toBe(429) | ||
| expect(response.headers.get("retry-after")).toBe("60") | ||
| expect(asked).toHaveLength(before) | ||
| const key = checked[checked.length - 1]?.tokenHashPrefix ?? "" | ||
| expect(key).toMatch(/^[0-9a-f]{24}$/) | ||
| expect(key).not.toContain(TOKEN) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { createHash } from "node:crypto" | ||
| import { Effect, Option, String as Str } from "effect" | ||
| import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http" | ||
| import { OnCallSchedulesService } from "@maple/backend/services/alerts/OnCallSchedulesService" | ||
| import { ShareRateLimiter } from "@maple/backend/services/auth/ShareRateLimiter" | ||
|
|
||
| /** | ||
| * `GET /calendar/oncall/{token}.ics`: a schedule's shifts as an iCalendar feed, for a calendar app | ||
| * to subscribe to. No session and no API key: the link is the credential, so the response says | ||
| * nothing a caller without it could use, and an unknown link is the same bare 404 as a wrong path. | ||
| */ | ||
|
|
||
| export const ONCALL_CALENDAR_PATH = "/calendar/oncall" | ||
| const ICS_SUFFIX = ".ics" | ||
|
|
||
| /** The link a schedule's feed is fetched by. */ | ||
| export const onCallCalendarFeedUrl = (apiOrigin: string, token: string): string => | ||
| `${apiOrigin}${ONCALL_CALENDAR_PATH}/${token}${ICS_SUFFIX}` | ||
|
|
||
| // Private: the body names people. A calendar app refetches on its own clock, so a short | ||
| // lifetime only spares a burst of repeat requests. | ||
| const FEED_HEADERS = { | ||
| "cache-control": "private, max-age=300", | ||
| "x-robots-tag": "noindex", | ||
| "content-disposition": 'inline; filename="on-call.ics"', | ||
| } | ||
|
|
||
| const notFound = HttpServerResponse.text("Not found", { | ||
| status: 404, | ||
| headers: { "cache-control": "no-store", "x-robots-tag": "noindex" }, | ||
| }) | ||
|
|
||
| const comeBackLater = (seconds: number) => | ||
| HttpServerResponse.text("Temporarily unavailable", { | ||
| status: 503, | ||
| headers: { "cache-control": "no-store", "retry-after": String(seconds) }, | ||
| }) | ||
|
|
||
| const tooManyRequests = HttpServerResponse.text("Too many requests", { | ||
| status: 429, | ||
| headers: { "cache-control": "no-store", "retry-after": "60" }, | ||
| }) | ||
|
|
||
| export const OnCallCalendarRouter = HttpRouter.use((router) => | ||
| Effect.gen(function* () { | ||
| const schedules = yield* OnCallSchedulesService | ||
| const rateLimiter = yield* ShareRateLimiter | ||
| yield* router.add( | ||
| "GET", | ||
| `${ONCALL_CALENDAR_PATH}/:file`, | ||
| Effect.gen(function* () { | ||
| const params = yield* HttpRouter.params | ||
| const file = params.file ?? "" | ||
| if (!Str.endsWith(ICS_SUFFIX)(file)) return notFound | ||
| const token = Str.slice(0, -ICS_SUFFIX.length)(file) | ||
| // The same two buckets as a shared dashboard link: per caller, and per link, so a | ||
| // leaked link cannot be polled without bound. Keyed by a hash, never the token. | ||
| const request = yield* HttpServerRequest.HttpServerRequest | ||
| const outcome = yield* rateLimiter.check({ | ||
| tokenHashPrefix: Str.slice( | ||
| 0, | ||
| 24, | ||
| )(createHash("sha256").update(token, "utf8").digest("hex")), | ||
| ip: request.headers["cf-connecting-ip"], | ||
| }) | ||
| if (outcome === "limited") return tooManyRequests | ||
| const body = yield* schedules.calendarFeed(token) | ||
| return Option.match(body, { | ||
| onNone: () => notFound, | ||
| onSome: (calendar) => | ||
| HttpServerResponse.text(calendar, { | ||
| status: 200, | ||
| contentType: "text/calendar; charset=utf-8", | ||
| headers: FEED_HEADERS, | ||
| }), | ||
| }) | ||
| }).pipe( | ||
| Effect.tap((response) => | ||
| Effect.annotateCurrentSpan("http.response.status_code", response.status), | ||
| ), | ||
| Effect.tapError(() => Effect.annotateCurrentSpan("http.response.status_code", 503)), | ||
| // The request's only server span, since the automatic one is suppressed for this | ||
| // prefix. The token must not reach a trace: it carries the route, not the path. | ||
| Effect.withSpan("OnCallCalendar.feed", { | ||
| kind: "server", | ||
| attributes: { | ||
| "http.route": `${ONCALL_CALENDAR_PATH}/:file`, | ||
| "http.request.method": "GET", | ||
| }, | ||
| }), | ||
| // A calendar app keeps its last good copy on a 503, which beats a feed without names. | ||
| Effect.catchTags({ | ||
| "@maple/http/errors/AlertPersistenceError": () => Effect.succeed(comeBackLater(60)), | ||
| "@maple/http/errors/AlertMemberDirectoryUnavailableError": () => | ||
| Effect.succeed(comeBackLater(300)), | ||
| }), | ||
| ), | ||
| // The server span is suppressed for this prefix; this covers a span recorded anyway. | ||
| { redactedParams: ["file"] }, | ||
| ) | ||
| }), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.