summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/prometheus/cache.go
blob: 7fc34f8c6c1330ec25557bf547d38f9affad5590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
	}
}