add metrics for backend_retries_total
This commit is contained in:
parent
7874ffd506
commit
e007bb7546
8 changed files with 530 additions and 125 deletions
48
middlewares/metrics_test.go
Normal file
48
middlewares/metrics_test.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package middlewares
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-kit/kit/metrics"
|
||||
)
|
||||
|
||||
func TestMetricsRetryListener(t *testing.T) {
|
||||
// nil implementation, nothing should fail
|
||||
retryListener := NewMetricsRetryListener(nil)
|
||||
retryListener.Retried(1)
|
||||
|
||||
retryMetrics := newCollectingMetrics()
|
||||
retryListener = NewMetricsRetryListener(retryMetrics)
|
||||
retryListener.Retried(1)
|
||||
retryListener.Retried(2)
|
||||
|
||||
wantCounterValue := float64(2)
|
||||
if retryMetrics.retryCounter.counterValue != wantCounterValue {
|
||||
t.Errorf("got counter value of %d, want %d", retryMetrics.retryCounter.counterValue, wantCounterValue)
|
||||
}
|
||||
}
|
||||
|
||||
// collectingRetryMetrics is an implementation of the RetryMetrics interface that can be used inside tests to collect the times Add() was called.
|
||||
type collectingRetryMetrics struct {
|
||||
retryCounter *collectingCounter
|
||||
}
|
||||
|
||||
func newCollectingMetrics() collectingRetryMetrics {
|
||||
return collectingRetryMetrics{retryCounter: &collectingCounter{}}
|
||||
}
|
||||
|
||||
func (metrics collectingRetryMetrics) getRetryCounter() metrics.Counter {
|
||||
return metrics.retryCounter
|
||||
}
|
||||
|
||||
type collectingCounter struct {
|
||||
counterValue float64
|
||||
}
|
||||
|
||||
func (c *collectingCounter) With(labelValues ...string) metrics.Counter {
|
||||
panic("collectingCounter.With not implemented!")
|
||||
}
|
||||
|
||||
func (c *collectingCounter) Add(delta float64) {
|
||||
c.counterValue += delta
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue