Alerting: Support custom annotations and labels when testing contact points

Support custom annotations and labels when testing contact points
This commit is contained in:
George Robinson
2021-10-21 13:47:06 +01:00
committed by GitHub
parent 3abb355364
commit 967721068e
6 changed files with 591 additions and 130 deletions
+6 -2
View File
@@ -444,8 +444,12 @@ func contextWithTimeoutFromRequest(ctx context.Context, r *http.Request, default
func newTestReceiversResult(r *notifier.TestReceiversResult) apimodels.TestReceiversResult {
v := apimodels.TestReceiversResult{
Receivers: make([]apimodels.TestReceiverResult, len(r.Receivers)),
NotifedAt: r.NotifedAt,
Alert: apimodels.TestReceiversConfigAlertParams{
Annotations: r.Alert.Annotations,
Labels: r.Alert.Labels,
},
Receivers: make([]apimodels.TestReceiverResult, len(r.Receivers)),
NotifiedAt: r.NotifedAt,
}
for ix, next := range r.Receivers {
configs := make([]apimodels.TestReceiverConfigResult, len(next.Configs))
@@ -137,6 +137,8 @@ type MultiStatus struct{}
// swagger:parameters RoutePostTestReceivers
type TestReceiversConfigParams struct {
// in:body
Alert *TestReceiversConfigAlertParams `yaml:"alert,omitempty" json:"alert,omitempty"`
// in:body
Receivers []*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
}
@@ -145,10 +147,16 @@ func (c *TestReceiversConfigParams) ProcessConfig(encrypt EncryptFn) error {
return processReceiverConfigs(c.Receivers, encrypt)
}
type TestReceiversConfigAlertParams struct {
Annotations model.LabelSet `yaml:"annotations,omitempty" json:"annotations,omitempty"`
Labels model.LabelSet `yaml:"labels,omitempty" json:"labels,omitempty"`
}
// swagger:model
type TestReceiversResult struct {
Receivers []TestReceiverResult `json:"receivers"`
NotifedAt time.Time `json:"notified_at"`
Alert TestReceiversConfigAlertParams `json:"alert"`
Receivers []TestReceiverResult `json:"receivers"`
NotifiedAt time.Time `json:"notified_at"`
}
// swagger:model
+48 -10
View File
@@ -1065,6 +1065,19 @@
"type": "array",
"x-go-package": "github.com/prometheus/common/model"
},
"LabelSet": {
"additionalProperties": {
"$ref": "#/definitions/LabelValue"
},
"description": "A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet\nmay be fully-qualified down to the point where it may resolve to a single\nMetric in the data store or not. All operations that occur within the realm\nof a LabelSet can emit a vector of Metric entities to which the LabelSet may\nmatch.",
"type": "object",
"x-go-package": "github.com/prometheus/common/model"
},
"LabelValue": {
"title": "A LabelValue is an associated value for a LabelName.",
"type": "string",
"x-go-package": "github.com/prometheus/common/model"
},
"Labels": {
"description": "Labels is a sorted set of labels. Order has to be guaranteed upon\ninstantiation.",
"items": {
@@ -2403,12 +2416,27 @@
"type": "object",
"x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
},
"TestReceiversConfigAlertParams": {
"properties": {
"annotations": {
"$ref": "#/definitions/LabelSet"
},
"labels": {
"$ref": "#/definitions/LabelSet"
}
},
"type": "object",
"x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
},
"TestReceiversResult": {
"properties": {
"alert": {
"$ref": "#/definitions/TestReceiversConfigAlertParams"
},
"notified_at": {
"format": "date-time",
"type": "string",
"x-go-name": "NotifedAt"
"x-go-name": "NotifiedAt"
},
"receivers": {
"items": {
@@ -2649,6 +2677,7 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
},
"alertGroup": {
"description": "AlertGroup alert group",
"properties": {
"alerts": {
"description": "alerts",
@@ -2670,9 +2699,7 @@
"labels",
"receiver"
],
"type": "object",
"x-go-name": "AlertGroup",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
"type": "object"
},
"alertGroups": {
"items": {
@@ -2869,7 +2896,6 @@
"type": "array"
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
"properties": {
"comment": {
"description": "comment",
@@ -2921,14 +2947,17 @@
"status",
"updatedAt"
],
"type": "object"
"type": "object",
"x-go-name": "GettableSilence",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"items": {
"$ref": "#/definitions/gettableSilence"
},
"type": "array"
"type": "array",
"x-go-name": "GettableSilences",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
},
"labelSet": {
"additionalProperties": {
@@ -3101,7 +3130,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
},
"receiver": {
"description": "Receiver receiver",
"properties": {
"name": {
"description": "name",
@@ -3112,7 +3140,9 @@
"required": [
"name"
],
"type": "object"
"type": "object",
"x-go-name": "Receiver",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
},
"silence": {
"description": "Silence silence",
@@ -3699,6 +3729,14 @@
"post": {
"operationId": "RoutePostTestReceivers",
"parameters": [
{
"in": "body",
"name": "alert",
"schema": {
"$ref": "#/definitions/TestReceiversConfigAlertParams"
},
"x-go-name": "Alert"
},
{
"in": "body",
"name": "receivers",
+44 -6
View File
@@ -493,6 +493,14 @@
"summary": "Test Grafana managed receivers without saving them.",
"operationId": "RoutePostTestReceivers",
"parameters": [
{
"x-go-name": "Alert",
"name": "alert",
"in": "body",
"schema": {
"$ref": "#/definitions/TestReceiversConfigAlertParams"
}
},
{
"x-go-name": "Receivers",
"name": "receivers",
@@ -2090,6 +2098,19 @@
},
"x-go-package": "github.com/prometheus/common/model"
},
"LabelSet": {
"description": "A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet\nmay be fully-qualified down to the point where it may resolve to a single\nMetric in the data store or not. All operations that occur within the realm\nof a LabelSet can emit a vector of Metric entities to which the LabelSet may\nmatch.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/LabelValue"
},
"x-go-package": "github.com/prometheus/common/model"
},
"LabelValue": {
"type": "string",
"title": "A LabelValue is an associated value for a LabelName.",
"x-go-package": "github.com/prometheus/common/model"
},
"Labels": {
"description": "Labels is a sorted set of labels. Order has to be guaranteed upon\ninstantiation.",
"type": "array",
@@ -3429,13 +3450,28 @@
},
"x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
},
"TestReceiversConfigAlertParams": {
"type": "object",
"properties": {
"annotations": {
"$ref": "#/definitions/LabelSet"
},
"labels": {
"$ref": "#/definitions/LabelSet"
}
},
"x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
},
"TestReceiversResult": {
"type": "object",
"properties": {
"alert": {
"$ref": "#/definitions/TestReceiversConfigAlertParams"
},
"notified_at": {
"type": "string",
"format": "date-time",
"x-go-name": "NotifedAt"
"x-go-name": "NotifiedAt"
},
"receivers": {
"type": "array",
@@ -3675,6 +3711,7 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
},
"alertGroup": {
"description": "AlertGroup alert group",
"type": "object",
"required": [
"alerts",
@@ -3697,8 +3734,6 @@
"$ref": "#/definitions/receiver"
}
},
"x-go-name": "AlertGroup",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/alertGroup"
},
"alertGroups": {
@@ -3899,7 +3934,6 @@
"$ref": "#/definitions/gettableAlerts"
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
"type": "object",
"required": [
"comment",
@@ -3952,14 +3986,17 @@
"x-go-name": "UpdatedAt"
}
},
"x-go-name": "GettableSilence",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/gettableSilence"
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"type": "array",
"items": {
"$ref": "#/definitions/gettableSilence"
},
"x-go-name": "GettableSilences",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/gettableSilences"
},
"labelSet": {
@@ -4134,7 +4171,6 @@
"$ref": "#/definitions/postableSilence"
},
"receiver": {
"description": "Receiver receiver",
"type": "object",
"required": [
"name"
@@ -4146,6 +4182,8 @@
"x-go-name": "Name"
}
},
"x-go-name": "Receiver",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/receiver"
},
"silence": {