forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.go
105 lines (91 loc) · 1.77 KB
/
point.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
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
package models
import (
"bytes"
"sort"
)
type GroupID string
const (
NilGroup GroupID = ""
)
type Dimensions struct {
ByName bool
TagNames []string
}
func (d Dimensions) Equal(o Dimensions) bool {
if d.ByName != o.ByName || len(d.TagNames) != len(o.TagNames) {
return false
}
for i := range d.TagNames {
if d.TagNames[i] != o.TagNames[i] {
return false
}
}
return true
}
func (d Dimensions) Copy() Dimensions {
tags := make([]string, len(d.TagNames))
copy(tags, d.TagNames)
return Dimensions{ByName: d.ByName, TagNames: tags}
}
func (d Dimensions) ToSet() map[string]bool {
set := make(map[string]bool, len(d.TagNames))
for _, dim := range d.TagNames {
set[dim] = true
}
return set
}
type Fields map[string]interface{}
func (f Fields) Copy() Fields {
cf := make(Fields, len(f))
for k, v := range f {
cf[k] = v
}
return cf
}
func SortedFields(fields Fields) []string {
a := make([]string, 0, len(fields))
for k := range fields {
a = append(a, k)
}
sort.Strings(a)
return a
}
type Tags map[string]string
func (t Tags) Copy() Tags {
ct := make(Tags, len(t))
for k, v := range t {
ct[k] = v
}
return ct
}
func SortedKeys(tags map[string]string) []string {
a := make([]string, 0, len(tags))
for k := range tags {
a = append(a, k)
}
sort.Strings(a)
return a
}
func ToGroupID(name string, tags map[string]string, dims Dimensions) GroupID {
if len(dims.TagNames) == 0 {
if dims.ByName {
return GroupID(name)
}
return NilGroup
}
var buf bytes.Buffer
if dims.ByName {
buf.WriteString(name)
// Add delimiter that is not allowed in name.
buf.WriteRune('\n')
}
for i, d := range dims.TagNames {
if i != 0 {
buf.WriteRune(',')
}
buf.WriteString(d)
buf.WriteRune('=')
buf.WriteString(tags[d])
}
return GroupID(buf.Bytes())
}