fix(pg): alert_history retention never ran; resolve state lost on restart - #30
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(pg): alert_history retention never ran; resolve state lost on restart#30cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
cleanupAlertHistory deleted by nonexistent ts/created_at columns so retention never ran. resolveAlertRecord updated only resolved_at while loadRecentAlerts restored JSONB as still firing after restart. Co-authored-by: Ethan <sreyun@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug and impact
cleanupAlertHistoryissuedDELETE … WHERE ts/created_at, but bootstrap only createsfired_at. Errors were discarded, soRetention.AlertHistoryDayshad no effect and the table grew without bound on PG deployments.resolveAlertRecordupdated only theresolved_atcolumn;loadRecentAlertsrebuilt memory from JSONB (status=firing,resolved_at=0)./api/v1/alerts/history?status=firingshowed ghosts; MTTR/history reporting was wrong. Resolve also matched PGBIGSERIAL idagainst the in-memoryalertSeq, which diverges after a failed insert.Root cause
Stale cleanup SQL against the wrong columns; resolve/load asymmetry between the relational column and JSONB payload; async insert + id-based update.
Fix
fired_at < cutand log failures.keyand update bothresolved_atand JSONBstatus/resolved_at.resolved_atonto JSONB records.licenseResetForTest,classicAppJS) so./cmd/servertests compile after license/Vue v2 removal.Validation
go test -count=1 -run 'TestCleanupAlertHistoryUsesFiredAt|TestResolveAlertRecord|TestLoadRecentAlerts|TestStoreAlertHistory|TestMetricsEndpointAuthAndPayload|TestSweepSkipsInflight' ./cmd/server/go build ./cmd/server ./cmd/agent