forked from atlassian/gostatsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sets.go
46 lines (38 loc) · 1.22 KB
/
sets.go
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
package gostatsd
// Set is used for storing aggregated values for sets.
type Set struct {
Values map[string]struct{}
Timestamp Nanotime // Last time value was updated
Hostname string // Hostname of the source of the metric
Tags Tags // The tags for the set
}
// NewSet initialises a new set.
func NewSet(timestamp Nanotime, values map[string]struct{}, hostname string, tags Tags) Set {
return Set{Values: values, Timestamp: timestamp, Hostname: hostname, Tags: tags}
}
// Sets stores a map of sets by tags.
type Sets map[string]map[string]Set
// MetricsName returns the name of the aggregated metrics collection.
func (s Sets) MetricsName() string {
return "Sets"
}
// Delete deletes the metrics from the collection.
func (s Sets) Delete(k string) {
delete(s, k)
}
// DeleteChild deletes the metrics from the collection for the given tags.
func (s Sets) DeleteChild(k, t string) {
delete(s[k], t)
}
// HasChildren returns whether there are more children nested under the key.
func (s Sets) HasChildren(k string) bool {
return len(s[k]) != 0
}
// Each iterates over each set.
func (s Sets) Each(f func(string, string, Set)) {
for key, value := range s {
for tags, set := range value {
f(key, tags, set)
}
}
}