Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func main() {
return apiconfig.DefaultRevisionTimeoutSeconds * time.Second,
apiconfig.DefaultRevisionResponseStartTimeoutSeconds * time.Second,
apiconfig.DefaultRevisionIdleTimeoutSeconds * time.Second
})
}, logger)
ah = concurrencyReporter.Handler(ah)
ah = activatorhandler.NewTracingAttributeHandler(tp, ah)
reqLogHandler, err := pkghttp.NewRequestLogHandler(ah, logging.NewSyncFileWriter(os.Stdout), "",
Expand Down
8 changes: 7 additions & 1 deletion pkg/http/handler/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"
"time"

"go.uber.org/zap"
"k8s.io/utils/clock"
"knative.dev/pkg/websocket"
)
Expand All @@ -37,6 +38,7 @@ type timeoutHandler struct {
timeoutFunc TimeoutFunc
body string
clock clock.Clock
logger *zap.SugaredLogger
}

// NewTimeoutHandler returns a Handler that runs `h` with the
Expand All @@ -55,12 +57,13 @@ type timeoutHandler struct {
// https://golang.org/pkg/net/http/#Handler.
//
// The implementation is largely inspired by http.TimeoutHandler.
func NewTimeoutHandler(h http.Handler, msg string, timeoutFunc TimeoutFunc) http.Handler {
func NewTimeoutHandler(h http.Handler, msg string, timeoutFunc TimeoutFunc, logger *zap.SugaredLogger) http.Handler {
return &timeoutHandler{
handler: h,
body: msg,
timeoutFunc: timeoutFunc,
clock: clock.RealClock{},
logger: logger,
}
}

Expand Down Expand Up @@ -128,12 +131,14 @@ func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case <-timeout.C():
timeoutDrained = true
if tw.tryTimeoutAndWriteError(h.body) {
h.logger.Warnf("Request timeout: %v", revTimeout)
return
}
case now := <-idleTimeoutCh:
timedOut, timeToNextTimeout := tw.tryIdleTimeoutAndWriteError(now, revIdleTimeout, h.body)
if timedOut {
idleTimeoutDrained = true
h.logger.Warnf("Idle timeout: %v", revIdleTimeout)
return
}
idleTimeout.Reset(timeToNextTimeout)
Expand All @@ -143,6 +148,7 @@ func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
responseStartTimeoutDrained = true
timedOut := tw.tryResponseStartTimeoutAndWriteError(h.body)
if timedOut {
h.logger.Warnf("Response start timeout: %v", revResponseStartTimeout)
return
}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/http/handler/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"
"time"

"go.uber.org/zap/zaptest"
"k8s.io/utils/clock"
clocktest "k8s.io/utils/clock/testing"
)
Expand Down Expand Up @@ -223,6 +224,7 @@ func testTimeoutScenario(t *testing.T, scenarios []timeoutHandlerTestScenario) {
body: scenario.timeoutMessage,
timeoutFunc: StaticTimeoutFunc(scenario.timeout, scenario.responseStartTimeout, scenario.idleTimeout),
clock: fakeClock,
logger: zaptest.NewLogger(t).Sugar(),
}

defer func() {
Expand Down Expand Up @@ -350,7 +352,7 @@ func TestResponseStartTimeoutAfterResponseStarted(t *testing.T) {

// Create timeout handler with a responseStartTimeout
timeoutHandler := NewTimeoutHandler(handler, "timeout",
StaticTimeoutFunc(30*time.Second, 50*time.Millisecond, 0))
StaticTimeoutFunc(30*time.Second, 50*time.Millisecond, 0), zaptest.NewLogger(t).Sugar())

req := httptest.NewRequest(http.MethodGet, "/", nil)
rr := httptest.NewRecorder()
Expand Down Expand Up @@ -604,7 +606,7 @@ func BenchmarkTimeoutHandler(b *testing.B) {
w.Write(write)
}
})
handler := NewTimeoutHandler(baseHandler, "test", StaticTimeoutFunc(10*time.Minute, 10*time.Minute, 10*time.Minute))
handler := NewTimeoutHandler(baseHandler, "test", StaticTimeoutFunc(10*time.Minute, 10*time.Minute, 10*time.Minute), zaptest.NewLogger(b).Sugar())
req := httptest.NewRequest(http.MethodPost, "http://example.com", nil)

b.Run("sequential", func(b *testing.B) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/queue/sharedmain/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func mainHandler(
composedHandler = queue.ForwardedShimHandler(composedHandler)
composedHandler = handler.NewTimeoutHandler(composedHandler, "request timeout", func(r *http.Request) (time.Duration, time.Duration, time.Duration) {
return timeout, responseStartTimeout, idleTimeout
})
}, logger)

composedHandler = queue.NewRouteTagHandler(composedHandler)
composedHandler = withFullDuplex(composedHandler, env.EnableHTTPFullDuplex, logger)
Expand Down
Loading