@@ -43,8 +43,8 @@ type Metrics map[string]model.Samples
43
43
44
44
// Equal returns true if all metrics are the same as the arguments.
45
45
func (m * Metrics ) Equal (o Metrics ) bool {
46
- leftKeySet := []string {}
47
- rightKeySet := []string {}
46
+ var leftKeySet []string
47
+ var rightKeySet []string
48
48
for k := range * m {
49
49
leftKeySet = append (leftKeySet , k )
50
50
}
@@ -207,22 +207,22 @@ func GetHistogramFromGatherer(gatherer metrics.Gatherer, metricName string) (His
207
207
return Histogram {}, err
208
208
}
209
209
for _ , mFamily := range m {
210
- if mFamily .Name != nil && * mFamily . Name == metricName {
210
+ if mFamily .GetName () == metricName {
211
211
metricFamily = mFamily
212
212
break
213
213
}
214
214
}
215
215
216
216
if metricFamily == nil {
217
- return Histogram {}, fmt .Errorf ("Metric %q not found" , metricName )
217
+ return Histogram {}, fmt .Errorf ("metric %q not found" , metricName )
218
218
}
219
219
220
220
if metricFamily .GetMetric () == nil {
221
- return Histogram {}, fmt .Errorf ("Metric %q is empty" , metricName )
221
+ return Histogram {}, fmt .Errorf ("metric %q is empty" , metricName )
222
222
}
223
223
224
224
if len (metricFamily .GetMetric ()) == 0 {
225
- return Histogram {}, fmt .Errorf ("Metric %q is empty" , metricName )
225
+ return Histogram {}, fmt .Errorf ("metric %q is empty" , metricName )
226
226
}
227
227
228
228
return Histogram {
@@ -277,12 +277,12 @@ func bucketQuantile(q float64, buckets []bucket) float64 {
277
277
// Quantile computes q-th quantile of a cumulative histogram.
278
278
// It's expected the histogram is valid (by calling Validate)
279
279
func (hist * Histogram ) Quantile (q float64 ) float64 {
280
- buckets := []bucket {}
280
+ var buckets []bucket
281
281
282
282
for _ , bckt := range hist .Bucket {
283
283
buckets = append (buckets , bucket {
284
- count : float64 (* bckt .CumulativeCount ),
285
- upperBound : * bckt .UpperBound ,
284
+ count : float64 (bckt .GetCumulativeCount () ),
285
+ upperBound : bckt .GetUpperBound () ,
286
286
})
287
287
}
288
288
@@ -294,7 +294,7 @@ func (hist *Histogram) Quantile(q float64) float64 {
294
294
295
295
// Average computes histogram's average value
296
296
func (hist * Histogram ) Average () float64 {
297
- return * hist .SampleSum / float64 (* hist .SampleCount )
297
+ return hist .GetSampleSum () / float64 (hist .GetSampleCount () )
298
298
}
299
299
300
300
// Clear clears all fields of the wrapped histogram
@@ -314,19 +314,19 @@ func (hist *Histogram) Clear() {
314
314
315
315
// Validate makes sure the wrapped histogram has all necessary fields set and with valid values.
316
316
func (hist * Histogram ) Validate () error {
317
- if hist .SampleCount == nil || * hist .SampleCount == 0 {
317
+ if hist .SampleCount == nil || hist .GetSampleCount () == 0 {
318
318
return fmt .Errorf ("nil or empty histogram SampleCount" )
319
319
}
320
320
321
- if hist .SampleSum == nil || * hist .SampleSum == 0 {
321
+ if hist .SampleSum == nil || hist .GetSampleSum () == 0 {
322
322
return fmt .Errorf ("nil or empty histogram SampleSum" )
323
323
}
324
324
325
325
for _ , bckt := range hist .Bucket {
326
326
if bckt == nil {
327
327
return fmt .Errorf ("empty histogram bucket" )
328
328
}
329
- if bckt .UpperBound == nil || * bckt .UpperBound < 0 {
329
+ if bckt .UpperBound == nil || bckt .GetUpperBound () < 0 {
330
330
return fmt .Errorf ("nil or negative histogram bucket UpperBound" )
331
331
}
332
332
}
@@ -338,7 +338,7 @@ func (hist *Histogram) Validate() error {
338
338
func GetGaugeMetricValue (m metrics.GaugeMetric ) (float64 , error ) {
339
339
metricProto := & dto.Metric {}
340
340
if err := m .Write (metricProto ); err != nil {
341
- return 0 , fmt .Errorf ("Error writing m: %v" , err )
341
+ return 0 , fmt .Errorf ("error writing m: %v" , err )
342
342
}
343
343
return metricProto .Gauge .GetValue (), nil
344
344
}
@@ -347,7 +347,7 @@ func GetGaugeMetricValue(m metrics.GaugeMetric) (float64, error) {
347
347
func GetCounterMetricValue (m metrics.CounterMetric ) (float64 , error ) {
348
348
metricProto := & dto.Metric {}
349
349
if err := m .(metrics.Metric ).Write (metricProto ); err != nil {
350
- return 0 , fmt .Errorf ("Error writing m: %v" , err )
350
+ return 0 , fmt .Errorf ("error writing m: %v" , err )
351
351
}
352
352
return metricProto .Counter .GetValue (), nil
353
353
}
@@ -356,7 +356,7 @@ func GetCounterMetricValue(m metrics.CounterMetric) (float64, error) {
356
356
func GetHistogramMetricValue (m metrics.ObserverMetric ) (float64 , error ) {
357
357
metricProto := & dto.Metric {}
358
358
if err := m .(metrics.Metric ).Write (metricProto ); err != nil {
359
- return 0 , fmt .Errorf ("Error writing m: %v" , err )
359
+ return 0 , fmt .Errorf ("error writing m: %v" , err )
360
360
}
361
361
return metricProto .Histogram .GetSampleSum (), nil
362
362
}
0 commit comments