From d88c3ed20fc1bb82ae583d6aae8b64e4eefebf89 Mon Sep 17 00:00:00 2001 From: Wesley Kim Date: Tue, 15 Dec 2020 10:10:12 -0500 Subject: [PATCH] [coordinator] Include tags in view.MappingRule Equals (#3015) --- src/metrics/rules/view/mapping.go | 10 ++++++++++ src/metrics/rules/view/mapping_test.go | 13 +++++++++++++ src/query/models/types.go | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/src/metrics/rules/view/mapping.go b/src/metrics/rules/view/mapping.go index a53ccf2609..22fdbed04c 100644 --- a/src/metrics/rules/view/mapping.go +++ b/src/metrics/rules/view/mapping.go @@ -49,6 +49,16 @@ func (m *MappingRule) Equal(other *MappingRule) bool { if m == nil || other == nil { return false } + if len(m.Tags) != len(other.Tags) { + return false + } + + for i := 0; i < len(m.Tags); i++ { + if !m.Tags[i].Equal(other.Tags[i]) { + return false + } + } + return m.ID == other.ID && m.Name == other.Name && m.Filter == other.Filter && diff --git a/src/metrics/rules/view/mapping_test.go b/src/metrics/rules/view/mapping_test.go index 2bbfb88bd5..86b5726d4d 100644 --- a/src/metrics/rules/view/mapping_test.go +++ b/src/metrics/rules/view/mapping_test.go @@ -26,6 +26,7 @@ import ( "github.com/m3db/m3/src/metrics/aggregation" "github.com/m3db/m3/src/metrics/policy" + "github.com/m3db/m3/src/query/models" xtime "github.com/m3db/m3/src/x/time" "github.com/stretchr/testify/require" @@ -43,6 +44,7 @@ func TestMappingRuleEqual(t *testing.T) { }, LastUpdatedAtMillis: 1234, LastUpdatedBy: "john", + Tags: []models.Tag{{Name: []byte("name_1"), Value: []byte("val_1")}}, } rule2 := MappingRule{ ID: "mr_id", @@ -55,6 +57,7 @@ func TestMappingRuleEqual(t *testing.T) { }, LastUpdatedAtMillis: 1234, LastUpdatedBy: "john", + Tags: []models.Tag{{Name: []byte("name_1"), Value: []byte("val_1")}}, } require.True(t, rule1.Equal(&rule2)) require.True(t, rule2.Equal(&rule1)) @@ -127,6 +130,16 @@ func TestMappingRuleNotEqual(t *testing.T) { }, DropPolicy: policy.DropIfOnlyMatch, }, + { + ID: "mr", + Name: "foo", + Filter: "filter", + AggregationID: aggregation.MustCompressTypes(aggregation.Sum), + StoragePolicies: policy.StoragePolicies{ + policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), + }, + Tags: []models.Tag{{Name: []byte("name_1"), Value: []byte("val_1")}}, + }, } for i := 0; i < len(rules); i++ { for j := i + 1; j < len(rules); j++ { diff --git a/src/query/models/types.go b/src/query/models/types.go index 66ce809fd4..d2d42dfe72 100644 --- a/src/query/models/types.go +++ b/src/query/models/types.go @@ -21,6 +21,7 @@ package models import ( + "bytes" "regexp" ) @@ -130,6 +131,11 @@ type Tag struct { Value []byte } +// Equal determiens whether two tags are equal to each other. +func (t Tag) Equal(other Tag) bool { + return bytes.Equal(t.Name, other.Name) && bytes.Equal(t.Value, other.Value) +} + // MatchType is an enum for label matching types. type MatchType int