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(ext-plugin): avoid sending conf request more times #5183

Merged
merged 10 commits into from
Oct 18, 2021

Conversation

tzssangglass
Copy link
Member

There are two cases where the conf request needs to be forced to be resent:

  1. conf has been updated
  2. the plugin runner returns 'conf token not found', will retry

For case 1, since the key used by the shared dict is lrucache_id, the lrucache_id will need to be updated after the conf is updated, so it is satisfied.

For case 2, work in progress

Signed-off-by: tzssangglass tzssangglass@gmail.com

What this PR does / why we need it:

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

There are two cases where the conf request needs to be forced to be resent:
1. conf has been updated
2. the plugin runner returns 'conf token not found', will retry

For case 1, since the key used by the shared dict is lrucache_id, the lrucache_id will need to be updated after the conf is updated, so it is satisfied.

For case 2, work in progress

Signed-off-by: tzssangglass <tzssangglass@gmail.com>
Signed-off-by: tzssangglass <tzssangglass@gmail.com>
Signed-off-by: tzssangglass <tzssangglass@gmail.com>
Comment on lines 110 to 140
=== TEST 2: share conf token in different workers
--- ext_plugin_cmd
["t/plugin/ext-plugin/runner.sh", "3600"]
--- config
location /t {
content_by_lua_block {
local http = require "resty.http"
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
local function r()
local httpc = http.new()
local res, err = httpc:request_uri(uri)
if not res then
ngx.log(ngx.ERR, err)
return
end
end

for i = 1, 20 do
r()
ngx.sleep(0.001)
end
ngx.say("done")
}
}
--- response_body
done
--- timeout: 5
--- error_log
fetch token from shared dict
--- no_error_log
[error]
Copy link
Member Author

Choose a reason for hiding this comment

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

In this test case, I want different workers to handle the "/hello" request in order to verify that the conf token can be shared in different workers, but my local tests show that it is handled by a fixed worker. Is there any way to do this? @spacewander @tokers

Copy link
Member

Choose a reason for hiding this comment

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

What about sending requests parallelly?

Signed-off-by: tzssangglass <tzssangglass@gmail.com>
Signed-off-by: tzssangglass <tzssangglass@gmail.com>
@tzssangglass tzssangglass marked this pull request as ready for review October 15, 2021 08:52
apisix/plugins/ext-plugin/init.lua Outdated Show resolved Hide resolved
apisix/plugins/ext-plugin/init.lua Outdated Show resolved Hide resolved
apisix/plugins/ext-plugin/init.lua Outdated Show resolved Hide resolved
t/plugin/ext-plugin/conf_token.t Outdated Show resolved Hide resolved
Signed-off-by: tzssangglass <tzssangglass@gmail.com>
@spacewander spacewander merged commit 4395d70 into apache:master Oct 18, 2021
@tzssangglass tzssangglass deleted the ext_ct branch October 21, 2021 04:42
bzp2010 pushed a commit to bzp2010/apisix that referenced this pull request Dec 31, 2021
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.

3 participants