@@ -9,20 +9,20 @@ import (
99 "gopkg.in/yaml.v2"
1010)
1111
12- // Rules array from yaml
12+ // Rules is a slice of rules that are loaded from a yaml array
1313type rules struct {
1414 Rules []rule `yaml:"rules" json:"rules"`
1515 CompiledRegexs map [string ]* regexp.Regexp
1616}
1717
18- // Individual rule within rules array
18+ // Rule is a struct that represents a rule within rules array
1919type rule struct {
2020 Name string `yaml:"name" json:"name"`
2121 Key string `yaml:"key" json:"key"`
2222 Value value `yaml:"value" json:"value"`
2323}
2424
25- // Value struct within each rule
25+ // Value is struct within each rule which only supports regex, but can be expanded
2626type value struct {
2727 Regex string `yaml:"regex" json:"regex"`
2828}
@@ -81,20 +81,14 @@ func (r *rules) validateAllRulesRegex() []ruleError {
8181 return r .compileRegex (false )
8282}
8383
84- func (r * rules ) ensureLabelsContainRules (labels map [string ]interface {}) error {
84+ func (r * rules ) ensureLabelsMatchRules (labels map [string ]interface {}) error {
8585 for _ , rule := range r .Rules {
8686 // Ensure labels contains rule
8787 if _ , ok := labels [rule .Key ]; ! ok {
8888 // If rule is not found, reject
8989 errStr := fmt .Sprintf ("%v not in labels" , rule .Key )
9090 return errors .New (errStr )
9191 }
92- }
93- return nil
94- }
95-
96- func (r * rules ) ensureLabelsMatchRules (labels map [string ]interface {}) error {
97- for _ , rule := range r .Rules {
9892 // Force all values to strings to prevent panic from interface conversion
9993 labelVal := fmt .Sprintf ("%v" , labels [rule .Key ])
10094 regex , _ := r .CompiledRegexs [rule .Name ]
0 commit comments