Skip to content

Adding configurability to the interceptor's HTTP round tripper #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
43e8eff
multi-tenant interceptor and scaler
arschles Jul 1, 2021
cbe11ec
Merge branch 'main' of github.com:kedacore/http-add-on into global-co…
arschles Aug 18, 2021
7bb4e11
Merge branch 'main' of github.com:kedacore/http-add-on into global-co…
arschles Aug 18, 2021
9d7fae6
specifying host in XKCD ingress
arschles Aug 18, 2021
e6a6d67
routing the xkcd chart to the interceptor properly
arschles Aug 18, 2021
20dac47
check host header first
arschles Aug 19, 2021
a3c0403
sending true active response in stream
arschles Aug 19, 2021
ff8a3c0
passing target pending requests through to the underlying ScaledObjec…
arschles Aug 19, 2021
ee8ef79
removing broken target pending requests
arschles Aug 19, 2021
966e8ce
using getHost in proxy handler
arschles Aug 20, 2021
b96f209
adding integration test
arschles Aug 20, 2021
1123c70
adding more tests to the integration test
arschles Aug 20, 2021
013915e
splitting up integration tests
arschles Aug 20, 2021
f63ad32
more checks
arschles Aug 20, 2021
37fe73b
mark new test TODO
arschles Aug 20, 2021
6078beb
expanding interceptor integration tests
arschles Aug 20, 2021
18452c3
error messages
arschles Aug 20, 2021
9b708e0
refactor test
arschles Aug 20, 2021
8db0df4
more test improvements
arschles Aug 20, 2021
647eaae
rolling back target pending requests in ScaledObject
arschles Aug 20, 2021
3b34131
removing target metric error. it's not used anymore
arschles Aug 20, 2021
9bda86e
improving waitFunc test
arschles Aug 23, 2021
76117d5
Refactoring the deployment cache to add better error handing and resi…
arschles Aug 23, 2021
69d4c0f
adding doc comment
arschles Aug 23, 2021
1039b92
refactoring deploy cache and adding tests
arschles Aug 23, 2021
bebce95
Using interfaces for deployment watch & list
arschles Aug 23, 2021
904b754
adding more deploy cache tests
arschles Aug 23, 2021
0c1dd47
Fixing up TestK8sDeploymentCacheRewatch
arschles Aug 23, 2021
ae28597
shutting down everything else when one thing errors, and adding a dep…
arschles Aug 24, 2021
a083ac7
removing commented code
arschles Aug 24, 2021
a0dc40c
clarifying deployment cache JSON output, and simplifying deployment w…
arschles Aug 24, 2021
15b46e8
adding TODO tests
arschles Aug 24, 2021
16762d0
error logs and restoring the count middleware
arschles Aug 24, 2021
3f32b2e
using consistent net/http package name throughout main.go
arschles Aug 24, 2021
e316986
Refactoring deployment cache deployment storage
arschles Aug 24, 2021
33dd3f2
using deployment.Status.ReadyReplicas, instead of just replicas
arschles Aug 24, 2021
1539e34
integration_tets ==> proxy_handlers_integration_test
arschles Aug 24, 2021
02abdb6
adding some resilience to tests
arschles Aug 24, 2021
db588d0
adding deployment cache endpoint documentation
arschles Aug 24, 2021
0bc461b
Merge branch 'main' of github.com:kedacore/http-add-on into global-co…
arschles Aug 24, 2021
b45fd22
running the global test target with sh.RunV
arschles Aug 30, 2021
570e259
adding timeout to magefile test target
arschles Aug 30, 2021
0a3b321
finishing one TODO test and adding issue for the rest:
arschles Aug 30, 2021
2d21ac0
Adding configurability to the interceptor's HTTP round tripper
arschles Sep 1, 2021
e496fdd
Merge branch 'main' of github.com:kedacore/http-add-on into intercept…
arschles Sep 7, 2021
7ac0c82
fixing compile errs in tests
arschles Sep 7, 2021
b07f9a1
Merge branch 'main' into interceptor-config
arschles Sep 21, 2021
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
15 changes: 15 additions & 0 deletions interceptor/config/timeouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ type Timeouts struct {
// DeploymentReplicas is how long to wait for the backing deployment
// to have 1 or more replicas before connecting and sending the HTTP request.
DeploymentReplicas time.Duration `envconfig:"KEDA_CONDITION_WAIT_TIMEOUT" default:"1500ms"`
// ForceHTTP2 toggles whether to try to force HTTP2 for all requests
ForceHTTP2 bool `envconfig:"KEDA_HTTP_FORCE_HTTP2" default:"false"`
// MaxIdleConns is the max number of connections that can be idle in the
// interceptor's internal connection pool
MaxIdleConns int `envconfig:"KEDA_HTTP_MAX_IDLE_CONNS" default:"100"`
// IdleConnTimeout is the timeout after which a connection in the interceptor's
// internal connection pool will be closed
IdleConnTimeout time.Duration `envconfig:"KEDA_HTTP_IDLE_CONN_TIMEOUT" default:"90s"`
// TLSHandshakeTimeout is the max amount of time the interceptor will
// wait to establish a TLS connection
TLSHandshakeTimeout time.Duration `envconfig:"KEDA_HTTP_TLS_HANDSHAKE_TIMEOUT" default:"10s"`
// ExpectContinueTimeout is the max amount of time the interceptor will wait
// after sending request headers if the server returned an Expect: 100-continue
// header
ExpectContinueTimeout time.Duration `envconfig:"KEDA_HTTP_EXPECT_CONTINUE_TIMEOUT" default:"1s"`
}

