Skip to content

Commit fa31eca

Browse files
authored
Merge pull request #308 from SiaFoundation/log-slow-api-responses
log warning when API response time exceeds 10 seconds
2 parents 5f563d7 + b3a873a commit fa31eca

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
# Log warning when API response time exceeds 10 seconds

cmd/explored/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ func runRootCmd(ctx context.Context, log *zap.Logger) error {
309309
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
310310
if strings.HasPrefix(r.URL.Path, "/api") {
311311
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/api")
312+
start := time.Now()
312313
api.ServeHTTP(w, r)
314+
if dur := time.Since(start); dur >= 10*time.Second {
315+
log.Warn("slow API request", zap.String("method", r.Method), zap.String("path", r.URL.Path), zap.Duration("elapsed", dur))
316+
}
313317
return
314318
}
315319
http.NotFound(w, r)

0 commit comments

Comments
 (0)