Skip to content

Commit

Permalink
[coordinator] Include tags in view.MappingRule Equals (#3015)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyk authored Dec 15, 2020
1 parent 59843cf commit d88c3ed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/metrics/rules/view/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
13 changes: 13 additions & 0 deletions src/metrics/rules/view/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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))
Expand Down Expand Up @@ -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++ {
Expand Down
6 changes: 6 additions & 0 deletions src/query/models/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package models

import (
"bytes"
"regexp"
)

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d88c3ed

Please sign in to comment.