Skip to content
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

Merged
merged 1 commit into from
Jul 20, 2016

Conversation

JacobTanenbaum
Copy link
Contributor

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

@JacobTanenbaum
Copy link
Contributor Author

@ramr @rajatchopra @knobunc please review?

@rajatchopra
Copy link
Contributor

Since the timeout is per route, maybe we should follow the existing convention of the annotation name: router.openshift.io/haproxy.timeout

@ramr
Copy link
Contributor

ramr commented Jul 6, 2016

Yeah, agree with @rajatchopra that it would better to just use a standard "name" ala: router.openshift.io/haproxy.timeout rather than a custom one per route (makes copy-pasta editing easier as well as if you want to change the host name).

And we should also do this for the other be_tcp_* and be_secure_* backends.

@rajatchopra
Copy link
Contributor

LGTM
@JacobTanenbaum squash the commits maybe.

@knobunc
Copy link
Contributor

knobunc commented Jul 8, 2016

Is the annotation value validated somewhere? Or can they sneak in a string and do naughty things?

@rajatchopra
Copy link
Contributor

Good point @knobunc
There is a function call implemented already to check if the value is an integer, we should use that call.

@JacobTanenbaum see https://github.com/openshift/origin/blob/master/pkg/router/template/router.go#L176

@JacobTanenbaum
Copy link
Contributor Author

@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?

@knobunc
Copy link
Contributor

knobunc commented Jul 12, 2016

@rajatchopra added a regex validator... we can just use that.

On Tue, Jul 12, 2016 at 2:22 PM, Jacob Tanenbaum [email protected]
wrote:

@rajatchopra https://github.com/rajatchopra @knobunc
https://github.com/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?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9671 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AJkavcJYdgVVnP3zfhRfTZF16VkVLlD1ks5qU9tPgaJpZM4JDLz9
.

@rajatchopra
Copy link
Contributor

rajatchopra commented Jul 12, 2016

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) }}
Copy link
Contributor

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.

Copy link
Contributor

@rajatchopra rajatchopra Jul 14, 2016

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)?$"

Copy link
Contributor

@knobunc knobunc Jul 14, 2016

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.

@rajatchopra
Copy link
Contributor

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)
Copy link
Contributor

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'

@JacobTanenbaum
Copy link
Contributor Author

@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,
Copy link
Contributor

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).

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
@knobunc
Copy link
Contributor

knobunc commented Jul 20, 2016

LGTM [merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Jul 20, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6563/) (Image: devenv-rhel7_4632)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to c1db34b

@openshift-bot
Copy link
Contributor

[Test]ing while waiting on the merge queue

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to c1db34b

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6563/)

@openshift-bot openshift-bot merged commit b0d347c into openshift:master Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants