-
Notifications
You must be signed in to change notification settings - Fork 1k
/
debug.go
93 lines (78 loc) · 2.17 KB
/
debug.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
package metrics
import (
"time"
"github.com/runatlantis/atlantis/server/logging"
tally "github.com/uber-go/tally/v4"
)
// newLoggingReporter returns a tally reporter that logs to the provided logger at debug level. This is useful for
// local development where the usual sinks are not available.
func newLoggingReporter(logger logging.SimpleLogging) tally.StatsReporter {
return &debugReporter{log: logger}
}
type debugReporter struct {
log logging.SimpleLogging
}
// Capabilities interface.
func (r *debugReporter) Reporting() bool {
return true
}
func (r *debugReporter) Tagging() bool {
return true
}
func (r *debugReporter) Capabilities() tally.Capabilities {
return r
}
// Reporter interface.
func (r *debugReporter) Flush() {
// Silence.
}
func (r *debugReporter) ReportCounter(name string, tags map[string]string, value int64) {
log := r.log.With("name", name, "value", value, "tags", tags, "type", "counter")
log.Debug("counter")
}
func (r *debugReporter) ReportGauge(name string, tags map[string]string, value float64) {
log := r.log.With("name", name, "value", value, "tags", tags, "type", "gauge")
log.Debug("gauge")
}
func (r *debugReporter) ReportTimer(name string, tags map[string]string, interval time.Duration) {
log := r.log.With("name", name, "value", interval, "tags", tags, "type", "timer")
log.Debug("timer")
}
func (r *debugReporter) ReportHistogramValueSamples(
name string,
tags map[string]string,
buckets tally.Buckets,
bucketLowerBound,
bucketUpperBound float64,
samples int64,
) {
log := r.log.With(
"name", name,
"buckets", buckets.AsValues(),
"bucketLowerBound", bucketLowerBound,
"bucketUpperBound", bucketUpperBound,
"samples", samples,
"tags", tags,
"type", "valueHistogram",
)
log.Debug("histogram")
}
func (r *debugReporter) ReportHistogramDurationSamples(
name string,
tags map[string]string,
buckets tally.Buckets,
bucketLowerBound,
bucketUpperBound time.Duration,
samples int64,
) {
log := r.log.With(
"name", name,
"buckets", buckets.AsValues(),
"bucketLowerBound", bucketLowerBound,
"bucketUpperBound", bucketUpperBound,
"samples", samples,
"tags", tags,
"type", "durationHistogram",
)
log.Debug("histogram")
}