mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
swarm/api/http: add resetting timer metrics to requests (#18249)
This commit is contained in:
parent
b98d2e9a1c
commit
3ac633ba84
@ -5,6 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/swarm/api"
|
"github.com/ethereum/go-ethereum/swarm/api"
|
||||||
@ -73,9 +74,13 @@ func ParseURI(h http.Handler) http.Handler {
|
|||||||
|
|
||||||
func InitLoggingResponseWriter(h http.Handler) http.Handler {
|
func InitLoggingResponseWriter(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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)
|
writer := newLoggingResponseWriter(w)
|
||||||
h.ServeHTTP(writer, r)
|
h.ServeHTTP(writer, r)
|
||||||
log.Info("request served", "ruid", GetRUID(r.Context()), "code", writer.statusCode)
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user