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:
Yuri Tseretyan
2023-09-26 12:45:22 -04:00
committed by GitHub
parent 918f11d81e
commit 237ce5ea82
2 changed files with 110 additions and 108 deletions
+12
View File
@@ -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
}