feat(config_etcd): use a single long http connection to watch all resources#9456
Conversation
66bd5bc to
1c0102f
Compare
| 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.
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.
deprecated test. etcd watch is a single long connection now.
|
|
||
| export OPENRESTY_VERSION=source | ||
| export TEST_CI_USE_GRPC=true | ||
| #export TEST_CI_USE_GRPC=true |
There was a problem hiding this comment.
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.
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"
| 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.
| 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 |
| end | ||
| end | ||
|
|
||
| for i = 1,min_idx-1 do |
There was a problem hiding this comment.
| for i = 1,min_idx-1 do | |
| for i = 1, min_idx-1 do |
|
|
||
| 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.
| watch_ctx.idx[k] = idx-min_idx+1 | |
| watch_ctx.idx[k] = idx - min_idx + 1 |
| 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.
| for i = 1,min_idx-1 do | |
| for i = 1, min_idx - 1 do |
| res, err = res_func() | ||
| end | ||
| ::iterate_events:: | ||
| for i = watch_ctx.idx[key],#watch_ctx.res do |
There was a problem hiding this comment.
| for i = watch_ctx.idx[key],#watch_ctx.res do | |
| for i = watch_ctx.idx[key], #watch_ctx.res do |
| 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.
| 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.
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.
Why not use json.delay_encode here?
There was a problem hiding this comment.
the delay stuff has bug:
Lines 116 to 120 in a943c03
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