diff options
Diffstat (limited to '')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/prometheus/cache.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/prometheus/cache.go b/src/go/collectors/go.d.plugin/modules/prometheus/cache.go new file mode 100644 index 000000000..7fc34f8c6 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/prometheus/cache.go @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package prometheus + +import ( + "github.com/netdata/netdata/go/go.d.plugin/agent/module" +) + +func newCache() *cache { + return &cache{entries: make(map[string]*cacheEntry)} +} + +type ( + cache struct { + entries map[string]*cacheEntry + } + + cacheEntry struct { + seen bool + notSeenTimes int + charts []*module.Chart + } +) + +func (c *cache) hasP(key string) bool { + v, ok := c.entries[key] + if !ok { + v = &cacheEntry{} + c.entries[key] = v + } + v.seen = true + v.notSeenTimes = 0 + + return ok +} + +func (c *cache) addChart(key string, chart *module.Chart) { + if v, ok := c.entries[key]; ok { + v.charts = append(v.charts, chart) + } +} |