MCPcopy
hub / github.com/prometheus/prometheus / rules

Method rules

web/api/v1/api.go:1590–1748  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

1588}
1589
1590func (api *API) rules(r *http.Request) apiFuncResult {
1591 if err := r.ParseForm(); err != nil {
1592 return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
1593 }
1594
1595 queryFormToSet := func(values []string) map[string]struct{} {
1596 set := make(map[string]struct{}, len(values))
1597 for _, v := range values {
1598 set[v] = struct{}{}
1599 }
1600 return set
1601 }
1602
1603 rnSet := queryFormToSet(r.Form["rule_name[]"])
1604 rgSet := queryFormToSet(r.Form["rule_group[]"])
1605 fSet := queryFormToSet(r.Form["file[]"])
1606
1607 matcherSets, err := api.parseMatchersParam(r.Form["match[]"])
1608 if err != nil {
1609 return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
1610 }
1611
1612 ruleGroups := api.rulesRetriever(r.Context()).RuleGroups()
1613 res := &RuleDiscovery{RuleGroups: make([]*RuleGroup, 0, len(ruleGroups))}
1614 typ := strings.ToLower(r.URL.Query().Get("type"))
1615
1616 if typ != "" && typ != "alert" && typ != "record" {
1617 return invalidParamError(fmt.Errorf("not supported value %q", typ), "type")
1618 }
1619
1620 returnAlerts := typ == "" || typ == "alert"
1621 returnRecording := typ == "" || typ == "record"
1622
1623 excludeAlerts, err := parseExcludeAlerts(r)
1624 if err != nil {
1625 return invalidParamError(err, "exclude_alerts")
1626 }
1627
1628 maxGroups, nextToken, parseErr := parseListRulesPaginationRequest(r)
1629 if parseErr != nil {
1630 return *parseErr
1631 }
1632
1633 rgs := make([]*RuleGroup, 0, len(ruleGroups))
1634
1635 foundToken := false
1636
1637 for _, grp := range ruleGroups {
1638 if maxGroups > 0 && nextToken != "" && !foundToken {
1639 if nextToken != getRuleGroupNextToken(grp.File(), grp.Name()) {
1640 continue
1641 }
1642 foundToken = true
1643 }
1644
1645 if len(rgSet) > 0 {
1646 if _, ok := rgSet[grp.Name()]; !ok {
1647 continue

Callers

nothing calls this directly

Calls 15

parseMatchersParamMethod · 0.95
invalidParamErrorFunction · 0.85
parseExcludeAlertsFunction · 0.85
getRuleGroupNextTokenFunction · 0.85
rulesAlertsToAPIAlertsFunction · 0.85
IntervalMethod · 0.80
LimitMethod · 0.80
GetEvaluationTimeMethod · 0.80
GetLastEvaluationMethod · 0.80
ActiveAlertsMethod · 0.80
HoldDurationMethod · 0.80

Tested by

no test coverage detected