mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update ListAlertRulesQuery to take a slice of RuleGroups (#88385)
* Change ListAlertRulesQuery to take RuleGroup slice instead * Change func name * Change func name * Fix fakes * Fix function arg
This commit is contained in:
committed by
GitHub
parent
4c8ce76929
commit
543f0ae37e
@@ -363,17 +363,13 @@ func (st DBstore) ListAlertRules(ctx context.Context, query *ngmodels.ListAlertR
|
||||
}
|
||||
|
||||
if len(query.NamespaceUIDs) > 0 {
|
||||
args := make([]any, 0, len(query.NamespaceUIDs))
|
||||
in := make([]string, 0, len(query.NamespaceUIDs))
|
||||
for _, namespaceUID := range query.NamespaceUIDs {
|
||||
args = append(args, namespaceUID)
|
||||
in = append(in, "?")
|
||||
}
|
||||
args, in := getINSubQueryArgs(query.NamespaceUIDs)
|
||||
q = q.Where(fmt.Sprintf("namespace_uid IN (%s)", strings.Join(in, ",")), args...)
|
||||
}
|
||||
|
||||
if query.RuleGroup != "" {
|
||||
q = q.Where("rule_group = ?", query.RuleGroup)
|
||||
if len(query.RuleGroups) > 0 {
|
||||
args, in := getINSubQueryArgs(query.RuleGroups)
|
||||
q = q.Where(fmt.Sprintf("rule_group IN (%s)", strings.Join(in, ",")), args...)
|
||||
}
|
||||
|
||||
if query.ReceiverName != "" {
|
||||
@@ -789,3 +785,14 @@ func (st DBstore) GetNamespacesByRuleUID(ctx context.Context, orgID int64, uids
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
func getINSubQueryArgs[T any](inputSlice []T) ([]any, []string) {
|
||||
args := make([]any, 0, len(inputSlice))
|
||||
in := make([]string, 0, len(inputSlice))
|
||||
for _, t := range inputSlice {
|
||||
args = append(args, t)
|
||||
in = append(in, "?")
|
||||
}
|
||||
|
||||
return args, in
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func CalculateChanges(ctx context.Context, ruleReader RuleReader, groupKey model
|
||||
q := &models.ListAlertRulesQuery{
|
||||
OrgID: groupKey.OrgID,
|
||||
NamespaceUIDs: []string{groupKey.NamespaceUID},
|
||||
RuleGroup: groupKey.RuleGroup,
|
||||
RuleGroups: []string{groupKey.RuleGroup},
|
||||
}
|
||||
existingGroupRules, err := ruleReader.ListAlertRules(ctx, q)
|
||||
if err != nil {
|
||||
@@ -203,7 +203,7 @@ func CalculateRuleUpdate(ctx context.Context, ruleReader RuleReader, rule *model
|
||||
q := &models.ListAlertRulesQuery{
|
||||
OrgID: rule.OrgID,
|
||||
NamespaceUIDs: []string{rule.NamespaceUID},
|
||||
RuleGroup: rule.RuleGroup,
|
||||
RuleGroups: []string{rule.RuleGroup},
|
||||
}
|
||||
existingGroupRules, err := ruleReader.ListAlertRules(ctx, q)
|
||||
if err != nil {
|
||||
@@ -232,7 +232,7 @@ func CalculateRuleGroupDelete(ctx context.Context, ruleReader RuleReader, groupK
|
||||
q := models.ListAlertRulesQuery{
|
||||
OrgID: groupKey.OrgID,
|
||||
NamespaceUIDs: []string{groupKey.NamespaceUID},
|
||||
RuleGroup: groupKey.RuleGroup,
|
||||
RuleGroups: []string{groupKey.RuleGroup},
|
||||
}
|
||||
ruleList, err := ruleReader.ListAlertRules(ctx, &q)
|
||||
if err != nil {
|
||||
@@ -288,7 +288,7 @@ func CalculateRuleCreate(ctx context.Context, ruleReader RuleReader, rule *model
|
||||
q := &models.ListAlertRulesQuery{
|
||||
OrgID: rule.OrgID,
|
||||
NamespaceUIDs: []string{rule.NamespaceUID},
|
||||
RuleGroup: rule.RuleGroup,
|
||||
RuleGroups: []string{rule.RuleGroup},
|
||||
}
|
||||
group, err := ruleReader.ListAlertRules(ctx, q)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user