Files
grafana/pkg/services/ngalert/api/tooling/definitions/prom.go
T
gotjosh 6572017ec7 Alerting: Allow more characters in label names so notifications are sent (#38629)
Remove validation for labels to be accepted in the Alertmanager, This helps with datasources that produce non-compatible labels.

Adds an "object_matchers" to alert manager routers so we can support labels names with extended characters beyond prometheus/openmetrics. It only does this for the internal Grafana managed Alert Manager.

This requires a change to alert manager, so for now we use grafana/alertmanager which is a slight fork, with the intention of going back to upstream.

The frontend handles the migration of "matchers" -> "object_matchers" when the route is edited and saved. Once this is done, downgrades will not work old versions will not recognize the "object_matchers".

Co-authored-by: Kyle Brandt <kyle@grafana.com>
Co-authored-by: Nathan Rodman <nathanrodman@gmail.com>
2021-10-04 15:06:40 +02:00

131 lines
3.1 KiB
Go

package definitions
import (
"time"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
)
// swagger:route GET /api/prometheus/{Recipient}/api/v1/rules prometheus RouteGetRuleStatuses
//
// gets the evaluation statuses of all rules
//
// Responses:
// 200: RuleResponse
// swagger:route GET /api/prometheus/{Recipient}/api/v1/alerts prometheus RouteGetAlertStatuses
//
// gets the current alerts
//
// Responses:
// 200: AlertResponse
// swagger:model
type RuleResponse struct {
// in: body
DiscoveryBase
// in: body
Data RuleDiscovery `json:"data"`
}
// swagger:model
type AlertResponse struct {
// in: body
DiscoveryBase
// in: body
Data AlertDiscovery `json:"data"`
}
// swagger:model
type DiscoveryBase struct {
// required: true
Status string `json:"status"`
// required: false
ErrorType v1.ErrorType `json:"errorType,omitempty"`
// required: false
Error string `json:"error,omitempty"`
}
// swagger:model
type RuleDiscovery struct {
// required: true
RuleGroups []*RuleGroup `json:"groups"`
}
// AlertDiscovery has info for all active alerts.
// swagger:model
type AlertDiscovery struct {
// required: true
Alerts []*Alert `json:"alerts"`
}
// swagger:model
type RuleGroup struct {
// required: true
Name string `json:"name"`
// required: true
File string `json:"file"`
// In order to preserve rule ordering, while exposing type (alerting or recording)
// specific properties, both alerting and recording rules are exposed in the
// same array.
// required: true
Rules []AlertingRule `json:"rules"`
// required: true
Interval float64 `json:"interval"`
LastEvaluation time.Time `json:"lastEvaluation"`
EvaluationTime float64 `json:"evaluationTime"`
}
// adapted from cortex
// swagger:model
type AlertingRule struct {
// State can be "pending", "firing", "inactive".
// required: true
State string `json:"state,omitempty"`
// required: true
Name string `json:"name,omitempty"`
// required: true
Query string `json:"query,omitempty"`
Duration float64 `json:"duration,omitempty"`
// required: true
Annotations overrideLabels `json:"annotations,omitempty"`
// required: true
Alerts []*Alert `json:"alerts,omitempty"`
Rule
}
// adapted from cortex
// swagger:model
type Rule struct {
// required: true
Name string `json:"name"`
// required: true
Query string `json:"query"`
Labels overrideLabels `json:"labels"`
// required: true
Health string `json:"health"`
LastError string `json:"lastError"`
// required: true
Type v1.RuleType `json:"type"`
LastEvaluation time.Time `json:"lastEvaluation"`
EvaluationTime float64 `json:"evaluationTime"`
}
// Alert has info for an alert.
// swagger:model
type Alert struct {
// required: true
Labels overrideLabels `json:"labels"`
// required: true
Annotations overrideLabels `json:"annotations"`
// required: true
State string `json:"state"`
ActiveAt *time.Time `json:"activeAt"`
// required: true
Value string `json:"value"`
}
// override the labels type with a map for generation.
// The custom marshaling for labels.Labels ends up doing this anyways.
type overrideLabels map[string]string