MCPcopy Create free account
hub / github.com/cortexproject/cortex / LoadRuleGroups

Method LoadRuleGroups

pkg/ruler/store_mock_test.go:232–264  ·  view source on GitHub ↗
(ctx context.Context, groupsToLoad map[string]rulespb.RuleGroupList)

Source from the content-addressed store, hash-verified

230}
231
232func (m *mockRuleStore) LoadRuleGroups(ctx context.Context, groupsToLoad map[string]rulespb.RuleGroupList) (map[string]rulespb.RuleGroupList, error) {
233 m.mtx.Lock()
234 defer m.mtx.Unlock()
235 result := make(map[string]rulespb.RuleGroupList, len(groupsToLoad))
236 var err error
237
238 gm := make(map[string]*rulespb.RuleGroupDesc)
239 for _, gs := range m.rules {
240 for _, gr := range gs {
241 user, namespace, name := gr.GetUser(), gr.GetNamespace(), gr.GetName()
242 key := user + delim + base64.URLEncoding.EncodeToString([]byte(namespace)) + delim + base64.URLEncoding.EncodeToString([]byte(name))
243 gm[key] = gr
244 }
245 }
246
247 for _, gs := range groupsToLoad {
248 for _, gr := range gs {
249 user, namespace, name := gr.GetUser(), gr.GetNamespace(), gr.GetName()
250 if e, ok := m.errorMap[user]; ok {
251 err = e
252 continue
253 }
254 key := user + delim + base64.URLEncoding.EncodeToString([]byte(namespace)) + delim + base64.URLEncoding.EncodeToString([]byte(name))
255 mgr, ok := gm[key]
256 if !ok {
257 return nil, fmt.Errorf("failed to get rule group user %s", gr.GetUser())
258 }
259 *gr = *mgr
260 result[user] = append(result[user], gr)
261 }
262 }
263 return result, err
264}
265
266func (m *mockRuleStore) GetRuleGroup(_ context.Context, userID string, namespace string, group string) (*rulespb.RuleGroupDesc, error) {
267 m.mtx.Lock()

Callers

nothing calls this directly

Calls 3

GetNamespaceMethod · 0.80
GetUserMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected