Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: expose filterRuleGroupsByNotMissing() #10250

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading