Alerting: Extract methods for fetching rule groups with authorization (#75375)
* extract methods for fetching rule groups with authorization and refactor the request handlers. * add logging to delete handler
This commit is contained in:
@@ -571,3 +571,15 @@ func RuleKeyFromContext(ctx context.Context) (AlertRuleKey, bool) {
|
||||
key, ok := ctx.Value(ruleKeyContextKey{}).(AlertRuleKey)
|
||||
return key, ok
|
||||
}
|
||||
|
||||
// GroupByAlertRuleGroupKey groups all rules by AlertRuleGroupKey. Returns map of RulesGroup sorted by AlertRule.RuleGroupIndex
|
||||
func GroupByAlertRuleGroupKey(rules []*AlertRule) map[AlertRuleGroupKey]RulesGroup {
|
||||
result := make(map[AlertRuleGroupKey]RulesGroup)
|
||||
for _, rule := range rules {
|
||||
result[rule.GetGroupKey()] = append(result[rule.GetGroupKey()], rule)
|
||||
}
|
||||
for _, group := range result {
|
||||
group.SortByGroupIndex()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user