@ -324,19 +324,19 @@ type compareRuleType struct {
label map [ string ] string
label map [ string ] string
}
}
func checkDuplicates ( r [ ] rulefmt . RuleGroup ) [ ] compareRuleType {
func checkDuplicates ( g roups [ ] rulefmt . RuleGroup ) [ ] compareRuleType {
var duplicates [ ] compareRuleType
var duplicates [ ] compareRuleType
for rindex := range r {
for _, group := range groups {
for index , props := range r [ rindex ] . Rules {
for index , rule := range group . Rules {
inst := compareRuleType {
inst := compareRuleType {
metric : props . Record ,
metric : ruleMetric ( rule ) ,
label : props . Labels ,
label : rule . Labels ,
}
}
for i := 0 ; i < index ; i ++ {
for i := 0 ; i < index ; i ++ {
t := compareRuleType {
t := compareRuleType {
metric : r [ rindex ] . Rules [ i ] . Record ,
metric : ruleMetric ( group . Rules [ i ] ) ,
label : r[ rindex ] . Rules [ i ] . Labels ,
label : group . Rules [ i ] . Labels ,
}
}
if reflect . DeepEqual ( t , inst ) {
if reflect . DeepEqual ( t , inst ) {
duplicates = append ( duplicates , t )
duplicates = append ( duplicates , t )
@ -347,6 +347,13 @@ func checkDuplicates(r []rulefmt.RuleGroup) []compareRuleType {
return duplicates
return duplicates
}
}
func ruleMetric ( rule rulefmt . Rule ) string {
if rule . Alert != "" {
return rule . Alert
}
return rule . Record
}
var checkMetricsUsage = strings . TrimSpace ( `
var checkMetricsUsage = strings . TrimSpace ( `
Pass Prometheus metrics over stdin to lint them for consistency and correctness .
Pass Prometheus metrics over stdin to lint them for consistency and correctness .