Unified API for all query types; remove dead code

This commit is contained in:
Lou Knauer
2022-01-20 10:42:44 +01:00
parent 15733cb1b7
commit b6b219a9ad
3 changed files with 115 additions and 342 deletions

View File

@@ -247,8 +247,9 @@ type level struct {
// Find the correct level for the given selector, creating it if
// it does not exist. Example selector in the context of the
// ClusterCockpit could be: []string{ "emmy", "host123", "cpu", "0" }
// 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
@@ -261,6 +262,9 @@ 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()
@@ -458,3 +462,21 @@ func (m *MemoryStore) FreeAll() error {
return nil
}
// 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)
if lvl == nil {
return nil
}
lvl.lock.RLock()
defer lvl.lock.RUnlock()
children := make([]string, 0, len(lvl.children))
for child := range lvl.children {
children = append(children, child)
}
return children
}