-
Notifications
You must be signed in to change notification settings - Fork 53
/
types.go
44 lines (40 loc) · 938 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package rules
import (
"github.com/prometheus/prometheus/model/rulefmt"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"
)
// Alias so we can implement the Finder[T] interface
// on Prometheus' rulefmt.RuleGroup
type RuleGroup rulefmt.RuleGroup
type RuleGroupList []RuleGroup
func (r RuleGroup) Clone() RuleGroup {
cloned := RuleGroup{
Name: r.Name,
Interval: r.Interval,
Rules: make([]rulefmt.RuleNode, len(r.Rules)),
}
for i, r := range r.Rules {
cloned.Rules[i] = rulefmt.RuleNode{
Record: yaml.Node{
Kind: r.Record.Kind,
Tag: r.Record.Tag,
Value: r.Record.Value,
},
Alert: yaml.Node{
Kind: r.Alert.Kind,
Tag: r.Alert.Tag,
Value: r.Alert.Value,
},
Expr: yaml.Node{
Kind: r.Expr.Kind,
Tag: r.Expr.Tag,
Value: r.Expr.Value,
},
For: r.For,
Labels: maps.Clone(r.Labels),
Annotations: maps.Clone(r.Annotations),
}
}
return cloned
}