// Backoff returns a wait.Backoff based on the timeouts in t
Expand Down
3 changes: 1 addition & 2 deletions interceptor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ func runProxyServer(
routingTable,
dialContextFunc,
waitFunc,
timeouts.DeploymentReplicas,
timeouts.ResponseHeader,
newForwardingConfigFromTimeouts(timeouts),
),
)

Expand Down
41 changes: 30 additions & 11 deletions interceptor/proxy_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,31 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/kedacore/http-add-on/interceptor/config"
kedanet "github.com/kedacore/http-add-on/pkg/net"
"github.com/kedacore/http-add-on/pkg/routing"
)

func moreThanPtr(i *int32, target int32) bool {
return i != nil && *i > target
type forwardingConfig struct {
waitTimeout time.Duration
respHeaderTimeout time.Duration
forceAttemptHTTP2 bool
maxIdleConns int
idleConnTimeout time.Duration
tlsHandshakeTimeout time.Duration
expectContinueTimeout time.Duration
}

func newForwardingConfigFromTimeouts(t *config.Timeouts) forwardingConfig {
return forwardingConfig{
waitTimeout: t.DeploymentReplicas,
respHeaderTimeout: t.ResponseHeader,
forceAttemptHTTP2: t.ForceHTTP2,
maxIdleConns: t.MaxIdleConns,
idleConnTimeout: t.IdleConnTimeout,
tlsHandshakeTimeout: t.TLSHandshakeTimeout,
expectContinueTimeout: t.ExpectContinueTimeout,
}
}

// newForwardingHandler takes in the service URL for the app backend
Expand All @@ -26,18 +45,17 @@ func newForwardingHandler(
routingTable *routing.Table,
dialCtxFunc kedanet.DialContextFunc,
waitFunc forwardWaitFunc,
waitTimeout time.Duration,
respHeaderTimeout time.Duration,
fwdCfg forwardingConfig,
) http.Handler {
roundTripper := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: dialCtxFunc,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: respHeaderTimeout,
ForceAttemptHTTP2: fwdCfg.forceAttemptHTTP2,
MaxIdleConns: fwdCfg.maxIdleConns,
IdleConnTimeout: fwdCfg.idleConnTimeout,
TLSHandshakeTimeout: fwdCfg.tlsHandshakeTimeout,
ExpectContinueTimeout: fwdCfg.expectContinueTimeout,
ResponseHeaderTimeout: fwdCfg.respHeaderTimeout,
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
host, err := getHost(r)
Expand All @@ -52,7 +70,8 @@ func newForwardingHandler(
w.Write([]byte(fmt.Sprintf("Host %s not found", r.Host)))
return
}
ctx, done := context.WithTimeout(r.Context(), waitTimeout)

ctx, done := context.WithTimeout(r.Context(), fwdCfg.waitTimeout)
defer done()
if err := waitFunc(ctx, routingTarget.Deployment); err != nil {
lggr.Error(err, "wait function failed, not forwarding request")
Expand Down
6 changes: 4 additions & 2 deletions interceptor/proxy_handlers_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ func newHarness(
routingTable,
dialContextFunc,
waitFunc,
deployReplicasTimeout,
responseHeaderTimeout,
forwardingConfig{
waitTimeout: deployReplicasTimeout,
respHeaderTimeout: responseHeaderTimeout,
},
)

originHdl := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
30 changes: 20 additions & 10 deletions interceptor/proxy_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ func TestImmediatelySuccessfulProxy(t *testing.T) {
routingTable,
dialCtxFunc,
waitFunc,
timeouts.DeploymentReplicas,
timeouts.ResponseHeader,
forwardingConfig{
waitTimeout: timeouts.DeploymentReplicas,
respHeaderTimeout: timeouts.ResponseHeader,
},
)
const path = "/testfwd"
res, req, err := reqAndRes(path)
Expand Down Expand Up @@ -91,8 +93,10 @@ func TestWaitFailedConnection(t *testing.T) {
routingTable,
dialCtxFunc,
waitFunc,
timeouts.DeploymentReplicas,
timeouts.ResponseHeader,
forwardingConfig{
waitTimeout: timeouts.DeploymentReplicas,
respHeaderTimeout: timeouts.ResponseHeader,
},
)
const path = "/testfwd"
res, req, err := reqAndRes(path)
Expand Down Expand Up @@ -129,8 +133,10 @@ func TestTimesOutOnWaitFunc(t *testing.T) {
routingTable,
dialCtxFunc,
waitFunc,
timeouts.DeploymentReplicas,
timeouts.ResponseHeader,
forwardingConfig{
waitTimeout: timeouts.DeploymentReplicas,
respHeaderTimeout: timeouts.ResponseHeader,
},
)
const path = "/testfwd"
res, req, err := reqAndRes(path)
Expand Down Expand Up @@ -192,8 +198,10 @@ func TestWaitsForWaitFunc(t *testing.T) {
routingTable,
dialCtxFunc,
waitFunc,
timeouts.DeploymentReplicas,
timeouts.ResponseHeader,
forwardingConfig{
waitTimeout: timeouts.DeploymentReplicas,
respHeaderTimeout: timeouts.ResponseHeader,
},
)
const path = "/testfwd"
res, req, err := reqAndRes(path)
Expand Down Expand Up @@ -259,8 +267,10 @@ func TestWaitHeaderTimeout(t *testing.T) {
routingTable,
dialCtxFunc,
waitFunc,
timeouts.DeploymentReplicas,
timeouts.ResponseHeader,
forwardingConfig{
waitTimeout: timeouts.DeploymentReplicas,
respHeaderTimeout: timeouts.ResponseHeader,
},
)
const path = "/testfwd"
res, req, err := reqAndRes(path)
Expand Down