Alerting: Add rule_limit parameter to the list rules API (#114055)

This commit is contained in:
Alexander Akhmetov
2025-11-18 15:56:40 +01:00
committed by GitHub
parent 66259bdede
commit 633c9a9cb0
6 changed files with 333 additions and 3 deletions
+7 -1
View File
@@ -234,12 +234,13 @@ func (f *RuleStore) ListAlertRulesByGroup(_ context.Context, q *models.ListAlert
}
}
if q.Limit < 0 {
if q.Limit < 0 && q.RuleLimit < 0 {
return ruleList, "", nil
}
outputRules := make([]*models.AlertRule, 0, len(ruleList))
var groupsFetched int64
var rulesFetched int64
initialCursor := cursor
for _, r := range ruleList {
// skip rules before the initial cursor
@@ -258,11 +259,16 @@ func (f *RuleStore) ListAlertRulesByGroup(_ context.Context, q *models.ListAlert
nextToken = models.EncodeGroupCursor(cursor)
break
}
if q.RuleLimit > 0 && rulesFetched >= q.RuleLimit {
nextToken = models.EncodeGroupCursor(cursor)
break
}
cursor = key
groupsFetched++
}
outputRules = append(outputRules, r)
rulesFetched++
}
return outputRules, nextToken, nil