Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,15 @@ func (s *Server) handleRequestHTTP(chain string) http.HandlerFunc {
first400EndpointID = ""
}

// Increment the request count and track success for debouncing
// Increment the request count and track success for debouncing.
// Use a fresh context to ensure metrics are recorded even if the
// request context is close to expiring.
log.Debug().Str("chain", chain).Str("endpoint", endpoint.ID).Str("endpoint_url", helpers.RedactAPIKey(endpoint.Endpoint.HTTPURL)).Int("retry", retryCount).Msg("HTTP request succeeded")
if err := s.valkeyClient.IncrementRequestCount(ctx, chain, endpoint.ID, "proxy_requests"); err != nil {
metricsCtx, metricsCancel := context.WithTimeout(context.Background(), 5*time.Second)
if err := s.valkeyClient.IncrementRequestCount(metricsCtx, chain, endpoint.ID, "proxy_requests"); err != nil {
log.Error().Err(err).Str("endpoint", endpoint.ID).Msg("Failed to increment request count")
}
metricsCancel()
// Track success for health debouncing
s.markEndpointHealthyAttempt(chain, endpoint.ID, "http")
return
Expand Down Expand Up @@ -732,10 +736,14 @@ func (s *Server) handleRequestWS(chain string) http.HandlerFunc {
}

// Increment the request count and track success for debouncing.
// Use a fresh context since WebSocket connections are long-lived and
// the original request context may have expired.
log.Debug().Str("chain", chain).Str("endpoint", endpoint.ID).Str("endpoint_url", helpers.RedactAPIKey(endpoint.Endpoint.WSURL)).Int("retry", retryCount).Msg("WebSocket connection succeeded")
if err := s.valkeyClient.IncrementRequestCount(ctx, chain, endpoint.ID, "proxy_requests"); err != nil {
metricsCtx, metricsCancel := context.WithTimeout(context.Background(), 5*time.Second)
if err := s.valkeyClient.IncrementRequestCount(metricsCtx, chain, endpoint.ID, "proxy_requests"); err != nil {
log.Error().Err(err).Str("endpoint", endpoint.ID).Msg("Failed to increment WebSocket request count")
}
metricsCancel()
// Track success for health debouncing
s.markEndpointHealthyAttempt(chain, endpoint.ID, "ws")
return
Expand Down