diff --git a/go.mod b/go.mod index 9c7ae68..41b6df0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/golang-jwt/jwt/v4 v4.0.0 github.com/golang/protobuf v1.5.2 // indirect - github.com/google/gops v0.3.22 // indirect + github.com/google/gops v0.3.22 github.com/gorilla/mux v1.8.0 github.com/influxdata/line-protocol/v2 v2.2.0 github.com/nats-io/nats-server/v2 v2.2.6 // indirect diff --git a/memstore.go b/memstore.go index 9a909f5..017288d 100644 --- a/memstore.go +++ b/memstore.go @@ -254,7 +254,6 @@ type level struct { // it does not exist. Example selector in the context of the // ClusterCockpit could be: []string{ "emmy", "host123", "cpu0" }. // This function would probably benefit a lot from `level.children` beeing a `sync.Map`? -// If nMetrics is -1, do not create new levels. func (l *level) findLevelOrCreate(selector []string, nMetrics int) *level { if len(selector) == 0 { return l @@ -267,9 +266,6 @@ func (l *level) findLevelOrCreate(selector []string, nMetrics int) *level { if l.children == nil { // Children map needs to be created... l.lock.RUnlock() - if nMetrics == -1 { - return nil - } } else { child, ok := l.children[selector[0]] l.lock.RUnlock() @@ -486,7 +482,15 @@ func (m *MemoryStore) FreeAll() error { // Given a selector, return a list of all children of the level selected. func (m *MemoryStore) ListChildren(selector []string) []string { - lvl := m.root.findLevelOrCreate(selector, -1) + lvl := &m.root + for lvl != nil && len(selector) != 0 { + lvl.lock.RLock() + next := lvl.children[selector[0]] + lvl.lock.RUnlock() + lvl = next + selector = selector[1:] + } + if lvl == nil { return nil }