-
Notifications
You must be signed in to change notification settings - Fork 20
/
noop.go
117 lines (95 loc) · 2.03 KB
/
noop.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
package monitoring
import (
"fmt"
"time"
"github.com/go-masonry/mortar/interfaces/monitor"
)
type noop struct {
name, desc string
err error
onError func(error)
}
type noopCounter struct {
*noop
}
func (n *noopCounter) WithTags(tags map[string]string) (monitor.Counter, error) {
return n, nil
}
func newNoopCounter(name, desc string, err error, onError func(error)) monitor.BricksCounter {
return &noopCounter{&noop{
err: err,
onError: onError,
name: name,
desc: desc,
}}
}
type noopGauge struct {
*noop
}
func (n *noopGauge) WithTags(tags map[string]string) (monitor.Gauge, error) {
return n, nil
}
func newNoopGauge(name, desc string, err error, onError func(error)) monitor.BricksGauge {
return &noopGauge{&noop{
err: err,
onError: onError,
name: name,
desc: desc,
}}
}
type noopHistogram struct {
*noop
}
func (n *noopHistogram) WithTags(tags map[string]string) (monitor.Histogram, error) {
return n, nil
}
func newNoopHistogram(name, desc string, err error, onError func(error)) monitor.BricksHistogram {
return &noopHistogram{&noop{
err: err,
onError: onError,
name: name,
desc: desc,
}}
}
type noopTimer struct {
*noop
}
func (n *noopTimer) WithTags(tags map[string]string) (monitor.Timer, error) {
return n, nil
}
func (n *noopTimer) Record(d time.Duration) {
n.noop.Record(d.Seconds())
}
func newNoopTimer(name, desc string, err error, onError func(error)) monitor.BricksTimer {
return &noopTimer{&noop{
err: err,
onError: onError,
name: name,
desc: desc,
}}
}
// Inc increments the counter by 1
func (n *noop) Inc() {
n.do()
}
// Add adds the given value to the counter, negative values are not advised
func (n *noop) Add(v float64) {
n.do()
}
// Record value
func (n *noop) Record(v float64) {
n.do()
}
// Set sets Gauge value
func (n *noop) Set(v float64) {
n.do()
}
// Dec adds -1
func (n *noop) Dec() {
n.do()
}
func (n *noop) do() {
n.onError(
fmt.Errorf("still trying to use failed metric %s:%s, %w", n.name, n.desc, n.err),
)
}