-
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
Router template optimization #12882
Router template optimization #12882
Conversation
@ramr @JacobTanenbaum PTAL |
f78a53c
to
07ad61a
Compare
07ad61a
to
5104d00
Compare
Anyone take a look? |
5104d00
to
f161234
Compare
f161234
to
d6cf2ed
Compare
@louyihua This is really good stuff. We had talked about similar changes but you beat us to the implementation. If you can rebase this @JacobTanenbaum can help shepherd it in. |
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 is great stuff. We need to think about what functions we expose in the template a bit since they are an API contract. But I really like the cleanliness of the resulting template.
{{ else }} | ||
timeout http-keep-alive 300s | ||
{{ end }} | ||
timeout connect {{firstMatch "[1-9][0-9]*(us|ms|s|m|h|d)?" (env "ROUTER_DEFAULT_CONNECT_TIMEOUT" "") "5s"}} |
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 was wondering if we should change env to take variable args, and if called without a default, assume "".
We can do that as a follow-on PR, but I wanted to get your thoughts. Alternatively, we can add a new env function that takes one arg... but I don't like that as much.
|
||
{{ if (matchPattern "true|TRUE" (env "ROUTER_ENABLE_COMPRESSION" "false")) }} | ||
{{ if isTrue (env "ROUTER_ENABLE_COMPRESSION" "false") }} |
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 an "is" function, and have the first arg govern "true" vs "false"?
I don't really want to add isTrue and isFalse and whatever else people think of...
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.
But I guess we can say not isTrue ...
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.
Would we need to change the documentation because of the way isTrue is implemented using strconv? The amount of acceptable values increases 1, t, T, TRUE, true, True
{{ else }} | ||
timeout http-keep-alive 300s | ||
{{ end }} | ||
timeout connect {{firstMatch "[1-9][0-9]*(us|ms|s|m|h|d)?" (env "ROUTER_DEFAULT_CONNECT_TIMEOUT" "") "5s"}} |
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 was thinking that we should define a template variable at the top that holds this regex (and make other ones for common regexes.
e.g.:
{{with $timeSpecRE := "[1-9][0-9]*(us|ms|s|m|h|d)?"}}
timeout connect {{firstMatch $timeSpecRE (env ...) "5s"}}
return v | ||
} | ||
|
||
func matchValues(s string, allowedValues ...string) bool { |
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 you add the logging to matchValues similar to that of the helper functions you added
d6cf2ed
to
07f978a
Compare
@knobunc @JacobTanenbaum |
07f978a
to
c917b69
Compare
This is looking good, besides rebase I don't see anything specific that I have a problem with. The env function looks good. I will take a another look after rebase |
Fixed the template broken. |
/retest |
Seems all tests are unexpectly stopped |
@louyihua I am on PTO next week. @rajatchopra can help you. |
@rajatchopra Seems tests are failed strangely, maybe rerun the tests can solve the problem? |
/retest |
@louyihua I am back from PTO and will continue to help with this. |
@louyihua do the tests work on your local machine? |
@louyihua The end to end test has a regression that needs to be fixed:
|
This PR introduces some optimizations to router template files, which simplify the structure of the template file, improve compatibility for future HAPROXY versions, and improve maintainancibility of template-related codes. Major optimizations include: 1. Move template helper functions, as well as the mapping structure, into a new .go file named `template_helper.go` 2. Replace the non-standard form `listen stats :<port>` which is forbidden by HAPROXY 1.7.0+ with the standard form `listen stats` and `bind :<port>`. 3. Introduce two new helper functions: `firstMatch` and `isTrue`. `firstMatch` matches the regexp given in the first argument with the following string arguments and returns the first matched string, while `isTrue` is a proxy for Go's `strconv.ParseBool`. 4. Change the `env` function to take variable args: `env(name, def...)`. It accepts multiple default values, but only the first non-empty default value takes effect if the environment variable is not defined. If no default value is given, or all default values are empty, then it treats `""` as the default value. 5. Eliminate many unnecessary `{{if}}`s from the template file through the introduction of `firstMatch` function. The result is the size of the template file is significantly reduced.
2d47da0
to
2ed8547
Compare
/retest |
@stevekuznetsov Do you have any idea what we need to do to get past this? Thanks! |
That is a red herring. Looks like you hit #15874 which should be fixed now /retest |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: louyihua, pecameron, rajatchopra The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@stevekuznetsov The ci/openshift-jenkins/extended_conformance_gce test previously passed. Actually all the tests passed. Where do we go from here? |
@pecameron GCE provision flake, /retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
/test all [submit-queue is verifying that this PR is safe to merge] |
@stevekuznetsov the ci/openshift-jenkins/extended_conformance_gce test seems to be stuck. How do we get it going? |
From my end I see it successful:
|
@stevekuznetsov Oops! My bad. I needed to refresh the page. All tests passed and then it did a /retest with everything. |
/retest |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
Documentation changes: |
This PR introduces some optimizations to router template files, which simplify the structure of the template file, improve compatibility for future HAPROXY versions, and improve maintainancibility of template-related codes. Major optimizations include:
template_helper.go
listen stats :<port>
which is forbidden by HAPROXY 1.7.0+ with the standard formlisten stats
andbind :<port>
.firstMatch
andisTrue
.firstMatch
matches the regexp given in the first argument with the following string arguments and returns the first matched string, whileisTrue
is a proxy for Go'sstrconv.ParseBool
.env
function to take variable args:env(name, def...)
. It accepts multiple default values, but only the first non-empty default value takes effect if the environment variable is not defined. If no default value is given, or all default values are empty, then it treats""
as the default value.{{if}}
s from the template file through the introduction offirstMatch
function. The result is the size of the template file is significantly reduced.Final result of this PR is that the size of the template file is significantly reduced, and there are much fewer duplicating items which improves the maintaincibility.