Skip to content

Commit bf35564

Browse files
authored
Implement HTTPScaledObject scoped timeout (#1285)
* Implement HTTPScaledObject scoped timeout Signed-off-by: Alexander Pykavy <[email protected]> * Add tests for HTTPScaledObject scoped timeout Signed-off-by: Alexander Pykavy <[email protected]> --------- Signed-off-by: Alexander Pykavy <[email protected]>
1 parent 29a6c2b commit bf35564

File tree

6 files changed

+349
-13
lines changed

6 files changed

+349
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This changelog keeps track of work items that have been completed and are ready
3131
- **General**: Add possibility to skip TLS verification for upstreams in interceptor ([#1307](https://github.com/kedacore/http-add-on/pull/1307))
3232
### Improvements
3333

34-
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
34+
- **Interceptor**: Support HTTPScaledObject scoped timeout ([#813](https://github.com/kedacore/http-add-on/issues/813))
3535

3636
### Fixes
3737

config/crd/bases/http.keda.sh_httpscaledobjects.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ spec:
162162
metric value
163163
format: int32
164164
type: integer
165+
timeouts:
166+
description: (optional) Timeouts that override the global ones
167+
properties:
168+
conditionWait:
169+
description: How long to wait for the backing workload to have
170+
1 or more replicas before connecting and sending the HTTP request
171+
(Default is set by the KEDA_CONDITION_WAIT_TIMEOUT environment
172+
variable)
173+
type: string
174+
responseHeader:
175+
description: How long to wait between when the HTTP request is
176+
sent to the backing app and when response headers need to arrive
177+
(Default is set by the KEDA_RESPONSE_HEADER_TIMEOUT environment
178+
variable)
179+
type: string
180+
type: object
165181
required:
166182
- scaleTargetRef
167183
type: object

interceptor/proxy_handlers.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,35 @@ func newForwardingHandler(
5353
tlsCfg *tls.Config,
5454
tracingCfg *config.Tracing,
5555
) http.Handler {
56-
roundTripper := &http.Transport{
57-
Proxy: http.ProxyFromEnvironment,
58-
DialContext: dialCtxFunc,
59-
ForceAttemptHTTP2: fwdCfg.forceAttemptHTTP2,
60-
MaxIdleConns: fwdCfg.maxIdleConns,
61-
IdleConnTimeout: fwdCfg.idleConnTimeout,
62-
TLSHandshakeTimeout: fwdCfg.tlsHandshakeTimeout,
63-
ExpectContinueTimeout: fwdCfg.expectContinueTimeout,
64-
ResponseHeaderTimeout: fwdCfg.respHeaderTimeout,
65-
TLSClientConfig: tlsCfg,
66-
}
6756
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6857
var uh *handler.Upstream
6958
ctx := r.Context()
7059
httpso := util.HTTPSOFromContext(ctx)
7160

72-
waitFuncCtx, done := context.WithTimeout(ctx, fwdCfg.waitTimeout)
61+
conditionWaitTimeout := fwdCfg.waitTimeout
62+
roundTripper := &http.Transport{
63+
Proxy: http.ProxyFromEnvironment,
64+
DialContext: dialCtxFunc,
65+
ForceAttemptHTTP2: fwdCfg.forceAttemptHTTP2,
66+
MaxIdleConns: fwdCfg.maxIdleConns,
67+
IdleConnTimeout: fwdCfg.idleConnTimeout,
68+
TLSHandshakeTimeout: fwdCfg.tlsHandshakeTimeout,
69+
ExpectContinueTimeout: fwdCfg.expectContinueTimeout,
70+
ResponseHeaderTimeout: fwdCfg.respHeaderTimeout,
71+
TLSClientConfig: tlsCfg,
72+
}
73+
74+
if httpso.Spec.Timeouts != nil {
75+
if httpso.Spec.Timeouts.ConditionWait.Duration > 0 {
76+
conditionWaitTimeout = httpso.Spec.Timeouts.ConditionWait.Duration
77+
}
78+
79+
if httpso.Spec.Timeouts.ResponseHeader.Duration > 0 {
80+
roundTripper.ResponseHeaderTimeout = httpso.Spec.Timeouts.ResponseHeader.Duration
81+
}
82+
}
83+
84+
waitFuncCtx, done := context.WithTimeout(ctx, conditionWaitTimeout)
7385
defer done()
7486
isColdStart, err := waitFunc(
7587
waitFuncCtx,

operator/apis/http/v1alpha1/httpscaledobject_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ type RateMetricSpec struct {
7676
Granularity metav1.Duration `json:"granularity" description:"Time granularity for rate calculation"`
7777
}
7878

79+
// HTTPScaledObjectTimeoutsSpec defines timeouts that override the global ones
80+
type HTTPScaledObjectTimeoutsSpec struct {
81+
// How long to wait for the backing workload to have 1 or more replicas before connecting and sending the HTTP request (Default is set by the KEDA_CONDITION_WAIT_TIMEOUT environment variable)
82+
// +optional
83+
ConditionWait metav1.Duration `json:"conditionWait" description:"How long to wait for the backing workload to have 1 or more replicas before connecting and sending the HTTP request"`
84+
85+
// How long to wait between when the HTTP request is sent to the backing app and when response headers need to arrive (Default is set by the KEDA_RESPONSE_HEADER_TIMEOUT environment variable)
86+
// +optional
87+
ResponseHeader metav1.Duration `json:"responseHeader" description:"How long to wait between when the HTTP request is sent to the backing app and when response headers need to arrive"`
88+
}
89+
7990
// HTTPScaledObjectSpec defines the desired state of HTTPScaledObject
8091
type HTTPScaledObjectSpec struct {
8192
// The hosts to route. All requests which the "Host" header
@@ -108,6 +119,9 @@ type HTTPScaledObjectSpec struct {
108119
// (optional) Configuration for the metric used for scaling
109120
// +optional
110121
ScalingMetric *ScalingMetricSpec `json:"scalingMetric,omitempty" description:"Configuration for the metric used for scaling. If empty 'concurrency' will be used"`
122+
// (optional) Timeouts that override the global ones
123+
// +optional
124+
Timeouts *HTTPScaledObjectTimeoutsSpec `json:"timeouts,omitempty" description:"Timeouts that override the global ones"`
111125
}
112126

113127
// HTTPScaledObjectStatus defines the observed state of HTTPScaledObject

operator/apis/http/v1alpha1/zz_generated.deepcopy.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)