-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.go
53 lines (39 loc) · 1021 Bytes
/
counter.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
package stats
type CounterVector interface {
WithLabels(...string) Counter
}
type Counter interface {
Inc()
Add(int64)
Get() int64
}
type counterVector struct {
*atomicInt64Vector
}
func (cv counterVector) WithLabels(ls ...string) Counter {
return cv.fetchValue(ls)
}
type partialCounterVector struct {
cv CounterVector
vs []string
}
func (pcv partialCounterVector) WithLabels(ls ...string) Counter {
return pcv.cv.WithLabels(append(pcv.vs, ls...)...)
}
type reorderCounterVector struct {
cv CounterVector
labelOrderer
}
func (rcv reorderCounterVector) WithLabels(ls ...string) Counter {
return rcv.cv.WithLabels(rcv.order(ls)...)
}
var (
NoopCounter Counter = noopCounter{}
NoopCounterVector CounterVector = noopCounterVector{}
)
type noopCounter struct{}
func (noopCounter) Inc() {}
func (noopCounter) Add(int64) {}
func (noopCounter) Get() int64 { return 0 }
type noopCounterVector struct{}
func (noopCounterVector) WithLabels(...string) Counter { return noopCounter{} }