Skip to content

Commit

Permalink
Refactoring: expose filterRuleGroupsByNotMissing()
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci committed Dec 16, 2024
1 parent cf3cafd commit dc67cdf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/ruler/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func (a *API) ListRules(w http.ResponseWriter, req *http.Request) {
// so their content is empty).
numRuleGroupsBeforeFiltering := len(rgs)
tenantRuleGroups := map[string]rulespb.RuleGroupList{userID: rgs}
tenantRuleGroups = filterRuleGroupsByNotMissing(tenantRuleGroups, missing, a.logger)
tenantRuleGroups = FilterRuleGroupsByNotMissing(tenantRuleGroups, missing, a.logger)

var tenantFound bool
rgs, tenantFound = tenantRuleGroups[userID]
Expand Down
6 changes: 3 additions & 3 deletions pkg/ruler/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (r *Ruler) loadRuleGroupsToSync(ctx context.Context, configs map[string]rul
// cached for a short period of time. This means that some rule groups discovered by listing
// the bucket (cached) may no longer exist because deleted in the meanwhile. For this reason,
// we filter out any missing rule group, not considering it as an hard error.
configs = filterRuleGroupsByNotMissing(configs, missing, r.logger)
configs = FilterRuleGroupsByNotMissing(configs, missing, r.logger)

return configs, nil
}
Expand Down Expand Up @@ -888,11 +888,11 @@ func filterRuleGroupByEnabled(group *rulespb.RuleGroupDesc, recordingEnabled, al
return filtered, removedRules
}

// filterRuleGroupsByNotMissing filters out from the input configs all the rules groups which are in the missing list.
// FilterRuleGroupsByNotMissing filters out from the input configs all the rules groups which are in the missing list.
//
// This function doesn't modify the input configs in place (even if it could) in order to reduce the likelihood of introducing
// future bugs, in case the rule groups will be cached in memory.
func filterRuleGroupsByNotMissing(configs map[string]rulespb.RuleGroupList, missing rulespb.RuleGroupList, logger log.Logger) (filtered map[string]rulespb.RuleGroupList) {
func FilterRuleGroupsByNotMissing(configs map[string]rulespb.RuleGroupList, missing rulespb.RuleGroupList, logger log.Logger) (filtered map[string]rulespb.RuleGroupList) {
// Nothing to do if there are no missing rule groups.
if len(missing) == 0 {
return configs
Expand Down
2 changes: 1 addition & 1 deletion pkg/ruler/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ func TestFilterRuleGroupsByNotMissing(t *testing.T) {
t.Run(testName, func(t *testing.T) {
logger := log.NewNopLogger()

actual := filterRuleGroupsByNotMissing(testData.configs, testData.missing, logger)
actual := FilterRuleGroupsByNotMissing(testData.configs, testData.missing, logger)
assert.Equal(t, testData.expected, actual)
})
}
Expand Down

0 comments on commit dc67cdf

Please sign in to comment.