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

feat: support the combination of Nginx variables for annotation upstream-hash-by. #5571

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

agile6v
Copy link
Contributor

@agile6v agile6v commented May 19, 2020

What this PR does / why we need it:

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Which issue/s this PR fixes

fixes #4846

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 19, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @agile6v. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 19, 2020
@aledbf
Copy link
Member

aledbf commented May 19, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 19, 2020
@aledbf
Copy link
Member

aledbf commented May 19, 2020

/assign @ElvinEfendi

@aledbf
Copy link
Member

aledbf commented May 19, 2020

/retest

@codecov-commenter
Copy link

codecov-commenter commented May 19, 2020

Codecov Report

Merging #5571 into master will decrease coverage by 0.31%.
The diff coverage is 46.49%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5571      +/-   ##
==========================================
- Coverage   58.64%   58.33%   -0.32%     
==========================================
  Files          88       88              
  Lines        6913     7195     +282     
==========================================
+ Hits         4054     4197     +143     
- Misses       2414     2534     +120     
- Partials      445      464      +19     
Impacted Files Coverage Δ
cmd/nginx/main.go 5.61% <0.00%> (-0.80%) ⬇️
...ternal/ingress/annotations/sessionaffinity/main.go 60.41% <ø> (+1.59%) ⬆️
internal/ingress/controller/template/template.go 79.67% <0.00%> (-0.43%) ⬇️
internal/ingress/types.go 0.00% <ø> (ø)
internal/k8s/main.go 58.06% <0.00%> (-11.17%) ⬇️
internal/ingress/controller/store/store.go 58.77% <40.00%> (-1.32%) ⬇️
internal/ingress/annotations/class/main.go 54.54% <50.00%> (-34.35%) ⬇️
internal/ingress/controller/controller.go 49.59% <83.33%> (+0.18%) ⬆️
internal/admission/controller/main.go 90.47% <96.77%> (+4.36%) ⬆️
internal/admission/controller/server.go 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b18ea26...c035a14. Read the comment docs.

@aledbf
Copy link
Member

aledbf commented May 19, 2020

/retest

1 similar comment
@aledbf
Copy link
Member

aledbf commented May 19, 2020

/retest

@ElvinEfendi
Copy link
Member

ElvinEfendi commented May 20, 2020

@agile6v thanks for the PR. I think we should stick to how Nginx does this and support nginx.ingress.kubernetes.io/upstream-hash-by: "$request_uri$host" instead of nginx.ingress.kubernetes.io/upstream-hash-by: "$request_uri,$host".

Also I think we should only be changing lua_ngx_var function to support compound arguments like "$request_uri$host". Everything else will then just work.

@agile6v
Copy link
Contributor Author

agile6v commented May 21, 2020

Hi @ElvinEfendi

@agile6v thanks for the PR. I think we should stick to how Nginx does this and support nginx.ingress.kubernetes.io/upstream-hash-by: "$request_uri$host" instead of nginx.ingress.kubernetes.io/upstream-hash-by: "$request_uri,$host".

Yes. I agree with your suggestion.

Also I think we should only be changing lua_ngx_var function to support compound arguments like "$request_uri$host". Everything else will then just work.

lua_ngx_var function will be called when every request comes. So in order to improve performance parse operation should be completed early.

Thanks.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 21, 2020
@aledbf
Copy link
Member

aledbf commented May 21, 2020

/retest

@aledbf
Copy link
Member

aledbf commented May 21, 2020

@agile6v please squash the commits

@k8s-ci-robot k8s-ci-robot removed the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 22, 2020
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 22, 2020
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 22, 2020
@agile6v
Copy link
Contributor Author

agile6v commented May 24, 2020

ping @ElvinEfendi


