prometheus, HTTP method and utf8
This commit is contained in:
parent
286d882f1e
commit
651d993d9c
1 changed files with 12 additions and 2 deletions
|
@ -4,7 +4,9 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/containous/traefik/log"
|
||||||
"github.com/containous/traefik/metrics"
|
"github.com/containous/traefik/metrics"
|
||||||
gokitmetrics "github.com/go-kit/kit/metrics"
|
gokitmetrics "github.com/go-kit/kit/metrics"
|
||||||
)
|
)
|
||||||
|
@ -17,7 +19,7 @@ type MetricsWrapper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMetricsWrapper return a MetricsWrapper struct with
|
// NewMetricsWrapper return a MetricsWrapper struct with
|
||||||
// a given Metrics implementation e.g Prometheuss
|
// a given Metrics implementation
|
||||||
func NewMetricsWrapper(registry metrics.Registry, service string) *MetricsWrapper {
|
func NewMetricsWrapper(registry metrics.Registry, service string) *MetricsWrapper {
|
||||||
var metricsWrapper = MetricsWrapper{
|
var metricsWrapper = MetricsWrapper{
|
||||||
registry: registry,
|
registry: registry,
|
||||||
|
@ -32,7 +34,7 @@ func (m *MetricsWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Request, next
|
||||||
prw := &responseRecorder{rw, http.StatusOK}
|
prw := &responseRecorder{rw, http.StatusOK}
|
||||||
next(prw, r)
|
next(prw, r)
|
||||||
|
|
||||||
reqLabels := []string{"service", m.serviceName, "code", strconv.Itoa(prw.statusCode), "method", r.Method}
|
reqLabels := []string{"service", m.serviceName, "code", strconv.Itoa(prw.statusCode), "method", getMethod(r)}
|
||||||
m.registry.ReqsCounter().With(reqLabels...).Add(1)
|
m.registry.ReqsCounter().With(reqLabels...).Add(1)
|
||||||
|
|
||||||
reqDurationLabels := []string{"service", m.serviceName, "code", strconv.Itoa(prw.statusCode)}
|
reqDurationLabels := []string{"service", m.serviceName, "code", strconv.Itoa(prw.statusCode)}
|
||||||
|
@ -48,6 +50,14 @@ func NewMetricsRetryListener(retryMetrics retryMetrics, backendName string) Retr
|
||||||
return &MetricsRetryListener{retryMetrics: retryMetrics, backendName: backendName}
|
return &MetricsRetryListener{retryMetrics: retryMetrics, backendName: backendName}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMethod(r *http.Request) string {
|
||||||
|
if !utf8.ValidString(r.Method) {
|
||||||
|
log.Warnf("Invalid HTTP method encoding: %s", r.Method)
|
||||||
|
return "NON_UTF8_HTTP_METHOD"
|
||||||
|
}
|
||||||
|
return r.Method
|
||||||
|
}
|
||||||
|
|
||||||
// MetricsRetryListener is an implementation of the RetryListener interface to
|
// MetricsRetryListener is an implementation of the RetryListener interface to
|
||||||
// record RequestMetrics about retry attempts.
|
// record RequestMetrics about retry attempts.
|
||||||
type MetricsRetryListener struct {
|
type MetricsRetryListener struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue