github.com/m3db/m3@v1.5.0/src/query/graphite/storage/converter.go (about) 1 // Copyright (c) 2019 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package storage 22 23 import ( 24 "github.com/m3db/m3/src/query/graphite/graphite" 25 "github.com/m3db/m3/src/query/models" 26 ) 27 28 const ( 29 wildcard = "*" 30 ) 31 32 func convertMetricPartToMatcher( 33 count int, 34 metric string, 35 ) (models.Matcher, error) { 36 var matchType models.MatchType 37 if metric == wildcard { 38 if count == 0 { 39 // Match field does not actually match all values 40 // for the first metric selector in practice. 41 // Need to special case this and just use a regexp match all 42 // on this first value. 43 // This is ok since there usually a very small amount of distinct 44 // values in the first dot separator. 45 return models.Matcher{ 46 Type: models.MatchRegexp, 47 Name: graphite.TagName(count), 48 Value: []byte(".*"), 49 }, nil 50 } 51 return models.Matcher{ 52 Type: models.MatchField, 53 Name: graphite.TagName(count), 54 }, nil 55 } 56 57 value, isRegex, err := graphite.GlobToRegexPattern(metric) 58 if err != nil { 59 return models.Matcher{}, err 60 } 61 62 if isRegex { 63 matchType = models.MatchRegexp 64 } else { 65 matchType = models.MatchEqual 66 } 67 68 return models.Matcher{ 69 Type: matchType, 70 Name: graphite.TagName(count), 71 Value: value, 72 }, nil 73 } 74 75 func matcherTerminator(count int) models.Matcher { 76 return models.Matcher{ 77 Type: models.MatchNotField, 78 Name: graphite.TagName(count), 79 } 80 }