Skip to content

Commit

Permalink
swarm/api/http: add resetting timer metrics to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
acud committed Dec 5, 2018
1 parent edc39aa commit 373e9d2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions swarm/api/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"runtime/debug"
"strings"
"time"

"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/swarm/api"
Expand Down Expand Up @@ -73,9 +74,13 @@ func ParseURI(h http.Handler) http.Handler {

func InitLoggingResponseWriter(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.time", r.Method), nil).UpdateSince(startTime)

writer := newLoggingResponseWriter(w)
h.ServeHTTP(writer, r)
log.Info("request served", "ruid", GetRUID(r.Context()), "code", writer.statusCode)
metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.%d.time", r.Method, writer.statusCode), nil).UpdateSince(startTime)
})
}

Expand Down

0 comments on commit 373e9d2

Please sign in to comment.