diff --git a/lint/rule_target_job_instance_test.go b/lint/rule_target_job_instance_test.go index 3b36277..c7d64e4 100644 --- a/lint/rule_target_job_instance_test.go +++ b/lint/rule_target_job_instance_test.go @@ -29,6 +29,19 @@ func testTargetRequiredMatcherRule(t *testing.T, matcher string) { Expr: fmt.Sprintf(`sum(rate(foo{%s=~"$%s"}[5m]))`, matcher, matcher), }, }, + // Happy path (multiple matchers where at least one matches) + { + result: ResultSuccess, + target: Target{ + Expr: fmt.Sprintf(`sum(rate(foo{%s="integrations/bar", %s=~"$%s"}[5m]))`, matcher, matcher, matcher), + }, + }, + { + result: ResultSuccess, + target: Target{ + Expr: fmt.Sprintf(`sum(rate(foo{%s=~"$%s", %s="integrations/bar"}[5m]))`, matcher, matcher, matcher), + }, + }, // Also happy when the promql is invalid { result: ResultSuccess, diff --git a/lint/target_utils.go b/lint/target_utils.go index 32c1c6e..25b163e 100644 --- a/lint/target_utils.go +++ b/lint/target_utils.go @@ -7,21 +7,26 @@ import ( ) func checkForMatcher(selector []*labels.Matcher, name string, ty labels.MatchType, value string) error { + var result error + result = fmt.Errorf("%s selector not found", name) + for _, matcher := range selector { if matcher.Name != name { continue } + if matcher.Type == ty && matcher.Value == value { + result = nil + break + } if matcher.Type != ty { - return fmt.Errorf("%s selector is %s, not %s", name, matcher.Type, ty) + result = fmt.Errorf("%s selector is %s, not %s", name, matcher.Type, ty) } if matcher.Value != value { - return fmt.Errorf("%s selector is %s, not %s", name, matcher.Value, value) + result = fmt.Errorf("%s selector is %s, not %s", name, matcher.Value, value) } - - return nil } - return fmt.Errorf("%s selector not found", name) + return result }