feat(api): backfill alert name and tags - #3029
Conversation
π¦ Changeset detectedLatest commit: ea67086 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
π΄ Tier 4 β CriticalTouches authentication, tenancy data models, the public API or shipped database config β or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
Greptile SummaryThe PR adds an idempotent startup migration that derives missing alert names and tags from saved searches, dashboard tiles, or inline chart configuration, and makes malformed alert title templates fall back to their raw text.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking scalability concern in how the startup migration discovers records to batch. The migration's writes are guarded and its behavioral changes are covered, but every API restart performs an unindexed scan and retains all matching alert IDs before bounded processing begins. Files Needing Attention: packages/api/src/migrations.ts
|
| Filename | Overview |
|---|---|
| packages/api/src/migrations.ts | Adds derivation and conditional bulk backfill logic, but its initial query loads every matching alert ID into memory before batching. |
| packages/api/src/server.ts | Invokes the idempotent alert backfill after connecting to MongoDB on every API startup. |
| packages/api/src/models/alert.ts | Adds an optional string-array tags field without changing existing alert requirements. |
| packages/api/src/tasks/checkAlerts/template.ts | Compiles alert title templates once and intentionally falls back to raw text when rendering fails. |
| packages/api/src/tests/migrations.int.test.ts | Covers persisted backfill results, dangling references, legacy alerts, preservation of populated values, and reruns. |
| packages/api/src/tests/migrations.test.ts | Covers source-specific derivation, normalization, fallback names, and maximum name length. |
| packages/api/src/tasks/checkAlerts/tests/renderAlertTemplate.int.test.ts | Covers valid title interpolation and the intentional malformed-template fallback. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Start[API startup] --> Connect[Connect to MongoDB]
Connect --> Query[Find alerts missing name or tags]
Query --> Batch[Process alert IDs in batches]
Batch --> Sources[Load referenced saved searches and dashboards]
Sources --> Derive[Derive normalized name and tags]
Derive --> Write[Conditionally bulk-update alerts]
Write --> Serve[Complete startup]
Reviews (1): Last reviewed commit: "feat(api): backfill alert name and tags ..." | Re-trigger Greptile
| export async function backfillAlertNameAndTags() { | ||
| const ids = ( | ||
| await Alert.find( | ||
| { $or: [NAME_MISSING_FILTER, ...TAGS_MISSING_FILTER.$or] }, | ||
| { _id: 1 }, | ||
| ).lean() | ||
| ).map(doc => doc._id); |
There was a problem hiding this comment.
Backfill materializes every matching ID
If an installation has a large alerts collection, this unindexed query scans the collection and retains every matching alert ID in memory before the 500-record batching begins. Because the migration runs on every API startup, this adds repeated database load and potentially high process-memory usage; discover records incrementally with a cursor or pagination so the batch bound applies to the initial read as well.
Deep Reviewβ
No critical issues found. The largest reviewer claim β that the startup backfill blocks Kubernetes readiness and can crash-loop a rollout β was refuted by inspection: π‘ P2 -- recommended
π΅ P3 nitpicks (7)
Reviewers (8): correctness, testing, maintainability, data-migrations, reliability, adversarial, performance, kieran-typescript. Testing gaps:
Note on prior comments: the 2 existing PR comments are automated (changeset-bot, vercel-bot) with no substantive human feedback to verify, so the previous-comments reviewer was not spawned. |
E2E Test Resultsβ All tests passed β’ 324 passed β’ 1 skipped β’ 1124s
Tests ran across 4 shards in parallel. |
Summary
Backfills alert
nameandtagsfrom the referenced saved search, dashboard tile, or inline chart config.runStartupMigrations()called fromServer.start(). Idempotent and re-runs on every start, alerts with an existing name or tags are skipped.tagsfield to the Alert model.alert.nameis also used as the notification title template, a name that isn't valid Handlebars now renders as is to avoid breaking the notification.Tested with
make dev-int FILE=src/__tests__/migrations.int.test.tsandFILE=renderAlertTemplate.int.test.ts, plus unit tests for the name/tags derivation.References