From a59757c3a638f385ca7d90dfea686cc27aacba24 Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Wed, 1 Jan 2020 16:39:29 -0800 Subject: [PATCH] fix: enable skipped tests for notification rules and fixup issue in tag matcher --- kv/notification_rule.go | 4 +--- kv/notification_rule_test.go | 1 - notification/rule/rule.go | 28 ++++++++++++++-------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/kv/notification_rule.go b/kv/notification_rule.go index d4c3f4a06f8..deadfb7b22e 100644 --- a/kv/notification_rule.go +++ b/kv/notification_rule.go @@ -435,9 +435,7 @@ func (s *Service) forEachNotificationRule(ctx context.Context, tx Tx, descending return nil } -func filterNotificationRulesFn( - idMap map[influxdb.ID]bool, - filter influxdb.NotificationRuleFilter) func(nr influxdb.NotificationRule) bool { +func filterNotificationRulesFn(idMap map[influxdb.ID]bool, filter influxdb.NotificationRuleFilter) func(nr influxdb.NotificationRule) bool { if filter.OrgID != nil { return func(nr influxdb.NotificationRule) bool { if !nr.MatchesTags(filter.Tags) { diff --git a/kv/notification_rule_test.go b/kv/notification_rule_test.go index 870d578fe27..667e83cc877 100644 --- a/kv/notification_rule_test.go +++ b/kv/notification_rule_test.go @@ -11,7 +11,6 @@ import ( ) func TestBoltNotificationRuleStore(t *testing.T) { - t.Skip("https://github.com/influxdata/influxdb/issues/14799") influxdbtesting.NotificationRuleStore(initBoltNotificationRuleStore, t) } diff --git a/notification/rule/rule.go b/notification/rule/rule.go index ae892cff373..759463ff2a1 100644 --- a/notification/rule/rule.go +++ b/notification/rule/rule.go @@ -337,7 +337,6 @@ func (b *Base) ClearPrivateData() { // MatchesTags returns true if the Rule matches all of the tags func (b *Base) MatchesTags(tags []influxdb.Tag) bool { - // for each tag in NR // if there exists // a key value match with operator == equal in tags @@ -345,20 +344,21 @@ func (b *Base) MatchesTags(tags []influxdb.Tag) bool { // a key match with a value mismatch with operator == notequal in tags // then true - for _, NRtag := range b.TagRules { - isNRTagInFilterTags := false - - for _, filterTag := range tags { - if NRtag.Key == filterTag.Key { - if NRtag.Operator == influxdb.Equal && NRtag.Value == filterTag.Value { - isNRTagInFilterTags = true - } - if NRtag.Operator == influxdb.NotEqual && NRtag.Value != filterTag.Value { - isNRTagInFilterTags = true - } - } + // TODO(jsteenb2): understand the comment above + mTagRules := make(map[string]notification.TagRule) + for _, tag := range b.TagRules { + mTagRules[tag.Key] = tag + } + + for _, tag := range tags { + nTag, ok := mTagRules[tag.Key] + if !ok { + return false + } + if nTag.Operator == influxdb.Equal && nTag.Value != tag.Value { + return false } - if !isNRTagInFilterTags { + if nTag.Operator == influxdb.NotEqual && nTag.Value == tag.Value { return false } }