99 "sync"
1010 "sync/atomic"
1111
12+ schema "gopkg.in/raintank/schema.v1"
13+
1214 "github.com/grafana/metrictank/idx"
1315 "github.com/raintank/worldping-api/pkg/log"
1416)
@@ -97,8 +99,8 @@ type TagQuery struct {
9799
98100 startWith match // choses the first clause to generate the initial result set (one of EQUAL PREFIX MATCH MATCH_TAG PREFIX_TAG)
99101
100- index TagIndex // the tag index, hierarchy of tags & values, set by Run()/RunGetTags()
101- byId map [string ]* idx.Archive // the metric index by ID, set by Run()/RunGetTags()
102+ index TagIndex // the tag index, hierarchy of tags & values, set by Run()/RunGetTags()
103+ byId map [schema. MKey ]* idx.Archive // the metric index by ID, set by Run()/RunGetTags()
102104
103105 wg * sync.WaitGroup
104106}
@@ -333,7 +335,7 @@ func NewTagQuery(expressions []string, from int64) (TagQuery, error) {
333335}
334336
335337// getInitialByEqual generates the initial resultset by executing the given equal expression
336- func (q * TagQuery ) getInitialByEqual (expr kv , idCh chan string , stopCh chan struct {}) {
338+ func (q * TagQuery ) getInitialByEqual (expr kv , idCh chan schema. MKey , stopCh chan struct {}) {
337339 defer q .wg .Done ()
338340
339341KEYS:
@@ -349,7 +351,7 @@ KEYS:
349351}
350352
351353// getInitialByPrefix generates the initial resultset by executing the given prefix match expression
352- func (q * TagQuery ) getInitialByPrefix (expr kv , idCh chan string , stopCh chan struct {}) {
354+ func (q * TagQuery ) getInitialByPrefix (expr kv , idCh chan schema. MKey , stopCh chan struct {}) {
353355 defer q .wg .Done ()
354356
355357VALUES:
@@ -371,7 +373,7 @@ VALUES:
371373}
372374
373375// getInitialByMatch generates the initial resultset by executing the given match expression
374- func (q * TagQuery ) getInitialByMatch (expr kvRe , idCh chan string , stopCh chan struct {}) {
376+ func (q * TagQuery ) getInitialByMatch (expr kvRe , idCh chan schema. MKey , stopCh chan struct {}) {
375377 defer q .wg .Done ()
376378
377379 // shortcut if value == nil.
@@ -412,7 +414,7 @@ VALUES2:
412414
413415// getInitialByTagPrefix generates the initial resultset by creating a list of
414416// metric IDs of which at least one tag starts with the defined prefix
415- func (q * TagQuery ) getInitialByTagPrefix (idCh chan string , stopCh chan struct {}) {
417+ func (q * TagQuery ) getInitialByTagPrefix (idCh chan schema. MKey , stopCh chan struct {}) {
416418 defer q .wg .Done ()
417419
418420TAGS:
@@ -437,7 +439,7 @@ TAGS:
437439
438440// getInitialByTagMatch generates the initial resultset by creating a list of
439441// metric IDs of which at least one tag matches the defined regex
440- func (q * TagQuery ) getInitialByTagMatch (idCh chan string , stopCh chan struct {}) {
442+ func (q * TagQuery ) getInitialByTagMatch (idCh chan schema. MKey , stopCh chan struct {}) {
441443 defer q .wg .Done ()
442444
443445TAGS:
@@ -461,8 +463,8 @@ TAGS:
461463// getInitialIds asynchronously collects all ID's of the initial result set. It returns:
462464// a channel through which the IDs of the initial result set will be sent
463465// a stop channel, which when closed, will cause it to abort the background worker.
464- func (q * TagQuery ) getInitialIds () (chan string , chan struct {}) {
465- idCh := make (chan string , 1000 )
466+ func (q * TagQuery ) getInitialIds () (chan schema. MKey , chan struct {}) {
467+ idCh := make (chan schema. MKey , 1000 )
466468 stopCh := make (chan struct {})
467469 q .wg .Add (1 )
468470
@@ -492,7 +494,7 @@ func (q *TagQuery) getInitialIds() (chan string, chan struct{}) {
492494// all required tests in order to decide whether this metric should be part
493495// of the final result set or not
494496// in map/reduce terms this is the reduce function
495- func (q * TagQuery ) testByAllExpressions (id string , def * idx.Archive , omitTagFilters bool ) bool {
497+ func (q * TagQuery ) testByAllExpressions (id schema. MKey , def * idx.Archive , omitTagFilters bool ) bool {
496498 if ! q .testByFrom (def ) {
497499 return false
498500 }
@@ -695,7 +697,7 @@ func (q *TagQuery) testByTagPrefix(def *idx.Archive) bool {
695697}
696698
697699// testByEqual filters a given metric by the defined "=" expressions
698- func (q * TagQuery ) testByEqual (id string , exprs []kv , not bool ) bool {
700+ func (q * TagQuery ) testByEqual (id schema. MKey , exprs []kv , not bool ) bool {
699701 for _ , e := range exprs {
700702 indexIds := q.index [e.key ][e.value ]
701703
@@ -722,7 +724,7 @@ func (q *TagQuery) testByEqual(id string, exprs []kv, not bool) bool {
722724// required tests to decide whether a metric should be part of the final
723725// result set or not
724726// it returns the final result set via the given resCh parameter
725- func (q * TagQuery ) filterIdsFromChan (idCh , resCh chan string ) {
727+ func (q * TagQuery ) filterIdsFromChan (idCh , resCh chan schema. MKey ) {
726728 for id := range idCh {
727729 var def * idx.Archive
728730 var ok bool
@@ -772,14 +774,14 @@ func (q *TagQuery) sortByCost() {
772774}
773775
774776// Run executes the tag query on the given index and returns a list of ids
775- func (q * TagQuery ) Run (index TagIndex , byId map [string ]* idx.Archive ) IdSet {
777+ func (q * TagQuery ) Run (index TagIndex , byId map [schema. MKey ]* idx.Archive ) IdSet {
776778 q .index = index
777779 q .byId = byId
778780
779781 q .sortByCost ()
780782
781783 idCh , _ := q .getInitialIds ()
782- resCh := make (chan string )
784+ resCh := make (chan schema. MKey )
783785
784786 // start the tag query workers. they'll consume the ids on the idCh and
785787 // evaluate for each of them whether it satisfies all the conditions
@@ -836,7 +838,7 @@ func (q *TagQuery) getMaxTagCount() int {
836838// according to the criteria associated with this query
837839// those that pass all the tests will have their relevant tags extracted, which
838840// are then pushed into the given tag channel
839- func (q * TagQuery ) filterTagsFromChan (idCh chan string , tagCh chan string , stopCh chan struct {}, omitTagFilters bool ) {
841+ func (q * TagQuery ) filterTagsFromChan (idCh chan schema. MKey , tagCh chan string , stopCh chan struct {}, omitTagFilters bool ) {
840842 // used to prevent that this worker thread will push the same result into
841843 // the chan twice
842844 resultsCache := make (map [string ]struct {})
@@ -953,7 +955,7 @@ func (q *TagQuery) tagFilterMatchesName() bool {
953955
954956// RunGetTags executes the tag query and returns all the tags of the
955957// resulting metrics
956- func (q * TagQuery ) RunGetTags (index TagIndex , byId map [string ]* idx.Archive ) map [string ]struct {} {
958+ func (q * TagQuery ) RunGetTags (index TagIndex , byId map [schema. MKey ]* idx.Archive ) map [string ]struct {} {
957959 q .index = index
958960 q .byId = byId
959961
0 commit comments