summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/nginxplus/cache.go
blob: af58f3a55104e6e39db1dd8f4af69955a2f0ec3e (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// SPDX-License-Identifier: GPL-3.0-or-later

package nginxplus

func newCache() *cache {
	return &cache{
		httpCaches:            make(map[string]*cacheHTTPCacheEntry),
		httpServerZones:       make(map[string]*cacheZoneEntry),
		httpLocationZones:     make(map[string]*cacheZoneEntry),
		httpUpstreams:         make(map[string]*cacheUpstreamEntry),
		httpUpstreamServers:   make(map[string]*cacheUpstreamServerEntry),
		streamServerZones:     make(map[string]*cacheZoneEntry),
		streamUpstreams:       make(map[string]*cacheUpstreamEntry),
		streamUpstreamServers: make(map[string]*cacheUpstreamServerEntry),
		resolvers:             make(map[string]*cacheResolverEntry),
	}
}

type (
	cache struct {
		httpCaches            map[string]*cacheHTTPCacheEntry
		httpServerZones       map[string]*cacheZoneEntry
		httpLocationZones     map[string]*cacheZoneEntry
		httpUpstreams         map[string]*cacheUpstreamEntry
		httpUpstreamServers   map[string]*cacheUpstreamServerEntry
		streamServerZones     map[string]*cacheZoneEntry
		streamUpstreams       map[string]*cacheUpstreamEntry
		streamUpstreamServers map[string]*cacheUpstreamServerEntry
		resolvers             map[string]*cacheResolverEntry
	}
	cacheEntry struct {
		hasCharts    bool
		updated      bool
		notSeenTimes int
	}
	cacheHTTPCacheEntry struct {
		name string
		cacheEntry
	}
	cacheResolverEntry struct {
		zone string
		cacheEntry
	}
	cacheZoneEntry struct {
		zone string
		cacheEntry
	}
	cacheUpstreamEntry struct {
		name string
		zone string
		cacheEntry
	}
	cacheUpstreamServerEntry struct {
		name       string
		zone       string
		serverAddr string
		serverName string
		cacheEntry
	}
)

func (c *cache) resetUpdated() {
	for _, v := range c.httpCaches {
		v.updated = false
	}
	for _, v := range c.httpServerZones {
		v.updated = false
	}
	for _, v := range c.httpLocationZones {
		v.updated = false
	}
	for _, v := range c.httpUpstreams {
		v.updated = false
	}
	for _, v := range c.httpUpstreamServers {
		v.updated = false
	}
	for _, v := range c.streamServerZones {
		v.updated = false
	}
	for _, v := range c.streamUpstreams {
		v.updated = false
	}
	for _, v := range c.streamUpstreamServers {
		v.updated = false
	}
	for _, v := range c.resolvers {
		v.updated = false
	}
}

func (c *cache) putHTTPCache(cache string) {
	v, ok := c.httpCaches[cache]
	if !ok {
		v = &cacheHTTPCacheEntry{name: cache}
		c.httpCaches[cache] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putHTTPServerZone(zone string) {
	v, ok := c.httpServerZones[zone]
	if !ok {
		v = &cacheZoneEntry{zone: zone}
		c.httpServerZones[zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putHTTPLocationZone(zone string) {
	v, ok := c.httpLocationZones[zone]
	if !ok {
		v = &cacheZoneEntry{zone: zone}
		c.httpLocationZones[zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putHTTPUpstream(name, zone string) {
	v, ok := c.httpUpstreams[name+"_"+zone]
	if !ok {
		v = &cacheUpstreamEntry{name: name, zone: zone}
		c.httpUpstreams[name+"_"+zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putHTTPUpstreamServer(name, serverAddr, serverName, zone string) {
	v, ok := c.httpUpstreamServers[name+"_"+serverAddr+"_"+zone]
	if !ok {
		v = &cacheUpstreamServerEntry{name: name, zone: zone, serverAddr: serverAddr, serverName: serverName}
		c.httpUpstreamServers[name+"_"+serverAddr+"_"+zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putStreamServerZone(zone string) {
	v, ok := c.streamServerZones[zone]
	if !ok {
		v = &cacheZoneEntry{zone: zone}
		c.streamServerZones[zone] = v
	}
	v.updated, v.notSeenTimes = true, 0

}

func (c *cache) putStreamUpstream(name, zone string) {
	v, ok := c.streamUpstreams[name+"_"+zone]
	if !ok {
		v = &cacheUpstreamEntry{name: name, zone: zone}
		c.streamUpstreams[name+"_"+zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putStreamUpstreamServer(name, serverAddr, serverName, zone string) {
	v, ok := c.streamUpstreamServers[name+"_"+serverAddr+"_"+zone]
	if !ok {
		v = &cacheUpstreamServerEntry{name: name, zone: zone, serverAddr: serverAddr, serverName: serverName}
		c.streamUpstreamServers[name+"_"+serverAddr+"_"+zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}

func (c *cache) putResolver(zone string) {
	v, ok := c.resolvers[zone]
	if !ok {
		v = &cacheResolverEntry{zone: zone}
		c.resolvers[zone] = v
	}
	v.updated, v.notSeenTimes = true, 0
}