Alerting: Support recording rule struct in provisioning API (#87849)
* Support record struct in provisioning API * Update api spec * Use record field * Restrict API endpoints following toggle * Fix swagger spec * Add recording rule validation to store validator
This commit is contained in:
@@ -32,9 +32,7 @@ func AlertRuleFromProvisionedAlertRule(a definitions.ProvisionedAlertRule) (mode
|
||||
Labels: a.Labels,
|
||||
IsPaused: a.IsPaused,
|
||||
NotificationSettings: NotificationSettingsFromAlertRuleNotificationSettings(a.NotificationSettings),
|
||||
// Recording Rule fields will be implemented in the future.
|
||||
// For now, no rules can be recording rules. So, we force these to be empty.
|
||||
Record: nil,
|
||||
Record: ModelRecordFromApiRecord(a.Record),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -58,6 +56,7 @@ func ProvisionedAlertRuleFromAlertRule(rule models.AlertRule, provenance models.
|
||||
Provenance: definitions.Provenance(provenance), // TODO validate enum conversion?
|
||||
IsPaused: rule.IsPaused,
|
||||
NotificationSettings: AlertRuleNotificationSettingsFromNotificationSettings(rule.NotificationSettings),
|
||||
Record: ApiRecordFromModelRecord(rule.Record),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +191,7 @@ func AlertRuleExportFromAlertRule(rule models.AlertRule) (definitions.AlertRuleE
|
||||
ExecErrState: definitions.ExecutionErrorState(rule.ExecErrState),
|
||||
IsPaused: rule.IsPaused,
|
||||
NotificationSettings: AlertRuleNotificationSettingsExportFromNotificationSettings(rule.NotificationSettings),
|
||||
Record: AlertRuleRecordExportFromRecord(rule.Record),
|
||||
}
|
||||
if rule.For.Seconds() > 0 {
|
||||
result.ForString = util.Pointer(model.Duration(rule.For).String())
|
||||
@@ -456,11 +456,11 @@ func NotificationSettingsFromAlertRuleNotificationSettings(ns *definitions.Alert
|
||||
}
|
||||
}
|
||||
|
||||
func ApiRecordFromModelRecord(r *models.Record) *definitions.Record {
|
||||
func AlertRuleRecordExportFromRecord(r *models.Record) *definitions.AlertRuleRecordExport {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
return &definitions.Record{
|
||||
return &definitions.AlertRuleRecordExport{
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
}
|
||||
@@ -475,3 +475,13 @@ func ModelRecordFromApiRecord(r *definitions.Record) *models.Record {
|
||||
From: r.From,
|
||||
}
|
||||
}
|
||||
|
||||
func ApiRecordFromModelRecord(r *models.Record) *definitions.Record {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
return &definitions.Record{
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user