mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
fix(docker-proxy): reduce DB writes to optimize the proxy calls EE-5516 (#9148)
This commit is contained in:
parent
b37120802e
commit
74515f102d
7 changed files with 61 additions and 73 deletions
36
api/http/middlewares/slow_request_logger.go
Normal file
36
api/http/middlewares/slow_request_logger.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package middlewares
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func WithSlowRequestsLogger(next http.Handler) http.Handler {
|
||||
if zerolog.GlobalLevel() > zerolog.DebugLevel {
|
||||
return next
|
||||
}
|
||||
|
||||
burstSampler := &zerolog.BurstSampler{
|
||||
Burst: 1,
|
||||
Period: time.Minute,
|
||||
}
|
||||
|
||||
log := log.With().Logger().Sample(burstSampler)
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
t0 := time.Now()
|
||||
|
||||
next.ServeHTTP(w, req)
|
||||
|
||||
if d := time.Since(t0); d > 100*time.Millisecond {
|
||||
log.Debug().
|
||||
Dur("elapsed_ms", d).
|
||||
Str("method", req.Method).
|
||||
Str("url", req.URL.String()).
|
||||
Msg("slow request")
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue