Added RetryMetrics to DataDog and StatsD providers
This commit is contained in:
parent
990ee89650
commit
6b133e24b9
5 changed files with 19 additions and 6 deletions
|
@ -11,7 +11,8 @@ import (
|
|||
"github.com/go-kit/kit/metrics/dogstatsd"
|
||||
)
|
||||
|
||||
var _ Metrics = (Metrics)(nil)
|
||||
var _ Metrics = (*Datadog)(nil)
|
||||
var _ RetryMetrics = (*Datadog)(nil)
|
||||
|
||||
var datadogClient = dogstatsd.New("traefik.", kitlog.LoggerFunc(func(keyvals ...interface{}) error {
|
||||
log.Info(keyvals)
|
||||
|
@ -24,6 +25,7 @@ var datadogTicker *time.Ticker
|
|||
const (
|
||||
ddMetricsReqsName = "requests.total"
|
||||
ddMetricsLatencyName = "request.duration"
|
||||
ddRetriesTotalName = "backend.retries.total"
|
||||
)
|
||||
|
||||
// Datadog is an Implementation for Metrics that exposes datadog metrics for the latency
|
||||
|
@ -55,6 +57,7 @@ func NewDataDog(name string) *Datadog {
|
|||
|
||||
m.reqsCounter = datadogClient.NewCounter(ddMetricsReqsName, 1.0).With("service", name)
|
||||
m.reqDurationHistogram = datadogClient.NewHistogram(ddMetricsLatencyName, 1.0).With("service", name)
|
||||
m.retryCounter = datadogClient.NewCounter(ddRetriesTotalName, 1.0).With("service", name)
|
||||
|
||||
return &m
|
||||
}
|
||||
|
|
|
@ -40,10 +40,16 @@ func TestDatadog(t *testing.T) {
|
|||
req1 := testhelpers.MustNewRequest(http.MethodGet, "http://localhost:3000/ok", nil)
|
||||
req2 := testhelpers.MustNewRequest(http.MethodGet, "http://localhost:3000/not-found", nil)
|
||||
|
||||
retryListener := NewMetricsRetryListener(dd)
|
||||
retryListener.Retried(1)
|
||||
retryListener.Retried(2)
|
||||
|
||||
expected := []string{
|
||||
// We are only validating counts, as it is nearly impossible to validate latency, since it varies every run
|
||||
"traefik.requests.total:1.000000|c|#service:test,code:404,method:GET\n",
|
||||
"traefik.requests.total:1.000000|c|#service:test,code:200,method:GET\n",
|
||||
"traefik.backend.retries.total:2.000000|c|#service:test\n",
|
||||
"traefik.request.duration",
|
||||
}
|
||||
|
||||
udp.ShouldReceiveAll(t, expected, func() {
|
||||
|
|
|
@ -65,10 +65,6 @@ func (mm *MultiMetrics) getRetryCounter() metrics.Counter {
|
|||
return mm.retryCounter
|
||||
}
|
||||
|
||||
func (mm *MultiMetrics) getWrappedMetrics() *[]Metrics {
|
||||
return mm.wrappedMetrics
|
||||
}
|
||||
|
||||
// MetricsWrapper is a Negroni compatible Handler which relies on a
|
||||
// given Metrics implementation to expose and monitor Traefik Metrics.
|
||||
type MetricsWrapper struct {
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"github.com/go-kit/kit/metrics/statsd"
|
||||
)
|
||||
|
||||
var _ Metrics = (Metrics)(nil)
|
||||
var _ Metrics = (*Statsd)(nil)
|
||||
var _ RetryMetrics = (*Statsd)(nil)
|
||||
|
||||
var statsdClient = statsd.New("traefik.", kitlog.LoggerFunc(func(keyvals ...interface{}) error {
|
||||
log.Info(keyvals)
|
||||
|
@ -48,6 +49,7 @@ func NewStatsD(name string) *Statsd {
|
|||
|
||||
m.reqsCounter = statsdClient.NewCounter(ddMetricsReqsName, 1.0).With("service", name)
|
||||
m.reqDurationHistogram = statsdClient.NewTiming(ddMetricsLatencyName, 1.0).With("service", name)
|
||||
m.retryCounter = statsdClient.NewCounter(ddRetriesTotalName, 1.0).With("service", name)
|
||||
|
||||
return &m
|
||||
}
|
||||
|
|
|
@ -40,9 +40,15 @@ func TestStatsD(t *testing.T) {
|
|||
req1 := testhelpers.MustNewRequest(http.MethodGet, "http://localhost:3000/ok", nil)
|
||||
req2 := testhelpers.MustNewRequest(http.MethodGet, "http://localhost:3000/not-found", nil)
|
||||
|
||||
retryListener := NewMetricsRetryListener(c)
|
||||
retryListener.Retried(1)
|
||||
retryListener.Retried(2)
|
||||
|
||||
expected := []string{
|
||||
// We are only validating counts, as it is nearly impossible to validate latency, since it varies every run
|
||||
"traefik.requests.total:2.000000|c\n",
|
||||
"traefik.backend.retries.total:2.000000|c\n",
|
||||
"traefik.request.duration",
|
||||
}
|
||||
|
||||
udp.ShouldReceiveAll(t, expected, func() {
|
||||
|
|
Loading…
Reference in a new issue