Skip to content
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

config: Add option to auto-close acked alerts #3604

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type Config struct {
}

Maintenance struct {
AlertCleanupDays int `public:"true" info:"Closed alerts will be deleted after this many days (0 means disable cleanup)."`
AlertAutoCloseDays int `public:"true" info:"Unacknowledged alerts will automatically be closed after this many days of inactivity. (0 means disable auto-close)."`
APIKeyExpireDays int `public:"true" info:"Unused calendar API keys will be disabled after this many days (0 means disable cleanup)."`
ScheduleCleanupDays int `public:"true" info:"Schedule on-call history will be deleted after this many days (0 means disable cleanup)."`
AlertCleanupDays int `public:"true" info:"Closed alerts will be deleted after this many days (0 means disable cleanup)."`
AlertAutoCloseDays int `public:"true" info:"Unacknowledged alerts will automatically be closed after this many days of inactivity. (0 means disable auto-close)."`
AutoCloseAckedAlerts bool `public:"true" info:"If set, alerts that are acknowledged will also be automatically closed after the configured number of days of inactivity."`
APIKeyExpireDays int `public:"true" info:"Unused calendar API keys will be disabled after this many days (0 means disable cleanup)."`
ScheduleCleanupDays int `public:"true" info:"Schedule on-call history will be deleted after this many days (0 means disable cleanup)."`
}

Auth struct {
Expand Down
6 changes: 3 additions & 3 deletions engine/cleanupmanager/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type DB struct {
cleanupOverrides *sql.Stmt
cleanupSchedOnCall *sql.Stmt
cleanupEPOnCall *sql.Stmt
unackAlerts *sql.Stmt
staleAlerts *sql.Stmt
alertStore *alert.Store

logIndex int
Expand Down Expand Up @@ -94,10 +94,10 @@ func NewDB(ctx context.Context, db *sql.DB, alertstore *alert.Store) (*DB, error
cleanupOverrides: p.P(`DELETE FROM user_overrides WHERE id = ANY(SELECT id FROM user_overrides WHERE end_time < (now() - $1::interval) LIMIT 100 FOR UPDATE SKIP LOCKED)`),
cleanupSchedOnCall: p.P(`DELETE FROM schedule_on_call_users WHERE id = ANY(SELECT id FROM schedule_on_call_users WHERE end_time < (now() - $1::interval) LIMIT 100 FOR UPDATE SKIP LOCKED)`),
cleanupEPOnCall: p.P(`DELETE FROM ep_step_on_call_users WHERE id = ANY(SELECT id FROM ep_step_on_call_users WHERE end_time < (now() - $1::interval) LIMIT 100 FOR UPDATE SKIP LOCKED)`),
unackAlerts: p.P(`
staleAlerts: p.P(`
select id from alerts a
where
a.status='triggered' and
(a.status='triggered' or ($2 and a.status = 'active')) and
created_at <= now() - '1 day'::interval * $1 and
not exists (
select 1 from alert_logs log
Expand Down
2 changes: 1 addition & 1 deletion engine/cleanupmanager/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (db *DB) update(ctx context.Context) error {
}

if cfg.Maintenance.AlertAutoCloseDays > 0 {
rows, err := tx.StmtContext(ctx, db.unackAlerts).QueryContext(ctx, cfg.Maintenance.AlertAutoCloseDays)
rows, err := tx.StmtContext(ctx, db.staleAlerts).QueryContext(ctx, cfg.Maintenance.AlertAutoCloseDays, cfg.Maintenance.AutoCloseAckedAlerts)
if err != nil {
return fmt.Errorf("query auto-close alerts: %w", err)
}
Expand Down
8 changes: 8 additions & 0 deletions graphql2/mapconfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ type ConfigID =
| 'Services.RequiredLabels'
| 'Maintenance.AlertCleanupDays'
| 'Maintenance.AlertAutoCloseDays'
| 'Maintenance.AutoCloseAckedAlerts'
| 'Maintenance.APIKeyExpireDays'
| 'Maintenance.ScheduleCleanupDays'
| 'Auth.RefererURLs'
Expand Down