From 744e0fd578d7837f8e0546520fed0227b3730e4a Mon Sep 17 00:00:00 2001 From: arnikola Date: Thu, 30 May 2019 11:14:23 -0400 Subject: [PATCH] [query] Fix bug with parsing Graphite find query (#1676) --- .../api/v1/handler/graphite/find_parser.go | 4 +- .../api/v1/handler/graphite/find_test.go | 4 +- src/query/generated/proto/rpcpb/query.pb.go | 146 +++++++++--------- src/query/generated/proto/rpcpb/query.proto | 5 +- src/query/graphite/storage/converter.go | 16 +- src/query/graphite/storage/converter_test.go | 19 ++- src/query/graphite/storage/m3_wrapper_test.go | 4 +- src/query/models/matcher.go | 20 +-- src/query/models/matcher_test.go | 63 -------- src/query/models/types.go | 2 + src/query/storage/index.go | 11 ++ src/query/storage/index_test.go | 22 +++ src/query/tsdb/remote/codecs.go | 6 +- 13 files changed, 157 insertions(+), 165 deletions(-) diff --git a/src/query/api/v1/handler/graphite/find_parser.go b/src/query/api/v1/handler/graphite/find_parser.go index 2947c5cd7b..e6a6f9c34c 100644 --- a/src/query/api/v1/handler/graphite/find_parser.go +++ b/src/query/api/v1/handler/graphite/find_parser.go @@ -125,9 +125,9 @@ func parseFindParamsToQueries(r *http.Request) ( clonedMatchers := make([]models.Matcher, len(matchers)) copy(clonedMatchers, matchers) - // NB: change terminator from `MatchNotRegexp` to `MatchRegexp` to ensure + // NB: change terminator from `MatchNotField` to `MatchField` to ensure // segments with children are matched. - clonedMatchers[len(clonedMatchers)-1].Type = models.MatchRegexp + clonedMatchers[len(clonedMatchers)-1].Type = models.MatchField childQuery := &storage.CompleteTagsQuery{ CompleteNameOnly: false, FilterNameTags: filter, diff --git a/src/query/api/v1/handler/graphite/find_test.go b/src/query/api/v1/handler/graphite/find_test.go index 09c055424e..40bab7e668 100644 --- a/src/query/api/v1/handler/graphite/find_test.go +++ b/src/query/api/v1/handler/graphite/find_test.go @@ -127,7 +127,7 @@ func setupStorage(ctrl *gomock.Controller) storage.Storage { matchers: []models.Matcher{ {Type: models.MatchEqual, Name: b("__g0__"), Value: b("foo")}, {Type: models.MatchRegexp, Name: b("__g1__"), Value: b(`b[^\.]*`)}, - {Type: models.MatchNotRegexp, Name: b("__g2__"), Value: b(".*")}, + {Type: models.MatchNotField, Name: b("__g2__")}, }, } @@ -146,7 +146,7 @@ func setupStorage(ctrl *gomock.Controller) storage.Storage { matchers: []models.Matcher{ {Type: models.MatchEqual, Name: b("__g0__"), Value: b("foo")}, {Type: models.MatchRegexp, Name: b("__g1__"), Value: b(`b[^\.]*`)}, - {Type: models.MatchRegexp, Name: b("__g2__"), Value: b(".*")}, + {Type: models.MatchField, Name: b("__g2__")}, }, } diff --git a/src/query/generated/proto/rpcpb/query.pb.go b/src/query/generated/proto/rpcpb/query.pb.go index 9982a2a198..d09af2e607 100644 --- a/src/query/generated/proto/rpcpb/query.pb.go +++ b/src/query/generated/proto/rpcpb/query.pb.go @@ -86,9 +86,12 @@ const ( MatcherType_REGEXP MatcherType = 2 MatcherType_NOTREGEXP MatcherType = 3 // EXISTS and NOTEXISTS apply only to - // matcher name rather than value + // matcher name rather than value. MatcherType_EXISTS MatcherType = 4 MatcherType_NOTEXISTS MatcherType = 5 + // ALL supercedes other matcher types + // and does no filtering. + MatcherType_ALL MatcherType = 6 ) var MatcherType_name = map[int32]string{ @@ -98,6 +101,7 @@ var MatcherType_name = map[int32]string{ 3: "NOTREGEXP", 4: "EXISTS", 5: "NOTEXISTS", + 6: "ALL", } var MatcherType_value = map[string]int32{ "EQUAL": 0, @@ -106,6 +110,7 @@ var MatcherType_value = map[string]int32{ "NOTREGEXP": 3, "EXISTS": 4, "NOTEXISTS": 5, + "ALL": 6, } func (x MatcherType) String() string { @@ -5658,73 +5663,74 @@ func init() { } var fileDescriptorQuery = []byte{ - // 1087 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0xf6, 0x7a, 0x6d, 0xc7, 0x3e,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x66, 0x62, 0x3f, 0xcb, 0x91, - 0x34, 0xec, 0x04, 0xa0, 0xec, 0xa8, 0xb5, 0xf1, 0x15, 0x54, 0x53, 0x48, 0xfc, 0x28, 0x9b, 0x50, - 0xdb, 0xd5, 0xf7, 0xaa, 0x9d, 0xf5, 0x85, 0x84, 0x99, 0x6c, 0xc6, 0x63, 0x80, 0xc4, 0x85, 0x08, - 0x85, 0x29, 0x75, 0x98, 0x2c, 0xbc, 0x46, 0xe4, 0x5a, 0x74, 0xf3, 0x03, 0x9d, 0xcc, 0x98, 0xac, - 0xbc, 0x46, 0xc2, 0x0d, 0xbe, 0x0d, 0x05, 0x3e, 0xf7, 0x98, 0x2c, 0xba, 0xa1, 0x8a, 0x56, 0x59, - 0xcc, 0xb9, 0xc7, 0x88, 0xf4, 0x1a, 0x47, 0x50, 0x57, 0x93, 0x09, 0x3c, 0x77, 0x1a, 0x30, 0x7c, - 0x0b, 0x4a, 0x01, 0xf3, 0x6d, 0x16, 0x15, 0x57, 0x95, 0x81, 0x03, 0x69, 0x22, 0xca, 0x65, 0xfc, - 0xaa, 0x41, 0x29, 0x34, 0xe1, 0xbb, 0x50, 0x70, 0x18, 0xa7, 0xb2, 0xa0, 0x6a, 0x67, 0x23, 0x85, - 0xee, 0x33, 0x4e, 0x2d, 0xca, 0x29, 0x91, 0x00, 0xfc, 0x1c, 0x6a, 0x16, 0x1b, 0xb9, 0x8e, 0xe7, - 0xb3, 0x20, 0x60, 0xe1, 0x98, 0xab, 0x9d, 0x5b, 0x32, 0xe0, 0x5e, 0xca, 0x11, 0x06, 0x9f, 0xe5, - 0x48, 0x06, 0x8e, 0x77, 0x01, 0x52, 0xc1, 0x7a, 0x2a, 0xb8, 0xdf, 0xfd, 0x7a, 0x39, 0x38, 0x05, - 0x3e, 0x59, 0x53, 0xf3, 0x31, 0xae, 0xa0, 0x91, 0x2d, 0x0d, 0x1b, 0x90, 0xb7, 0x2d, 0x35, 0xcc, - 0xbc, 0x6d, 0xe1, 0x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, 0xed, 0x5d, 0x3d, 0x6c, 0xe6, 0xb1, 0x0e, 0x95, 0xf3, 0x0b, 0x53, - 0x6d, 0x75, 0xe1, 0xea, 0x5d, 0x7d, 0x33, 0x30, 0x07, 0xcd, 0x82, 0x72, 0xa9, 0x6d, 0x71, 0xff, - 0x03, 0x68, 0x2e, 0x92, 0x0c, 0xab, 0xb0, 0x76, 0xaf, 0x77, 0xff, 0xf8, 0xd1, 0x03, 0xb3, 0x99, - 0x13, 0x1b, 0xf3, 0xf8, 0xf4, 0xfc, 0xb8, 0xdf, 0x6b, 0x6a, 0x9d, 0xdf, 0x34, 0x28, 0x5e, 0x8a, - 0x27, 0x19, 0x1e, 0x42, 0x51, 0xbe, 0x36, 0xf0, 0x35, 0xd9, 0x43, 0xfa, 0x4d, 0xb6, 0x85, 0x69, - 0x53, 0x38, 0xa9, 0x43, 0x0d, 0xbb, 0xe2, 0xa1, 0x21, 0xbe, 0x45, 0x44, 0xf5, 0xb4, 0x48, 0x09, - 0xdf, 0xd6, 0x46, 0xc6, 0x16, 0x07, 0xf5, 0xa0, 0x96, 0x2e, 0x0f, 0x5b, 0x2f, 0xa3, 0xd2, 0xd6, - 0xed, 0x15, 0x9e, 0x28, 0xcd, 0xc9, 0xad, 0xdf, 0x6f, 0x76, 0xb4, 0x3f, 0x6e, 0x76, 0xb4, 0x3f, - 0x6f, 0x76, 0xb4, 0x9f, 0xfe, 0xda, 0xc9, 0x7d, 0x57, 0x94, 0xef, 0xcb, 0x61, 0x49, 0x3e, 0x2d, - 0xbb, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x8d, 0x75, 0x78, 0x03, 0x9c, 0x0a, 0x00, 0x00, + // 1092 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xdb, 0x6e, 0x23, 0x45, + 0x10, 0xf5, 0x78, 0x7c, 0x2d, 0x5f, 0x62, 0x2a, 0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0x94, 0x2f, 0x2e, 0x4d, 0xb5, 0xd5, + 0x85, 0xab, 0x77, 0xfd, 0xd5, 0xc0, 0x1c, 0x34, 0x72, 0xca, 0xa5, 0xb6, 0x79, 0x2c, 0x82, 0xde, + 0x3d, 0x3f, 0x6f, 0x14, 0x0e, 0xde, 0x83, 0xc6, 0x32, 0xdb, 0xb0, 0x02, 0xc5, 0x07, 0xbd, 0x87, + 0xdd, 0xc7, 0xe7, 0x66, 0x23, 0x23, 0x36, 0x66, 0xf7, 0xf4, 0xa2, 0xdb, 0xef, 0x35, 0xb4, 0xf6, + 0xaf, 0x1a, 0xe4, 0xaf, 0xc4, 0xdb, 0x0c, 0x8f, 0x20, 0x2f, 0x9f, 0x1d, 0xf8, 0x8a, 0x6c, 0x26, + 0xf9, 0x38, 0xdb, 0xc6, 0xa4, 0x29, 0x18, 0xd9, 0x91, 0x86, 0x1d, 0xf1, 0xe2, 0x10, 0x1f, 0x25, + 0xa2, 0x7a, 0x63, 0x24, 0x14, 0x70, 0x7b, 0x33, 0x65, 0x8b, 0x82, 0x7a, 0x50, 0x4d, 0x96, 0x87, + 0xcd, 0x97, 0x71, 0x6a, 0xfb, 0xee, 0x1a, 0x4f, 0x98, 0xe6, 0xe4, 0xce, 0x6f, 0xb7, 0xbb, 0xda, + 0xef, 0xb7, 0xbb, 0xda, 0x1f, 0xb7, 0xbb, 0xda, 0x8f, 0x7f, 0xee, 0x66, 0xbe, 0xc9, 0xcb, 0x87, + 0xe6, 0xb0, 0x20, 0xdf, 0x98, 0x9d, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x03, 0x62, 0xbc, 0x57, + 0xa5, 0x0a, 0x00, 0x00, } diff --git a/src/query/generated/proto/rpcpb/query.proto b/src/query/generated/proto/rpcpb/query.proto index bc07d2dc89..4fdd67d13a 100644 --- a/src/query/generated/proto/rpcpb/query.proto +++ b/src/query/generated/proto/rpcpb/query.proto @@ -35,9 +35,12 @@ enum MatcherType { REGEXP = 2; NOTREGEXP = 3; // EXISTS and NOTEXISTS apply only to - // matcher name rather than value + // matcher name rather than value. EXISTS = 4; NOTEXISTS = 5; + // ALL supercedes other matcher types + // and does no filtering. + ALL = 6; } message FetchResponse { diff --git a/src/query/graphite/storage/converter.go b/src/query/graphite/storage/converter.go index d00f3bcc3d..45e91ec04b 100644 --- a/src/query/graphite/storage/converter.go +++ b/src/query/graphite/storage/converter.go @@ -25,8 +25,8 @@ import ( "github.com/m3db/m3/src/query/models" ) -var ( - wildcard = []byte(".*") +const ( + wildcard = "*" ) func convertMetricPartToMatcher( @@ -34,6 +34,13 @@ func convertMetricPartToMatcher( metric string, ) (models.Matcher, error) { var matchType models.MatchType + if metric == wildcard { + return models.Matcher{ + Type: models.MatchField, + Name: graphite.TagName(count), + }, nil + } + value, isRegex, err := graphite.GlobToRegexPattern(metric) if err != nil { return models.Matcher{}, err @@ -54,8 +61,7 @@ func convertMetricPartToMatcher( func matcherTerminator(count int) models.Matcher { return models.Matcher{ - Type: models.MatchNotRegexp, - Name: graphite.TagName(count), - Value: wildcard, + Type: models.MatchNotField, + Name: graphite.TagName(count), } } diff --git a/src/query/graphite/storage/converter_test.go b/src/query/graphite/storage/converter_test.go index 7bcffac6c7..80955134b6 100644 --- a/src/query/graphite/storage/converter_test.go +++ b/src/query/graphite/storage/converter_test.go @@ -45,6 +45,20 @@ func TestConvertMetricPartToMatcher(t *testing.T) { } } +func TestConvertWildcardToMatcher(t *testing.T) { + metric := "*" + for i := 0; i < 100; i++ { + expected := models.Matcher{ + Type: models.MatchField, + Name: graphite.TagName(i), + } + + actual, err := convertMetricPartToMatcher(i, metric) + require.NoError(t, err) + assert.Equal(t, expected, actual) + } +} + func TestConvertAlphanumericMetricPartToMatcher(t *testing.T) { metric := "abcdefg" expected := models.Matcher{ @@ -61,9 +75,8 @@ func TestConvertAlphanumericMetricPartToMatcher(t *testing.T) { func TestMatcherTerminator(t *testing.T) { for i := 0; i < 100; i++ { expected := models.Matcher{ - Type: models.MatchNotRegexp, - Name: graphite.TagName(i), - Value: []byte(".*"), + Type: models.MatchNotField, + Name: graphite.TagName(i), } actual := matcherTerminator(i) diff --git a/src/query/graphite/storage/m3_wrapper_test.go b/src/query/graphite/storage/m3_wrapper_test.go index 0a22c81d0f..929a75b950 100644 --- a/src/query/graphite/storage/m3_wrapper_test.go +++ b/src/query/graphite/storage/m3_wrapper_test.go @@ -66,9 +66,9 @@ func TestTranslateQuery(t *testing.T) { {Type: models.MatchEqual, Name: graphite.TagName(3), Value: []byte("terminator")}, {Type: models.MatchEqual, Name: graphite.TagName(4), Value: []byte("will")}, {Type: models.MatchEqual, Name: graphite.TagName(5), Value: []byte("be")}, - {Type: models.MatchRegexp, Name: graphite.TagName(6), Value: []byte(`[^\.]*`)}, + {Type: models.MatchField, Name: graphite.TagName(6)}, {Type: models.MatchRegexp, Name: graphite.TagName(7), Value: []byte(`back[^\.]`)}, - {Type: models.MatchNotRegexp, Name: graphite.TagName(8), Value: []byte(".*")}, + {Type: models.MatchNotField, Name: graphite.TagName(8)}, } assert.Equal(t, expected, matchers) diff --git a/src/query/models/matcher.go b/src/query/models/matcher.go index 350f0ee948..0991ff8b1a 100644 --- a/src/query/models/matcher.go +++ b/src/query/models/matcher.go @@ -38,6 +38,10 @@ func (m MatchType) String() string { return "=~" case MatchNotRegexp: return "!~" + case MatchField: + return "-" + case MatchNotField: + return "!-" case MatchAll: return "*" default: @@ -69,22 +73,6 @@ func (m Matcher) String() string { return fmt.Sprintf("%s%s%q", m.Name, m.Type, m.Value) } -// Matches returns whether the matcher matches the given string value. -func (m Matcher) Matches(s []byte) bool { - switch m.Type { - case MatchEqual: - return bytes.Equal(s, m.Value) - case MatchNotEqual: - return !bytes.Equal(s, m.Value) - case MatchRegexp: - return m.re.MatchString(string(s)) - case MatchNotRegexp: - return !m.re.MatchString(string(s)) - } - - panic("labels.Matcher.Matches: invalid match type") -} - // ToTags converts Matchers to Tags // NB (braskin): this only works for exact matches func (m Matchers) ToTags( diff --git a/src/query/models/matcher_test.go b/src/query/models/matcher_test.go index 48449eb93f..af60022e57 100644 --- a/src/query/models/matcher_test.go +++ b/src/query/models/matcher_test.go @@ -35,69 +35,6 @@ func newMatcher(t *testing.T, mType MatchType, value string) Matcher { return m } -func TestMatcher(t *testing.T) { - tests := []struct { - matcher Matcher - value string - match bool - }{ - { - matcher: newMatcher(t, MatchEqual, "bar"), - value: "bar", - match: true, - }, - { - matcher: newMatcher(t, MatchEqual, "bar"), - value: "foo-bar", - match: false, - }, - { - matcher: newMatcher(t, MatchNotEqual, "bar"), - value: "bar", - match: false, - }, - { - matcher: newMatcher(t, MatchNotEqual, "bar"), - value: "foo-bar", - match: true, - }, - { - matcher: newMatcher(t, MatchRegexp, "bar"), - value: "bar", - match: true, - }, - { - matcher: newMatcher(t, MatchRegexp, "bar"), - value: "foo-bar", - match: false, - }, - { - matcher: newMatcher(t, MatchRegexp, ".*bar"), - value: "foo-bar", - match: true, - }, - { - matcher: newMatcher(t, MatchNotRegexp, "bar"), - value: "bar", - match: false, - }, - { - matcher: newMatcher(t, MatchNotRegexp, "bar"), - value: "foo-bar", - match: true, - }, - { - matcher: newMatcher(t, MatchNotRegexp, ".*bar"), - value: "foo-bar", - match: false, - }, - } - - for _, test := range tests { - assert.Equal(t, test.match, test.matcher.Matches([]byte(test.value))) - } -} - func TestMatcher_String(t *testing.T) { m := newMatcher(t, MatchEqual, "foo") m.Name = []byte(`key`) diff --git a/src/query/models/types.go b/src/query/models/types.go index f211d6d80a..913599fd3f 100644 --- a/src/query/models/types.go +++ b/src/query/models/types.go @@ -120,6 +120,8 @@ const ( MatchNotEqual MatchRegexp MatchNotRegexp + MatchField + MatchNotField MatchAll ) diff --git a/src/query/storage/index.go b/src/query/storage/index.go index 2f9640c638..0cff5702dc 100644 --- a/src/query/storage/index.go +++ b/src/query/storage/index.go @@ -192,6 +192,17 @@ func matcherToQuery(matcher models.Matcher) (idx.Query, error) { } return query, nil + case models.MatchNotField: + negate = true + fallthrough + case models.MatchField: + query := idx.NewFieldQuery(matcher.Name) + if negate { + query = idx.NewNegationQuery(query) + } + + return query, nil + case models.MatchAll: return idx.NewAllQuery(), nil diff --git a/src/query/storage/index_test.go b/src/query/storage/index_test.go index 159510e51f..c1138063a5 100644 --- a/src/query/storage/index_test.go +++ b/src/query/storage/index_test.go @@ -153,6 +153,28 @@ func TestFetchQueryToM3Query(t *testing.T) { }, }, }, + { + name: "field match", + expected: "field(t1)", + matchers: models.Matchers{ + { + Type: models.MatchField, + Name: []byte("t1"), + Value: []byte("v1"), + }, + }, + }, + { + name: "field match negated", + expected: "negation(field(t1))", + matchers: models.Matchers{ + { + Type: models.MatchNotField, + Name: []byte("t1"), + Value: []byte("v1"), + }, + }, + }, { name: "all matchers", expected: "all()", diff --git a/src/query/tsdb/remote/codecs.go b/src/query/tsdb/remote/codecs.go index d2d18bb38a..af6028f93b 100644 --- a/src/query/tsdb/remote/codecs.go +++ b/src/query/tsdb/remote/codecs.go @@ -192,8 +192,12 @@ func encodeMatcherTypeToProto(t models.MatchType) (rpc.MatcherType, error) { return rpc.MatcherType_REGEXP, nil case models.MatchNotRegexp: return rpc.MatcherType_NOTREGEXP, nil - case models.MatchAll: + case models.MatchField: return rpc.MatcherType_EXISTS, nil + case models.MatchNotField: + return rpc.MatcherType_NOTEXISTS, nil + case models.MatchAll: + return rpc.MatcherType_ALL, nil default: return rpc.MatcherType_EQUAL, fmt.Errorf("Unknown matcher type for proto encoding") }