MCPcopy Index your code
hub / github.com/cortexproject/cortex / ListRules

Method ListRules

pkg/ruler/api.go:500–532  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

498}
499
500func (a *API) ListRules(w http.ResponseWriter, req *http.Request) {
501 logger := util_log.WithContext(req.Context(), a.logger)
502
503 userID, namespace, _, err := parseRequest(req, false, false)
504 if err != nil {
505 util_api.RespondError(logger, w, v1.ErrBadData, err.Error(), http.StatusBadRequest)
506 return
507 }
508
509 level.Debug(logger).Log("msg", "retrieving rule groups with namespace", "userID", userID, "namespace", namespace)
510 rgs, err := a.store.ListRuleGroupsForUserAndNamespace(req.Context(), userID, namespace)
511 if err != nil {
512 http.Error(w, err.Error(), http.StatusBadRequest)
513 return
514 }
515
516 if len(rgs) == 0 {
517 level.Info(logger).Log("msg", "no rule groups found", "userID", userID)
518 http.Error(w, ErrNoRuleGroups.Error(), http.StatusNotFound)
519 return
520 }
521
522 _, err = a.store.LoadRuleGroups(req.Context(), map[string]rulespb.RuleGroupList{userID: rgs})
523 if err != nil {
524 http.Error(w, err.Error(), http.StatusBadRequest)
525 return
526 }
527
528 level.Debug(logger).Log("msg", "retrieved rule groups from rule store", "userID", userID, "num_namespaces", len(rgs))
529
530 formatted := rgs.Formatted()
531 marshalAndSend(formatted, w, logger)
532}
533
534func (a *API) GetRuleGroup(w http.ResponseWriter, req *http.Request) {
535 logger := util_log.WithContext(req.Context(), a.logger)

Callers

nothing calls this directly

Calls 8

parseRequestFunction · 0.85
marshalAndSendFunction · 0.85
FormattedMethod · 0.80
LoadRuleGroupsMethod · 0.65
ContextMethod · 0.45
ErrorMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected