Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/mimir/rules/kubernetes/debug.go
4096 views
1
package rules
2
3
import "fmt"
4
5
type DebugInfo struct {
6
Error string `river:"error,attr,optional"`
7
PrometheusRules []DebugK8sPrometheusRule `river:"prometheus_rule,block,optional"`
8
MimirRuleNamespaces []DebugMimirNamespace `river:"mimir_rule_namespace,block,optional"`
9
}
10
11
type DebugK8sPrometheusRule struct {
12
Namespace string `river:"namespace,attr"`
13
Name string `river:"name,attr"`
14
UID string `river:"uid,attr"`
15
NumRuleGroups int `river:"num_rule_groups,attr"`
16
}
17
18
type DebugMimirNamespace struct {
19
Name string `river:"name,attr"`
20
NumRuleGroups int `river:"num_rule_groups,attr"`
21
}
22
23
func (c *Component) DebugInfo() interface{} {
24
var output DebugInfo
25
for ns := range c.currentState {
26
if !isManagedMimirNamespace(c.args.MimirNameSpacePrefix, ns) {
27
continue
28
}
29
30
output.MimirRuleNamespaces = append(output.MimirRuleNamespaces, DebugMimirNamespace{
31
Name: ns,
32
NumRuleGroups: len(c.currentState[ns]),
33
})
34
}
35
36
// This should load from the informer cache, so it shouldn't fail under normal circumstances.
37
managedK8sNamespaces, err := c.namespaceLister.List(c.namespaceSelector)
38
if err != nil {
39
return DebugInfo{
40
Error: fmt.Sprintf("failed to list namespaces: %v", err),
41
}
42
}
43
44
for _, n := range managedK8sNamespaces {
45
// This should load from the informer cache, so it shouldn't fail under normal circumstances.
46
rules, err := c.ruleLister.PrometheusRules(n.Name).List(c.ruleSelector)
47
if err != nil {
48
return DebugInfo{
49
Error: fmt.Sprintf("failed to list rules: %v", err),
50
}
51
}
52
53
for _, r := range rules {
54
output.PrometheusRules = append(output.PrometheusRules, DebugK8sPrometheusRule{
55
Namespace: n.Name,
56
Name: r.Name,
57
UID: string(r.UID),
58
NumRuleGroups: len(r.Spec.Groups),
59
})
60
}
61
}
62
63
return output
64
}
65
66