-- given the compound Nginx variables i.e {"$request_uri"} or {"$request_uri$host$scheme"}
-- or {"${request_uri}-text-value"}, it returns the parsed value.
function _M.lua_ngx_var(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete this now? Does not seem to be used anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I move function lua_ngx_var to util_test.lua file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant this PR replaced lua_ngx_var with something else. Don't you think we should remove all references of lua_ngx_var (including tests), and add tests for the two new utility functions you introduced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ElvinEfendi The name of lua_ngx_var function is preserved but it contains two utility functions introduced this time. Function parse_complex_value and generate_var_value need to be used together (split into two functions because of performance considerations), So they are not individually written unit tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split into two functions because of performance considerations

This indicates me they should be individually unit tested. But I don't feel strongly if you don't add individual unit tests for them in this PR. But IMHO we should definitely delete all references to lua_ngx_var as it is promoting less performant solution.

--

the integration test for them is already being done as part of chash balancer test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ElvinEfendi What do you think of the latest commit?

@ElvinEfendi
Copy link
Member

@agile6v sorry for delay here. The PR looks great! Only lua_ngx_var seems to be redundant now.

@agile6v
Copy link
Contributor Author

agile6v commented May 29, 2020

/retest

3 similar comments
@ElvinEfendi
Copy link
Member

/retest

@agile6v
Copy link
Contributor Author

agile6v commented May 31, 2020

/retest

@aledbf
Copy link
Member

aledbf commented May 31, 2020

/retest

@aledbf
Copy link
Member

aledbf commented May 31, 2020

The error in the lua job seems valid

ERROR: module 'ngx.process' not found:

@aledbf
Copy link
Member

aledbf commented May 31, 2020

@agile6v please rebase and squash the commits

@aledbf
Copy link
Member

aledbf commented May 31, 2020

Running the patch against master works

wget https://github.com/kubernetes/ingress-nginx/pull/5571.patch
--2020-05-31 12:40:43--  https://github.com/kubernetes/ingress-nginx/pull/5571.patch
Resolving github.com (github.com)... 140.82.118.3
Connecting to github.com (github.com)|140.82.118.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://patch-diff.githubusercontent.com/raw/kubernetes/ingress-nginx/pull/5571.patch [following]
--2020-05-31 12:40:44--  https://patch-diff.githubusercontent.com/raw/kubernetes/ingress-nginx/pull/5571.patch
Resolving patch-diff.githubusercontent.com (patch-diff.githubusercontent.com)... 140.82.118.3
Connecting to patch-diff.githubusercontent.com (patch-diff.githubusercontent.com)|140.82.118.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Cookie coming from patch-diff.githubusercontent.com attempted to set domain to github.com
Length: unspecified [text/plain]
Saving to: ‘5571.patch’

5571.patch                                                                                      [  <=>                                                                                                                                                                                                                                    ]  15,39K  69,2KB/s    in 0,2s    

2020-05-31 12:40:45 (69,2 KB/s) - ‘5571.patch’ saved [15759]

 ⚙ aledbf@me  ~/.../k8s.io/ingress-nginx   ref ●  patch -p1 < 5571.patch 
patching file docs/user-guide/nginx-configuration/annotations.md
Hunk #1 succeeded at 213 (offset 1 line).
patching file internal/ingress/annotations/upstreamhashby/main_test.go
patching file rootfs/etc/nginx/lua/balancer/chash.lua
patching file rootfs/etc/nginx/lua/balancer/chashsubset.lua
patching file rootfs/etc/nginx/lua/test/util_test.lua
patching file rootfs/etc/nginx/lua/util.lua
patching file rootfs/etc/nginx/lua/test/util_test.lua
patching file rootfs/etc/nginx/lua/util.lua
patching file rootfs/etc/nginx/lua/test/util_test.lua
 ⚙ aledbf@me  ~/.../k8s.io/ingress-nginx   master ●  make lua-test
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
143 successes / 0 failures / 0 errors / 0 pending : 0.090901 seconds

@aledbf
Copy link
Member

aledbf commented Jun 1, 2020

/retest

@ElvinEfendi
Copy link
Member

/lgtm
/approve

thanks @agile6v !

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: agile6v, ElvinEfendi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 1, 2020
@aledbf
Copy link
Member

aledbf commented Jun 1, 2020

/retest

@k8s-ci-robot k8s-ci-robot merged commit d061375 into kubernetes:master Jun 1, 2020
@agile6v agile6v deleted the dev branch June 4, 2020 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

not support variables concatanation for upstream-hash-by annotation and not support endpoints set weight
5 participants