diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 39d07383c..a8888a17b 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -1155,15 +1155,15 @@ type RuleGroup struct { // 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. - Rules []rule `json:"rules"` + Rules []Rule `json:"rules"` Interval float64 `json:"interval"` EvaluationTime float64 `json:"evaluationTime"` LastEvaluation time.Time `json:"lastEvaluation"` } -type rule interface{} +type Rule interface{} -type alertingRule struct { +type AlertingRule struct { // State can be "pending", "firing", "inactive". State string `json:"state"` Name string `json:"name"` @@ -1180,7 +1180,7 @@ type alertingRule struct { Type string `json:"type"` } -type recordingRule struct { +type RecordingRule struct { Name string `json:"name"` Query string `json:"query"` Labels labels.Labels `json:"labels,omitempty"` @@ -1209,12 +1209,12 @@ func (api *API) rules(r *http.Request) apiFuncResult { Name: grp.Name(), File: grp.File(), Interval: grp.Interval().Seconds(), - Rules: []rule{}, + Rules: []Rule{}, EvaluationTime: grp.GetEvaluationTime().Seconds(), LastEvaluation: grp.GetLastEvaluation(), } for _, r := range grp.Rules() { - var enrichedRule rule + var enrichedRule Rule lastError := "" if r.LastError() != nil { @@ -1225,7 +1225,7 @@ func (api *API) rules(r *http.Request) apiFuncResult { if !returnAlerts { break } - enrichedRule = alertingRule{ + enrichedRule = AlertingRule{ State: rule.State().String(), Name: rule.Name(), Query: rule.Query().String(), @@ -1243,7 +1243,7 @@ func (api *API) rules(r *http.Request) apiFuncResult { if !returnRecording { break } - enrichedRule = recordingRule{ + enrichedRule = RecordingRule{ Name: rule.Name(), Query: rule.Query().String(), Labels: rule.Labels(), diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 5112201f4..be21a61ba 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -1472,8 +1472,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Name: "grp", File: "/path/to/file", Interval: 1, - Rules: []rule{ - alertingRule{ + Rules: []Rule{ + AlertingRule{ State: "inactive", Name: "test_metric3", Query: "absent(test_metric3) != 1", @@ -1484,7 +1484,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Health: "unknown", Type: "alerting", }, - alertingRule{ + AlertingRule{ State: "inactive", Name: "test_metric4", Query: "up == 1", @@ -1495,7 +1495,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Health: "unknown", Type: "alerting", }, - recordingRule{ + RecordingRule{ Name: "recording-rule-1", Query: "vector(1)", Labels: labels.Labels{}, @@ -1518,8 +1518,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Name: "grp", File: "/path/to/file", Interval: 1, - Rules: []rule{ - alertingRule{ + Rules: []Rule{ + AlertingRule{ State: "inactive", Name: "test_metric3", Query: "absent(test_metric3) != 1", @@ -1530,7 +1530,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Health: "unknown", Type: "alerting", }, - alertingRule{ + AlertingRule{ State: "inactive", Name: "test_metric4", Query: "up == 1", @@ -1557,8 +1557,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Name: "grp", File: "/path/to/file", Interval: 1, - Rules: []rule{ - recordingRule{ + Rules: []Rule{ + RecordingRule{ Name: "recording-rule-1", Query: "vector(1)", Labels: labels.Labels{},