-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter_vec.go
141 lines (121 loc) · 4.21 KB
/
counter_vec.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
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
package metrics
// A Uint64Vec is a collection of Uint64s that are partitioned
// by the same metric name and tag labels, but different tag values.
type Uint64Vec struct {
commonVec
}
// NewUint64Vec creates a new Uint64Vec on the global Set.
// See [Set.NewUint64Vec].
func NewUint64Vec(family string, labels ...string) *Uint64Vec {
return defaultSet.NewUint64Vec(family, labels...)
}
// NewCounterVec creates a new Uint64Vec on the global Set.
// See [Set.NewUint64Vec].
func NewCounterVec(family string, labels ...string) *Uint64Vec {
return defaultSet.NewCounterVec(family, labels...)
}
// WithLabelValues returns the Uint64 for the corresponding label values.
// If the combination of values is seen for the first time, a new Uint
// is created.
//
// This will panic if the values count doesn't match the number of labels.
func (c *Uint64Vec) WithLabelValues(values ...string) *Uint64 {
set := c.set
if set == nil {
set = c.setvec.WithLabelValue(values[0])
values = values[1:]
}
return c.withLabelValues(set, values)
}
func (c *Uint64Vec) withLabelValues(set *Set, values []string) *Uint64 {
hash := hashFinish(c.partialHash, values...)
nm, ok := set.metrics.Load(hash)
if !ok {
nm = set.loadOrStoreMetricFromVec(
&Uint64{}, hash, c.family, c.partialTags, values,
)
}
return nm.metric.(*Uint64)
}
// NewUint64Vec creates a new [Uint64Vec] with the supplied name.
func (s *Set) NewUint64Vec(family string, labels ...string) *Uint64Vec {
return &Uint64Vec{getCommonVecSet(s, family, labels)}
}
// NewCounterVec is an alias for [Set.NewUint64Vec].
func (s *Set) NewCounterVec(family string, labels ...string) *Uint64Vec {
return s.NewUint64Vec(family, labels...)
}
// A Int64Vec is a collection of Int64s that are partitioned
// by the same metric name and tag labels, but different tag values.
type Int64Vec struct {
commonVec
}
// NewInt64Vec creates a new Int64Vec on the global Set.
// See [Set.NewInt64Vec].
func NewInt64Vec(family string, labels ...string) *Int64Vec {
return defaultSet.NewInt64Vec(family, labels...)
}
// WithLabelValues returns the Int64 for the corresponding label values.
// If the combination of values is seen for the first time, a new Int
// is created.
//
// This will panic if the values count doesn't match the number of labels.
func (c *Int64Vec) WithLabelValues(values ...string) *Int64 {
set := c.set
if set == nil {
set = c.setvec.WithLabelValue(values[0])
values = values[1:]
}
return c.withLabelValues(set, values)
}
func (c *Int64Vec) withLabelValues(set *Set, values []string) *Int64 {
hash := hashFinish(c.partialHash, values...)
nm, ok := set.metrics.Load(hash)
if !ok {
nm = set.loadOrStoreMetricFromVec(
&Int64{}, hash, c.family, c.partialTags, values,
)
}
return nm.metric.(*Int64)
}
// NewInt64Vec creates a new [Int64Vec] with the supplied name.
func (s *Set) NewInt64Vec(family string, labels ...string) *Int64Vec {
return &Int64Vec{getCommonVecSet(s, family, labels)}
}
// A Float64Vec is a collection of Float64s that are partitioned
// by the same metric name and tag labels, but different tag values.
type Float64Vec struct {
commonVec
}
// NewFloat64Vec creates a new Float64Vec on the global Set.
// See [Set.NewFloat64Vec].
func NewFloat64Vec(family string, labels ...string) *Float64Vec {
return defaultSet.NewFloat64Vec(family, labels...)
}
// WithLabelValues returns the Float for the corresponding label values.
// If the combination of values is seen for the first time, a new Float
// is created.
//
// This will panic if the values count doesn't match the number of labels.
func (c *Float64Vec) WithLabelValues(values ...string) *Float64 {
set := c.set
if set == nil {
set = c.setvec.WithLabelValue(values[0])
values = values[1:]
}
return c.withLabelValues(set, values)
}
func (c *Float64Vec) withLabelValues(set *Set, values []string) *Float64 {
hash := hashFinish(c.partialHash, values...)
nm, ok := set.metrics.Load(hash)
if !ok {
nm = set.loadOrStoreMetricFromVec(
&Float64{}, hash, c.family, c.partialTags, values,
)
}
return nm.metric.(*Float64)
}
// NewFloat64Vec creates a new [Float64Vec] with the supplied name.
func (s *Set) NewFloat64Vec(family string, labels ...string) *Float64Vec {
return &Float64Vec{getCommonVecSet(s, family, labels)}
}