From 2f4289a3bfaca725a14f41e30f1c91de92936242 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 12 Jan 2022 09:14:22 +0530 Subject: [PATCH] add limit to the rules api (#10152) --- docs/querying/api.md | 1 + web/api/v1/api.go | 2 ++ web/api/v1/api_test.go | 3 +++ 3 files changed, 6 insertions(+) diff --git a/docs/querying/api.md b/docs/querying/api.md index 84d8c8f96..e3a8af787 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -620,6 +620,7 @@ $ curl http://localhost:9090/api/v1/rules ], "file": "/rules.yaml", "interval": 60, + "limit": 0, "name": "example" } ] diff --git a/web/api/v1/api.go b/web/api/v1/api.go index e6a6daffc..25918f791 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -1164,6 +1164,7 @@ type RuleGroup struct { // same array. Rules []Rule `json:"rules"` Interval float64 `json:"interval"` + Limit int `json:"limit"` EvaluationTime float64 `json:"evaluationTime"` LastEvaluation time.Time `json:"lastEvaluation"` } @@ -1216,6 +1217,7 @@ func (api *API) rules(r *http.Request) apiFuncResult { Name: grp.Name(), File: grp.File(), Interval: grp.Interval().Seconds(), + Limit: grp.Limit(), Rules: []Rule{}, EvaluationTime: grp.GetEvaluationTime().Seconds(), LastEvaluation: grp.GetLastEvaluation(), diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 74857ae93..5de0d60f8 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -1470,6 +1470,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Name: "grp", File: "/path/to/file", Interval: 1, + Limit: 0, Rules: []Rule{ AlertingRule{ State: "inactive", @@ -1516,6 +1517,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Name: "grp", File: "/path/to/file", Interval: 1, + Limit: 0, Rules: []Rule{ AlertingRule{ State: "inactive", @@ -1555,6 +1557,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E Name: "grp", File: "/path/to/file", Interval: 1, + Limit: 0, Rules: []Rule{ RecordingRule{ Name: "recording-rule-1",