Skip to content

Write up dashboard incidents and play them back offline - #277

Merged
coryodaniel merged 6 commits into
dashboardfrom
dashboard-incidents
Nov 30, 2026
Merged

coryodaniel merged 6 commits into
dashboardfrom
dashboard-incidents

Conversation

@coryodaniel

@coryodaniel coryodaniel commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Stacked on #276.

w writes an incident up, and mass dashboard --playback plays its recording back offline.

  • Timeline. While the dashboard runs, it keeps a record for each incident: the snapshot and stash when it fired, its blast radius, and the deployments, alarms and stash changes in that blast radius from 15 minutes before it fired until it cleared. It keeps 20 incidents and 200 events each, and counts the events it leaves out.
  • Write-up. w writes the selected alarm's incident, or else the selected environment's, or else the most recent, to incident-<instance>-<alarm>-<YYYYMMDD-HHMM>.md. The write-up has the duration, the alarm and its message, the blast radius, a timeline table, empty sections for root cause and follow-ups, and the command that plays it back. An alarm firing without --watch gets a record made on the spot from what is in view.
  • Recording. Next to the write-up, incident-…json holds the environments, runtimes, applications, annotations, the stash at the start and the timeline.
  • Playback. mass dashboard --playback <file> opens straight into replay over the recorded window, with the usual replay keys. It makes no API calls and needs no profile. Approving, deploying and logs are off.

Files are written with 0600, set again when a file already exists, because a write-up names the organization's environments and instances.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 32s —— View job


Review of #277: incident write-up and offline playback

I read the diff against origin/dashboard-actions. I did not run make check or make docs, so the test suite, lint and docs regeneration are unverified. The layering follows CLAUDE.md: cmd/ only wires, logic lives in internal/commands/dashboard, and the tests are table-driven, one per source file. I found no blocking bugs, but there are a few things to check.

Worth fixing or confirming

  1. os.WriteFile(..., 0o600) only sets the mode when it creates the file (writeup.go, WriteFile). If incident-<env>-<stamp>.md or .json already exists with looser permissions, the new content goes into a file that stays readable by others. It also follows symlinks. Since the stated reason for 0600 is that the files name sensitive things, consider os.OpenFile with O_EXCL, or a Chmod after writing.

  2. File names can collide. incidentName uses only EnvID and the start time to the minute. Two alarms that start in the same environment in the same minute write to the same name, and the second silently overwrites the first. This is realistic because a deploy often trips several alarms at once. Adding the instance ID (through fileSafe) or checking for an existing file would avoid it.

  3. The recording contains more than the blast radius. newRecording stores r.snap.Environments, the runtimes and applications, and r.stash in full. m.stash.entries() takes every stash entry in view, not only those in the blast radius, so the JSON can carry stash values from unrelated environments. The PR description says the write-up names the organization's environments and instances. Please confirm that whole-view stash values in the recording are intended. If not, filter to r.blast.Envs.

  4. Check that m.alarmIdx is in range (writeup.go, incidentToWrite). m.graph.Firing[m.alarmIdx] panics if the firing list shrank after a refresh and the index was not clamped. I did not trace where alarmIdx is clamped. If it is clamped on every graph update, this is fine. If not, add a m.alarmIdx < len(...) guard.

  5. Replay start in playback (recording.go, Window). The window is rounded up to the next entry in ReplayWindows (or the next hour), so replay can begin well before rec.Start. The PR says it replays "over the recorded window" and PlaybackConfig says "from the moment it started". Short incidents will therefore open with empty lead time. Fine if intended, but the doc comment overstates it.

Minor

  • Markdown escaping is uneven (writeup.go). Table cells go through mdCell, but a.Name in the # heading and in **…** is not escaped. An alarm name containing *, _ or a backtick breaks the formatting. The message is flattened but not escaped either.
  • Misleading toast on a partial write. The write order is JSON then markdown. If the markdown write fails, the JSON is already on disk but the toast only names the .md failure.
  • timeline() in timeline.go runs per call. It is called from both newRecording and writeTimeline. This is cheap at 200 events and not a concern.
  • recordedAPI method order. errNotRecorded is declared between methods, so Annotations comes after the var. Moving the var up or down is a tidy-up.
  • Dead branch. cfg.Watch, cfg.Links = false, nil in PlaybackConfig is correct, but cmd/dashboard.go already builds a config without them, so the reset is redundant. It is harmless.

Looks good

  • recordEvents and incidentRecord.add are copy-on-write (slices.Clone, slices.Clip). The earliest events are kept and the rest counted as dropped, which matches the description.
  • LoadRecording rejects empty recordings, and the playback API refuses deploy, approve and logs with sentinel errors.
  • Playback needs no profile: runDashboard returns before newMassdriverClient.
    · branch dashboard-incidents

@coryodaniel

Copy link
Copy Markdown
Member Author

Fixed in 935b8c2:

  • 1: WriteFile sets 0600 again after writing, since os.WriteFile keeps the mode of a file that already exists.
  • 2: write-ups are named for the alarmed instance rather than the environment, so two alarms that fire in one environment in the same minute get separate files. The helpdoc and the PR description use the new name.
  • 4: guarded the index. It's also clamped on every snapshot (applySnapshot), so this is belt and braces.
  • 5: the PlaybackConfig comment says playback can start a little before the recording, since replay windows come in fixed lengths.
  • Minor: alarm names are escaped for markdown in the heading and the bold line.

