-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.go
92 lines (80 loc) · 2.8 KB
/
lib.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
package metrics
import (
"time"
gometrics "github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/telemetry"
)
// This file provides a main entrypoint for logging in the v4 protocol.
// TODO(CLOB-1013) Drop both metrics libraries above for a library
// that supports float64 (i.e hashicorp go-metrics)
type Label = gometrics.Label
// IncrCounterWithLabels provides a wrapper functionality for emitting a counter
// metric with global labels (if any) along with the provided labels.
func IncrCounterWithLabels(key string, val float32, labels ...Label) {
telemetry.IncrCounterWithLabels([]string{key}, val, labels)
}
// IncrCounter provides a wrapper functionality for emitting a counter
// metric with global labels (if any).
func IncrCounter(key string, val float32) {
telemetry.IncrCounterWithLabels([]string{key}, val, []gometrics.Label{})
}
// SetGaugeWithLabels provides a wrapper functionality for emitting a gauge
// metric with global labels (if any) along with the provided labels.
func SetGaugeWithLabels(key string, val float32, labels ...gometrics.Label) {
telemetry.SetGaugeWithLabels([]string{key}, val, labels)
}
// SetGauge provides a wrapper functionality for emitting a gauge
// metric with global labels (if any).
func SetGauge(key string, val float32) {
telemetry.SetGaugeWithLabels([]string{key}, val, []gometrics.Label{})
}
// AddSampleWithLabels provides a wrapper functionality for emitting a sample
// metric with the provided labels.
func AddSampleWithLabels(key string, val float32, labels ...gometrics.Label) {
gometrics.AddSampleWithLabels(
[]string{key},
val,
labels,
)
}
// AddSample provides a wrapper functionality for emitting a sample
// metric.
func AddSample(key string, val float32) {
gometrics.AddSampleWithLabels(
[]string{key},
val,
[]gometrics.Label{},
)
}
// ModuleMeasureSince provides a wrapper functionality for emitting a time measure
// metric with global labels (if any).
// Please try to use `AddSample` instead.
// TODO(CLOB-1022) Roll our own calculations for timing on top of AddSample instead
// of using MeasureSince.
func ModuleMeasureSince(module string, key string, start time.Time) {
telemetry.ModuleMeasureSince(
module,
start,
key,
)
}
// ModuleMeasureSinceWithLabels provides a short hand method for emitting a time measure
// metric for a module with labels. Global labels are not included in this metric.
// Please try to use `AddSampleWithLabels` instead.
// TODO(CLOB-1022) Roll our own calculations for timing on top of AddSample instead
// of using MeasureSince.
func ModuleMeasureSinceWithLabels(
module string,
keys []string,
start time.Time,
labels []gometrics.Label,
) {
gometrics.MeasureSinceWithLabels(
keys,
start.UTC(),
append(
[]gometrics.Label{telemetry.NewLabel(telemetry.MetricLabelNameModule, module)},
labels...,
),
)
}