Skip to content

Commit 79e8c05

Browse files
committed
port label change to all the metrics methods
1 parent b2fd51a commit 79e8c05

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

metriks/metriks.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func Inc(name string, val int64, labels ...metrics.Label) {
142142
// metriks.IncLabels("publisher.errors", metriks.Labels(metriks.L("status_class", "4xx")), 1)
143143
//
144144
func IncLabels(name string, labels []metrics.Label, val int64) {
145-
metrics.IncrCounterWithLabels([]string{name}, float32(val), labels)
145+
Inc(name, val, labels...)
146146
}
147147

148148
// MeasureSince records the time from start until the invocation of the function
@@ -157,13 +157,17 @@ func IncLabels(name string, labels []metrics.Label, val int64) {
157157
// return db.Execute(query)
158158
// }
159159
//
160-
func MeasureSince(name string, start time.Time) {
161-
metrics.MeasureSince([]string{name}, start)
160+
func MeasureSince(name string, start time.Time, labels ...metrics.Label) {
161+
if len(labels) > 0 {
162+
metrics.MeasureSinceWithLabels([]string{name}, start, labels)
163+
} else {
164+
metrics.MeasureSince([]string{name}, start)
165+
}
162166
}
163167

164168
// MeasureSinceLabels is the same as MeasureSince, but with additional labels
165169
func MeasureSinceLabels(name string, labels []metrics.Label, start time.Time) {
166-
metrics.MeasureSinceWithLabels([]string{name}, start, labels)
170+
MeasureSince(name, start, labels...)
167171
}
168172

169173
// Sample records a float32 sample as part of a histogram. This will get histogram
@@ -173,25 +177,33 @@ func MeasureSinceLabels(name string, labels []metrics.Label, start time.Time) {
173177
//
174178
// metriks.Sample("publisher-payload-size", float32(len(payload)))
175179
//
176-
func Sample(name string, val float32) {
177-
metrics.AddSample([]string{name}, val)
180+
func Sample(name string, val float32, labels ...metrics.Label) {
181+
if len(labels) > 0 {
182+
metrics.AddSampleWithLabels([]string{name}, val, labels)
183+
} else {
184+
metrics.AddSample([]string{name}, val)
185+
}
178186
}
179187

180188
// SampleLabels is the same as Sample but with additional labels
181189
func SampleLabels(name string, labels []metrics.Label, val float32) {
182-
metrics.AddSampleWithLabels([]string{name}, val, labels)
190+
Sample(name, val, labels...)
183191
}
184192

185193
// Gauge is used to report a single float32 value. It is most often used during a
186194
// periodic update or timer to report the current size of a queue or how many
187195
// connections are currently connected.
188-
func Gauge(name string, val float32) {
189-
metrics.SetGauge([]string{name}, val)
196+
func Gauge(name string, val float32, labels ...metrics.Label) {
197+
if len(labels) > 0 {
198+
metrics.SetGaugeWithLabels([]string{name}, val, labels)
199+
} else {
200+
metrics.SetGauge([]string{name}, val)
201+
}
190202
}
191203

192204
// GaugeLabels is the same as Gauge but with additional labels
193205
func GaugeLabels(name string, labels []metrics.Label, val float32) {
194-
metrics.SetGaugeWithLabels([]string{name}, val, labels)
206+
Gauge(name, val, labels...)
195207
}
196208

197209
func statsdAddr(conf Config) string {

0 commit comments

Comments
 (0)