Alerting: Extend recording rule definitions/interfaces with data source. (#101678)
Extend the recording rule definition to include the target data source, allowing configuration of where the output of the recording rule is written to. Also extends the relevant interfaces in preparation for the next set of changes.
This commit is contained in:
@@ -494,13 +494,21 @@ func NotificationSettingsFromAlertRuleNotificationSettings(ns *definitions.Alert
|
||||
}
|
||||
}
|
||||
|
||||
func pointerOmitEmpty(s string) *string {
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func AlertRuleRecordExportFromRecord(r *models.Record) *definitions.AlertRuleRecordExport {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
return &definitions.AlertRuleRecordExport{
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
TargetDatasourceUID: pointerOmitEmpty(r.TargetDatasourceUID),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,8 +517,9 @@ func ModelRecordFromApiRecord(r *definitions.Record) *models.Record {
|
||||
return nil
|
||||
}
|
||||
return &models.Record{
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
TargetDatasourceUID: r.TargetDatasourceUID,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,8 +528,9 @@ func ApiRecordFromModelRecord(r *models.Record) *definitions.Record {
|
||||
return nil
|
||||
}
|
||||
return &definitions.Record{
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
Metric: r.Metric,
|
||||
From: r.From,
|
||||
TargetDatasourceUID: r.TargetDatasourceUID,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -533,6 +533,10 @@ type Record struct {
|
||||
// required: true
|
||||
// example: A
|
||||
From string `json:"from" yaml:"from"`
|
||||
// Which data source should be used to write the output of the recording rule, specified by UID.
|
||||
// required: false
|
||||
// example: my-prom
|
||||
TargetDatasourceUID string `json:"target_datasource_uid,omitempty" yaml:"target_datasource_uid,omitempty"`
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
|
||||
@@ -308,6 +308,7 @@ type AlertRuleNotificationSettingsExport struct {
|
||||
|
||||
// Record is the provisioned export of models.Record.
|
||||
type AlertRuleRecordExport struct {
|
||||
Metric string `json:"metric" yaml:"metric" hcl:"metric"`
|
||||
From string `json:"from" yaml:"from" hcl:"from"`
|
||||
Metric string `json:"metric" yaml:"metric" hcl:"metric"`
|
||||
From string `json:"from" yaml:"from" hcl:"from"`
|
||||
TargetDatasourceUID *string `json:"targetDatasourceUid,omitempty" yaml:"targetDatasourceUid,omitempty" hcl:"target_datasource_uid,optional"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user