-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add configurable timeouts to TransportServer #1346
Conversation
deployments/common/crds-v1beta1/k8s.nginx.org_transportservers.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Dean Coakley <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @LorcanMcVeigh Please see my feedback
parameters: &v1alpha1.SessionParameters{ | ||
Timeout: "60s", | ||
}, | ||
msg: "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid timeout?
internal/configs/transportserver.go
Outdated
if nextUpstream { | ||
nextUpstreamTries = transportServerEx.TransportServer.Spec.UpstreamParameters.NextUpstreamTries | ||
|
||
if transportServerEx.TransportServer.Spec.UpstreamParameters.NextUpstreamTimeout != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for cases when we check if a field is not empty (multiple places in this file), I suggest we use generateString
from internal/configs/virtualserver.go:1325
nextUpstreamTimeout = generateString(TransportServer.Spec.UpstreamParameters.NextUpstreamTimeout, "0")
Because the function will be used both in virtualserver.go
and here, better to put it in a new file, something like generation_helpers.go
(and generation_helpers_test.go
for unit tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be called something like stringWithDefaultValue()
.
Co-authored-by: Michael Pleshakov <[email protected]>
68d5f3d
to
a4c018a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: #1346 (comment)
Makes sense to give the test case a name "Valid timeout", etc
LGTM overall.
internal/configs/transportserver.go
Outdated
} | ||
|
||
connectTimeout = generateString(transportServerEx.TransportServer.Spec.UpstreamParameters.ConnectTimeout, "0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we have two default values for connectTimeout
:
""
- if transportServerEx.TransportServer.Spec.UpstreamParameters isnil
"0"
- if transportServerEx.TransportServer.Spec.UpstreamParameters isn'tnil
but TransportServer.Spec.UpstreamParameters.ConnectTimeout is""
.
It looks like that because of that, you added addition ifs
in the template:
{{ if $s.ProxyConnectTimeout }}
proxy_connect_timeout {{ $s.ProxyConnectTimeout }};
{{ end }}
As you can see, having two default values makes things more complicated. Additionally, there is a bug - because the second default value "0" should be "60s".
Instead, we can have something like this:
var connectTimeoutFieldVal string
if transportServerEx.TransportServer.Spec.UpstreamParameters != nil {
connectTimeoutFieldVal = transportServerEx.TransportServer.Spec.UpstreamParameters.ConnectTimeout
}
connectTimeout = generateString(connectTimeoutFieldVal, "60s")
and in the template:
proxy_connect_timeout {{ $s.ProxyConnectTimeout }};
That will be similar to what we have in VS:
ProxyConnectTimeout: generateString(upstream.ProxyConnectTimeout, cfgParams.ProxyConnectTimeout),
template:
proxy_connect_timeout {{ $l.ProxyConnectTimeout }};
Could you also apply this approach to proxyTimeout ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Lorcan.
Co-authored-by: Michael Pleshakov <[email protected]>
Proposed changes
This PR adds support for
proxy_connect_timeout
,proxy_timeout
,proxy_next_upstream
,proxy_next_upstream_timeout
andproxy_next_upstream_tries
directives for TransportServers.Checklist
Before creating a PR, run through this checklist and mark each as complete.