No change:

  • 3: the whole stash in view is intended. Playback redraws the whole map as it looked, widgets and notes included, not only the blast radius. The files are written 0600 for that reason.
  • Partial write toast: the toast names the file that failed. The JSON being on disk when the markdown fails is harmless, and writing it again overwrites both.
  • errNotRecorded placement and the redundant reset in PlaybackConfig are left as they are.

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 16s —— View job


Re-review of #277 after 935b8c2

I read the diff from 0d45cb3 to 935b8c2. I did not run make check or make docs, so tests, lint and docs regeneration are unverified. The generated docs and helpdoc match each other in the diff.

Your fixes

  • 0600 (item 1): WriteFile now chmods after writing, so an existing file ends up at 0600. Between the write and the chmod, an existing file keeps its old mode briefly. That is acceptable for this use. Symlinks are still followed, which I wouldn't block.
  • Index guard (item 4): m.alarmIdx < len(m.graph.Firing) covers both the empty list and a stale index.
  • Alarm names (minor): mdText escapes the heading and the bold line, and the test now expects Latency \| p99.
  • Playback comment (item 5): the comment now matches what the code does.
  • No-change items (3 and the partial-write toast): your reasoning holds. Writing the whole stash at 0600 is consistent with playback redrawing the whole map. The toast does name the file that failed.

Remaining issues

  1. Collisions are reduced, not removed (writeup.go, incidentName). The name is now InstanceID plus the minute. Two different alarms on the same instance that start in the same minute still collide, and the second silently overwrites the first. For example, "Latency" and "ErrorRate" on care-dev-app can both fire in one minute after a bad deploy. You can fix it by:

    • adding a short slug of Name to the file name, or
    • skipping to a -2 suffix when the file exists.

    It is only worth doing if you expect this case. The 0600 fix doesn't help here.

  2. mdText is applied to a heading and bold text, but not to the other text built from alarm data (writeup.go, the Environment row and the > message quote). The message is flattened but not escaped, so a message starting with # or containing a backtick can still format oddly inside the blockquote. This is cosmetic.

  3. Nit: mdText escapes # anywhere in the text, so Error #5 renders correctly but shows a stray backslash in the raw file. Only a leading # matters in the heading, where the text follows # anyway. The extra escape is harmless.

I found no blocking issues. Item 1 is the only one I'd consider before merging.
· branch dashboard-incidents

… collide

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel

Copy link
Copy Markdown
Member Author

Fixed in 2825eb3:

  • 1: the file name now includes a short slug of the alarm name (incident-care-dev-app-latency-p99-20261126-0001.md), so two alarms on one instance in the same minute write separate files. The helpdoc and the PR description use the new name.

No change:

  • 2: the message is flattened into a blockquote line, so markdown in it renders as markdown, as alarm text usually means it to.
  • 3: agreed, it's harmless.

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 16s —— View job


Re-review of #277 after 2825eb3

I read the diff from 935b8c2 to 2825eb3. I did not run make check or make docs, so tests, lint and docs regeneration are unverified. The helpdoc and docs/generated/mass_dashboard.md carry the same new file name in the diff, and the test file names match incidentName.

Your fix

  • Collision (item 1): incidentName now adds slugOf(r.alarm.Name), so "Latency" and "ErrorRate" on one instance in the same minute get separate files. slugOf collapses runs of -, trims the ends, and cuts to 32 characters. The cut is safe because fileSafe maps every non-ASCII character to -, so slug[:32] can't split a rune.
  • No-change items (2 and 3): I agree with both.

Remaining nits (none blocking)

  1. Collisions are still possible in rare cases (writeup.go:117). Two alarm names collide if they differ only in case or punctuation, such as Latency p99 and latency-p99. They also collide if their first 32 characters match, or if a name is empty or all punctuation and the slug is dropped. An alarm that is still firing under the same name and start minute also lands on the same file, which is a rewrite and not a problem. Two distinct alarms on one instance in one minute with such names is unlikely, so I'd leave it.
  2. slugOf has no direct test. Its collapse, trim, truncation and empty-name branches are only covered through two or three names in the scenario tests. A small table-driven test in writeup_test.go would cover them. For example, "Latency | p99" → latency-p99, a 40-character name cut to 32 with no trailing -, and "!!!" → "" with the file name omitting the slug. CLAUDE.md asks for table-driven tests, and this is a unit with several branches. That test would need package dashboard //nolint:testpackage, or an exported-behavior test through incidentName.
  3. incidentName comment. The comment above the slug explains why, which is acceptable under CLAUDE.md. Its wording would be clearer if it said the slug keeps same-minute alarms on one instance apart.

No bugs found in this change. The tests and docs are consistent with the code. Item 2 is the only one I'd consider before merging.
· branch dashboard-incidents

coryodaniel and others added 2 commits November 27, 2026 22:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel

coryodaniel commented Nov 28, 2026 •

Copy link
Copy Markdown
Member Author

Fixed in 3b122af: TestWriteupFileNames covers how alarm names shorten into file names: punctuation collapsing, a long name cut to 32 characters, and a name with no letters leaving the slug out. Test-only, so I'm not asking for another review.

Base automatically changed from dashboard-actions to dashboard November 30, 2026 06:12
@coryodaniel
coryodaniel merged commit e91c916 into dashboard Nov 30, 2026
2 checks passed
@coryodaniel
coryodaniel deleted the dashboard-incidents branch November 30, 2026 06:13
@coryodaniel

Copy link
Copy Markdown
Member Author

Folded into #272.

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.

1 participant