@@ -836,8 +836,9 @@ func (m *MemoryIdx) FindByTag(orgId uint32, expressions []string, from int64) ([
836
836
m .RLock ()
837
837
defer m .RUnlock ()
838
838
839
+ // construct the output slice of idx.Node's such that there is only 1 idx.Node for each path
839
840
ids := m .idsByTagQuery (orgId , query )
840
- nodesByPath := make (map [string ]idx.Node )
841
+ byPath := make (map [string ]idx.Node )
841
842
for id := range ids {
842
843
def , ok := m .defById [id ]
843
844
if ! ok {
@@ -846,8 +847,8 @@ func (m *MemoryIdx) FindByTag(orgId uint32, expressions []string, from int64) ([
846
847
continue
847
848
}
848
849
849
- if existing , ok := nodesByPath [def .NameWithTags ()]; ! ok {
850
- nodesByPath [def .NameWithTags ()] = idx.Node {
850
+ if existing , ok := byPath [def .NameWithTags ()]; ! ok {
851
+ byPath [def .NameWithTags ()] = idx.Node {
851
852
Path : def .NameWithTags (),
852
853
Leaf : true ,
853
854
HasChildren : false ,
@@ -858,13 +859,13 @@ func (m *MemoryIdx) FindByTag(orgId uint32, expressions []string, from int64) ([
858
859
}
859
860
}
860
861
861
- res := make ([]idx.Node , 0 , len (nodesByPath ))
862
+ results := make ([]idx.Node , 0 , len (byPath ))
862
863
863
- for _ , v := range nodesByPath {
864
- res = append (res , v )
864
+ for _ , v := range byPath {
865
+ results = append (results , v )
865
866
}
866
867
867
- return res , nil
868
+ return results , nil
868
869
}
869
870
870
871
func (m * MemoryIdx ) idsByTagQuery (orgId uint32 , query TagQuery ) IdSet {
@@ -893,11 +894,13 @@ func (m *MemoryIdx) Find(orgId uint32, pattern string, from int64) ([]idx.Node,
893
894
}
894
895
log .Debug ("memory-idx: %d nodes matching pattern %s found" , len (matchedNodes ), pattern )
895
896
results := make ([]idx.Node , 0 )
896
- seen := make (map [string ]struct {})
897
+ byPath := make (map [string ]struct {})
898
+ // construct the output slice of idx.Node's such that there is only 1 idx.Node
899
+ // for each path, and it holds all defs that the Node refers too.
897
900
// if there are public (orgId OrgIdPublic) and private leaf nodes with the same series
898
901
// path, then the public metricDefs will be excluded.
899
902
for _ , n := range matchedNodes {
900
- if _ , ok := seen [n .Path ]; ! ok {
903
+ if _ , ok := byPath [n .Path ]; ! ok {
901
904
idxNode := idx.Node {
902
905
Path : n .Path ,
903
906
Leaf : n .Leaf (),
@@ -920,7 +923,7 @@ func (m *MemoryIdx) Find(orgId uint32, pattern string, from int64) ([]idx.Node,
920
923
}
921
924
}
922
925
results = append (results , idxNode )
923
- seen [n .Path ] = struct {}{}
926
+ byPath [n .Path ] = struct {}{}
924
927
} else {
925
928
log .Debug ("memory-idx: path %s already seen" , n .Path )
926
929
}
@@ -930,6 +933,7 @@ func (m *MemoryIdx) Find(orgId uint32, pattern string, from int64) ([]idx.Node,
930
933
return results , nil
931
934
}
932
935
936
+ // find returns all Nodes matching the pattern for the given orgId
933
937
func (m * MemoryIdx ) find (orgId uint32 , pattern string ) ([]* Node , error ) {
934
938
tree , ok := m .tree [orgId ]
935
939
if ! ok {
0 commit comments