Compare commits

...

1 Commits

Author SHA1 Message Date
Nikhil Soni
cbb30cb60e fix: handle legacy alert type values on patch 2026-05-07 13:51:53 +05:30
2 changed files with 10 additions and 0 deletions

View File

@@ -952,6 +952,7 @@ func (m *Manager) PatchRule(ctx context.Context, ruleStr string, id valuer.UUID)
m.logger.ErrorContext(ctx, "failed to unmarshal rule from db", slog.String("rule.id", id.StringValue()), errors.Attr(err))
return nil, err
}
storedRule.NormalizeAlertType()
if err := json.Unmarshal([]byte(ruleStr), &storedRule); err != nil {
m.logger.ErrorContext(ctx, "failed to unmarshal patched rule with given id", slog.String("rule.id", id.StringValue()), errors.Attr(err))

View File

@@ -36,6 +36,15 @@ func (AlertType) Enum() []any {
}
}
// NormalizeAlertType corrects known legacy alert type values that were stored
// before strict validation was introduced. The corrected value is persisted on
// the next write, so the DB self-heals without a migration.
func (r *PostableRule) NormalizeAlertType() {
if r.AlertType == "LOG_BASED_ALERT" {
r.AlertType = AlertTypeLogs
}
}
const (
DefaultSchemaVersion = "v1"
SchemaVersionV2Alpha1 = "v2alpha1"