-
Notifications
You must be signed in to change notification settings - Fork 281
/
nop_reporter.go
130 lines (99 loc) · 4.31 KB
/
nop_reporter.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
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package metrics
import (
"time"
"github.com/uber-go/tally"
)
var (
capabilitiesReportingNoTagging = &capabilities{
reporting: true,
tagging: false,
}
)
type capabilities struct {
reporting bool
tagging bool
}
func (c *capabilities) Reporting() bool {
return c.reporting
}
func (c *capabilities) Tagging() bool {
return c.tagging
}
// NopCachedStatsReporter is an implementation of tally.CachedStatsReporter that simply does nothing
// and should be used for testing purposes only.
// TODO:(anup) This should exist in tally. https://github.com/uber-go/tally/issues/23
// Remove and replace metrics.NopCachedStatsReporter with tally.NopCachedStatsReporter once issue is resolved
var NopCachedStatsReporter tally.CachedStatsReporter = nopCachedStatsReporter{}
type nopCachedStatsReporter struct{}
func (nopCachedStatsReporter) AllocateCounter(name string, tags map[string]string) tally.CachedCount {
return NopCachedCount
}
func (nopCachedStatsReporter) AllocateGauge(name string, tags map[string]string) tally.CachedGauge {
return NopCachedGauge
}
func (nopCachedStatsReporter) AllocateHistogram(name string, tags map[string]string, buckets tally.Buckets) tally.CachedHistogram {
return NopCachedHistogram
}
func (nopCachedStatsReporter) AllocateTimer(name string, tags map[string]string) tally.CachedTimer {
return NopCachedTimer
}
func (r nopCachedStatsReporter) Capabilities() tally.Capabilities {
return capabilitiesReportingNoTagging
}
func (r nopCachedStatsReporter) Flush() {}
// NopCachedCount is an implementation of tally.CachedCount and same as other Nop types don't do anything and
// should be used for testing purposes only.
var NopCachedCount tally.CachedCount = nopCachedCount{}
type nopCachedCount struct {
}
func (nopCachedCount) ReportCount(value int64) {
}
// NopCachedGauge is an implementation of tally.CachedGauge and same as other Nop types don't do anything and
// should be used for testing purposes only.
var NopCachedGauge tally.CachedGauge = nopCachedGauge{}
type nopCachedGauge struct{}
func (nopCachedGauge) ReportGauge(value float64) {}
// NopCachedTimer is an implementation of tally.CachedTimer
var NopCachedTimer tally.CachedTimer = nopCachedTimer{}
type nopCachedTimer struct{}
func (nopCachedTimer) ReportTimer(interval time.Duration) {}
// NopCachedHistogram is an implementation of tally.CachedHistogram and same as other Nop types don't do anything and
// should be used for testing purposes only.
var NopCachedHistogram tally.CachedHistogram = nopCachedHistogram{}
type nopCachedHistogram struct{}
func (nopCachedHistogram) ValueBucket(
bucketLowerBound float64,
bucketUpperBound float64,
) tally.CachedHistogramBucket {
return nopCachedHistogramBucket{}
}
func (nopCachedHistogram) DurationBucket(
bucketLowerBound time.Duration,
bucketUpperBound time.Duration,
) tally.CachedHistogramBucket {
return nopCachedHistogramBucket{}
}
// NopCachedHistogramBucket is an implementation of tally.CachedHistogramBucket and same as other Nop types
// don't do anything and should be used for testing purposes only.
var NopCachedHistogramBucket tally.CachedHistogramBucket = nopCachedHistogramBucket{}
type nopCachedHistogramBucket struct{}
func (nopCachedHistogramBucket) ReportSamples(value int64) {}