Alerting: Add provisioning endpoint to fetch all rules (#59989)

* Domain layer api for fetching all rules

* Add endpoint for getting all rules
This commit is contained in:
Alexander Weaver
2022-12-13 11:54:08 +01:00
committed by GitHub
parent d6bd3c4fb6
commit e97b43cd58
10 changed files with 163 additions and 18 deletions
@@ -7,6 +7,13 @@ import (
"github.com/prometheus/common/model"
)
// swagger:route GET /api/v1/provisioning/alert-rules provisioning stable RouteGetAlertRules
//
// Get all the alert rules.
//
// Responses:
// 200: ProvisionedAlertRules
// swagger:route GET /api/v1/provisioning/alert-rules/{UID} provisioning stable RouteGetAlertRule
//
// Get a specific alert rule by UID.
@@ -63,6 +70,9 @@ type AlertRuleHeaders struct {
XDisableProvenance string `json:"X-Disable-Provenance"`
}
// swagger:model
type ProvisionedAlertRules []ProvisionedAlertRule
type ProvisionedAlertRule struct {
ID int64 `json:"id"`
UID string `json:"uid"`
@@ -142,6 +152,14 @@ func NewAlertRule(rule models.AlertRule, provenance models.Provenance) Provision
}
}
func NewAlertRules(rules []*models.AlertRule) ProvisionedAlertRules {
result := make([]ProvisionedAlertRule, 0, len(rules))
for _, r := range rules {
result = append(result, NewAlertRule(*r, models.ProvenanceNone))
}
return result
}
// swagger:route GET /api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group} provisioning stable RouteGetAlertRuleGroup
//
// Get a rule group.