Path: blob/main/component/mimir/rules/kubernetes/debug.go
4096 views
package rules12import "fmt"34type DebugInfo struct {5Error string `river:"error,attr,optional"`6PrometheusRules []DebugK8sPrometheusRule `river:"prometheus_rule,block,optional"`7MimirRuleNamespaces []DebugMimirNamespace `river:"mimir_rule_namespace,block,optional"`8}910type DebugK8sPrometheusRule struct {11Namespace string `river:"namespace,attr"`12Name string `river:"name,attr"`13UID string `river:"uid,attr"`14NumRuleGroups int `river:"num_rule_groups,attr"`15}1617type DebugMimirNamespace struct {18Name string `river:"name,attr"`19NumRuleGroups int `river:"num_rule_groups,attr"`20}2122func (c *Component) DebugInfo() interface{} {23var output DebugInfo24for ns := range c.currentState {25if !isManagedMimirNamespace(c.args.MimirNameSpacePrefix, ns) {26continue27}2829output.MimirRuleNamespaces = append(output.MimirRuleNamespaces, DebugMimirNamespace{30Name: ns,31NumRuleGroups: len(c.currentState[ns]),32})33}3435// This should load from the informer cache, so it shouldn't fail under normal circumstances.36managedK8sNamespaces, err := c.namespaceLister.List(c.namespaceSelector)37if err != nil {38return DebugInfo{39Error: fmt.Sprintf("failed to list namespaces: %v", err),40}41}4243for _, n := range managedK8sNamespaces {44// This should load from the informer cache, so it shouldn't fail under normal circumstances.45rules, err := c.ruleLister.PrometheusRules(n.Name).List(c.ruleSelector)46if err != nil {47return DebugInfo{48Error: fmt.Sprintf("failed to list rules: %v", err),49}50}5152for _, r := range rules {53output.PrometheusRules = append(output.PrometheusRules, DebugK8sPrometheusRule{54Namespace: n.Name,55Name: r.Name,56UID: string(r.UID),57NumRuleGroups: len(r.Spec.Groups),58})59}60}6162return output63}646566