Skip to content

Commit

Permalink
Revert "Debug HTTPLoggingMiddleware latency."
Browse files Browse the repository at this point in the history
This reverts commit ae86b1c.
  • Loading branch information
mpass99 committed Feb 6, 2024
1 parent a44061d commit 895dd88
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package logging

import (
"bufio"
"context"
"fmt"
"github.com/coreos/go-systemd/v22/daemon"
"github.com/getsentry/sentry-go"
"github.com/openHPI/poseidon/pkg/dto"
"github.com/sirupsen/logrus"
"net"
"net/http"
"os"
"runtime/pprof"
"strings"
"time"
)
Expand Down Expand Up @@ -85,12 +82,6 @@ func HTTPLoggingMiddleware(next http.Handler) http.Handler {
start := time.Now().UTC()
path := RemoveNewlineSymbol(r.URL.Path)

if path == "/api/v1/health" {
ctx, cancel := context.WithCancel(r.Context())
defer cancel()
go debugGoroutines(ctx)
}

lrw := NewLoggingResponseWriter(w)
next.ServeHTTP(lrw, r)

Expand All @@ -116,24 +107,3 @@ func RemoveNewlineSymbol(data string) string {
data = strings.ReplaceAll(data, "\n", "")
return data
}

// debugGoroutines temporarily debugs a behavior where we observe long latencies in the Health route.
func debugGoroutines(ctx context.Context) {
interval, err := daemon.SdWatchdogEnabled(false)
if err != nil || interval == 0 {
return
}
log.Trace("Starting timeout for debugging the Goroutines")

const notificationIntervalFactor = 3
select {
case <-ctx.Done():
return
case <-time.After(interval / notificationIntervalFactor):
log.Warn("Health route latency is too high")
err := pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
if err != nil {
log.WithError(err).Warn("Failed to log the goroutines")
}
}
}

0 comments on commit 895dd88

Please sign in to comment.