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

lua randomseed per worker #3581

Merged
merged 1 commit into from
Dec 20, 2018

Conversation

ElvinEfendi
Copy link
Member

What this PR does / why we need it:
Previously we have switched to explicitly seeding PRNG for tests and this PR does it for production code. I've also patched math.randomseed so that individual modules can not re-seed PRNG since that can potentially affect randomness. And the reason why I'm seeding per worker rather than in init_by_lua is because otherwise every worker would be seeded with the same seed.

lua_ingress.lua will be used for general things such as this. And eventually I'd like it to be the only entry point to Lua code that executes everything else.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 19, 2018
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 19, 2018
@wayt
Copy link
Contributor

wayt commented Dec 19, 2018

lgtm 👍

@@ -0,0 +1,9 @@
describe("lua_ingress", function()
it("patches math.randomseed to not be caled more than once per worker", function()
Copy link
Contributor

Choose a reason for hiding this comment

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

caled -> called


std = {
read_globals = { math = { fields = { "randomseed" } } }
}
Copy link
Contributor

@zrdaley zrdaley Dec 19, 2018

Choose a reason for hiding this comment

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

I think this file needs to be rewritten to something like:

std = {
  globals = {'_TEST', 'ngx_lua'},
  read_globals = { math = { fields = { "randomseed" } } }
}
exclude_files = {'./rootfs/etc/nginx/lua/test/**/*.lua'}

https://luacheck.readthedocs.io/en/stable/config.html

Copy link
Member Author

Choose a reason for hiding this comment

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

@zrdaley it looks like globals, read_globals, std are all same level, so can not be nested like you suggested. I had to use ignore per file.

@@ -3,3 +3,8 @@ globals = {
'_TEST'
}
exclude_files = {'./rootfs/etc/nginx/lua/test/**/*.lua'}
files["rootfs/etc/nginx/lua/lua_ingress.lua"] = {
ignore = { "122" },
Copy link
Member Author

Choose a reason for hiding this comment

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

The code is taken from

rootfs/etc/nginx/lua/lua_ingress.lua:5:1: (W122) setting read-only field randomseed of global math

@ElvinEfendi
Copy link
Member Author

/assign @aledbf

@aledbf
Copy link
Member

aledbf commented Dec 20, 2018

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, 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 merged commit a99f832 into kubernetes:master Dec 20, 2018
@ElvinEfendi ElvinEfendi deleted the lua-randomseed-per-worker branch December 20, 2018 13:55
@ElvinEfendi ElvinEfendi restored the lua-randomseed-per-worker branch January 8, 2019 18:39
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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants