-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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(config_etcd): use a single long http connection to watch all resources #9456
feat(config_etcd): use a single long http connection to watch all resources #9456
Conversation
66bd5bc
to
1c0102f
Compare
@@ -118,8 +118,8 @@ qr/Batch Processor\[error-log-logger\] failed to process entries: error while se | |||
--- request | |||
GET /tg | |||
--- response_body | |||
--- error_log eval | |||
qr/.*\[\{\"body\":\{\"text\":\{\"text\":\".*this is an error message for test.*\"\}\},\"endpoint\":\"\",\"service\":\"APISIX\",\"serviceInstance\":\"instance\".*/ |
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.
The new watch subsystem may print new logs.
All in all, strict log assumption is not a good practice.
--- response_body | ||
prev_index updated | ||
--- error_log eval | ||
qr/(create watch stream for key|cancel watch connection success)/ |
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.
deprecated test. etcd watch is a single long connection now.
@@ -18,5 +18,5 @@ | |||
|
|||
|
|||
export OPENRESTY_VERSION=source | |||
export TEST_CI_USE_GRPC=true | |||
#export TEST_CI_USE_GRPC=true |
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.
We're going to start focusing on etcd's http tests.
watch_ctx.wait_init = nil | ||
|
||
local opts = {} | ||
opts.timeout = 50 -- second |
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.
The choice of 50 seconds is to make it smaller than the default proxy_read_timeout value, 60 seconds, so that nginx will not print error logs, such as:
2023/05/10 23:43:44 [error] 3668019#3668019: *809 upstream timed out (110: Connection timed out) while reading upstream, client: unix:, server: , request: "POST /v3/watch HTTP/1.1", upstream: "http://127.0.0.1:2379/v3/watch", host: "127.0.0.1"
apisix/core/config_etcd.lua
Outdated
if err ~= "closed" and | ||
err ~= "timeout" and | ||
err ~= "broken pipe" then | ||
log.error("wait watch event: ", err) | ||
end |
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.
if err ~= "closed" and | |
err ~= "timeout" and | |
err ~= "broken pipe" then | |
log.error("wait watch event: ", err) | |
end | |
if err ~= "closed" and | |
err ~= "timeout" and | |
err ~= "broken pipe" | |
then | |
log.error("wait watch event: ", err) | |
end |
apisix/core/config_etcd.lua
Outdated
end | ||
end | ||
|
||
for i = 1,min_idx-1 do |
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.
for i = 1,min_idx-1 do | |
for i = 1, min_idx-1 do |
apisix/core/config_etcd.lua
Outdated
|
||
if min_idx > 100 then | ||
for k, idx in pairs(watch_ctx.idx) do | ||
watch_ctx.idx[k] = idx-min_idx+1 |
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.
watch_ctx.idx[k] = idx-min_idx+1 | |
watch_ctx.idx[k] = idx - min_idx + 1 |
apisix/core/config_etcd.lua
Outdated
watch_ctx.idx[k] = idx-min_idx+1 | ||
end | ||
-- trim the res table | ||
for i = 1,min_idx-1 do |
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.
for i = 1,min_idx-1 do | |
for i = 1, min_idx - 1 do |
apisix/core/config_etcd.lua
Outdated
res, err = res_func() | ||
end | ||
::iterate_events:: | ||
for i = watch_ctx.idx[key],#watch_ctx.res do |
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.
for i = watch_ctx.idx[key],#watch_ctx.res do | |
for i = watch_ctx.idx[key], #watch_ctx.res do |
apisix/core/config_etcd.lua
Outdated
end | ||
::iterate_events:: | ||
for i = watch_ctx.idx[key],#watch_ctx.res do | ||
watch_ctx.idx[key] = i+1 |
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.
watch_ctx.idx[key] = i+1 | |
watch_ctx.idx[key] = i + 1 |
Why do you call this "long http connection", the http_cli will be recreated every time: https://github.com/api7/lua-resty-etcd/blob/master/lib/resty/etcd/v3.lua#L803? |
::watch_event::
while true do
local res, err = res_func()
log.info("res_func: ", inspect(res)) Please read the code carefully. |
683f936
to
4eb055b
Compare
|
||
::watch_event:: | ||
while true do | ||
local res, err = res_func() |
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.
It's very good design here, the server response is a stream, if we don't close the connection here, we could get the response event one by one
if log_level >= NGX_INFO then | ||
log.info("append res: ", inspect(res), ", err: ", inspect(err)) | ||
end |
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.
Why not use json.delay_encode
here?
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.
the delay stuff has bug:
Lines 116 to 120 in a943c03
function _M.delay_encode(data, force) | |
delay_tab.data = data | |
delay_tab.force = force | |
return delay_tab | |
end |
It only uses a singleton table to log, but here I need two vars to log.
And inspect is more informational than json for debugging.
Description
Sequence Diagram:
Checklist