-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
allow for configurable server side timeouts on routes #9671
Conversation
@ramr @rajatchopra @knobunc please review? |
Since the timeout is per route, maybe we should follow the existing convention of the annotation name: router.openshift.io/haproxy.timeout |
Yeah, agree with @rajatchopra that it would better to just use a standard And we should also do this for the other |
786f5af
to
1055ae0
Compare
LGTM |
Is the annotation value validated somewhere? Or can they sneak in a string and do naughty things? |
Good point @knobunc @JacobTanenbaum see https://github.com/openshift/origin/blob/master/pkg/router/template/router.go#L176 |
@rajatchopra @knobunc If I use the isInteger() function then the timeout can only be specified in milliseconds. Most of the other timeouts in the haproxy router template are in seconds, should I make another function for isTime that includes the units so users can input a timeout in any unit that is valid in haproxy? |
@rajatchopra added a regex validator... we can just use that. On Tue, Jul 12, 2016 at 2:22 PM, Jacob Tanenbaum [email protected]
|
Yes matchString(pattern, str). [0-9]+[su] for the pattern or something like that. |
@@ -226,6 +226,11 @@ backend be_edge_http_{{$cfgIdx}} | |||
{{ else }} | |||
balance leastconn | |||
{{ end }} | |||
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}} | |||
{{if (matchString "[0-9]*(us|ms|s|m|h|d)?" $value) }} |
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.
I assume matchString has an implicit anchor to the start and end of the string? But can we check that "test 9ms test" doesn't match.
Also * matches 0+ characters... I assume you want [0-9]+ to make it match 1+. Also \d is usually a synonym for [0-9], so let's see if "\d+(us|ms|s|m|h|d)?" works.
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.
'rm -f *; 90ms test' will match. the regex needs to be "^[1-9][0-9]*(us|ms|s|m|h|d)?$"
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.
Should we make anchoring the front and back the default in matchString? i.e. wrap the match they give us with ^(...)$
If we want to match a substr, then we can say .*thing.*
It feels like we will bite people with this behavior.
Looks good. Squash? |
status, err := regexp.MatchString(pattern, s) | ||
func matchPattern(pattern, s string) bool { | ||
glog.V(4).Infof("matchPattern called with %s and %s", pattern, s) | ||
status, err := regexp.MatchString("^"+pattern+"$", s) |
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.
This needs parens, or 'a|b' would match 'anaughty'
0edc1a3
to
3893c95
Compare
@knobunc squashed the commits |
@@ -99,7 +99,7 @@ func NewTemplatePlugin(cfg TemplatePluginConfig) (*TemplatePlugin, error) { | |||
globalFuncs := template.FuncMap{ | |||
"endpointsForAlias": endpointsForAlias, | |||
"env": env, | |||
"matchString": matchString, | |||
"matchPattern": matchPattern, |
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.
Are there any docs for this that should change? I couldn't find any. So at the least can we put a comment over in the original PR that added matchString to say that it changed (and what the new behavior is).
3893c95
to
3eb05ca
Compare
using annotations configure a route to have it's own server side timeout --beginning of route.yaml apiVersion: v1 kind: Route metadata: annotations: hello-again.timeout: 5s creationTimestamp: 2016-06-20T22:43:44Z name: hello-again namespace: default resourceVersion: "461544" selfLink: /oapi/v1/namespaces/default/routes/hello-again uid: 717b8a38-3738-11e6-8b7f-525400d6577c ... matching against [routename].timeout: [time] is what creates the timeout changelog: - change the annotation name to "router.openshift.io/haproxy.timeout" to conform to naming convention - adding timeout annotations to be_tcp_* and be_secure_* - added a regex to validate input - corrected the regular expression - changed matchString to matchPattern and made the default to anchor the pattern at the beginning and end of lines - nit, changed info prompt to correct function name - inline description FuncMap functions for the router template
3eb05ca
to
c1db34b
Compare
LGTM [merge] |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6563/) (Image: devenv-rhel7_4632) |
Evaluated for origin merge up to c1db34b |
[Test]ing while waiting on the merge queue |
Evaluated for origin test up to c1db34b |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6563/) |
using annotations configure a route to have it's own server side timeout
--beginning of route.yaml
apiVersion: v1
kind: Route
metadata:
annotations:
hello-again.timeout: 5s
creationTimestamp: 2016-06-20T22:43:44Z
name: hello-again
namespace: default
resourceVersion: "461544"
selfLink: /oapi/v1/namespaces/default/routes/hello-again
uid: 717b8a38-3738-11e6-8b7f-525400d6577c
...
matching against [routename].timeout: [time] is what creates the timeout