-
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(xds): using data written by xds to control dp behavior #6759
Conversation
I want to write some test cases, such as without any keys, json with wrong format, json that does not conform to the route's json scheme, etc., but I don't know how to control the data passed with libxds.so in the test cases. But I can write data to shdict directly in the test case, which seems more convenient than writing data with libxds.so, is this acceptable way of testing. |
t/xds-library/config_xds_2.t
Outdated
} | ||
--- error_code: 404 | ||
--- no_error_log | ||
[alert] |
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 should we check the alert log? Is there any alert log in the path?
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.
because this test case throws an error level log, but the above defines
if (!$block->no_error_log) {
$block->set_value("no_error_log", "[error]\n[alert]");
}
so I need to override the above definition with the --- no_error_log
statement, and I need to verify that the error level log.
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.
@tzssangglass
We can check like this?
Line 40 in 97bcb56
if ((!defined $block->error_log) && (!defined $block->no_error_log)) { |
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.
update
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 can safely remove it, right?
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.
LGTM
apisix/init.lua
Outdated
@@ -116,18 +116,18 @@ function _M.http_init_worker() | |||
|
|||
require("apisix.debug").init_worker() | |||
|
|||
if core.config == require("apisix.core.config_xds") then |
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.
Can we just put all the init_worker together?
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 config_xds
, I need it to run before route, service is initialised. So do I need to advance config_yaml
to the same level as config_xds
?
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.
Yes.
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.
fix
t/xds-library/config_xds_2.t
Outdated
} | ||
--- error_code: 404 | ||
--- no_error_log | ||
[alert] |
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 can safely remove it, right?
apisix/core/config_xds.lua
Outdated
|
||
if not keys or #keys <= 0 then | ||
-- xds did not write any data to shdict | ||
return true, "no keys" |
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.
return true, "no keys" | |
return false, "no keys" |
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.
fix
apisix/core/config_xds.lua
Outdated
end | ||
|
||
-- v1 version we only support route/upstream | ||
local capacity = math_ceil(#keys / 2) |
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 divide 2?
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.
ngx.shared["xds-config"] stores all routes, upstreams, here I estimate the capacity of the route by using the total capacity / 2.
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.
Route and upstream are not 1:1.
Maybe we can use #keys
directly
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.
fix
|
||
-- blocking until xds completes initial configuration | ||
while true do | ||
fetch_version() |
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.
Need a sleep 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.
ngx.sleep can not used in init_worker_by_lua
, is there another way?
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 can use another sleep?
Line 41 in 07d535d
int usleep(useconds_t usec); |
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.
fix
apisix/core/config_xds.lua
Outdated
|
||
|
||
local function sync_data(self) | ||
if not latest_version then |
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.
As we already block for the version, we can skip this check?
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.
fix
apisix/core/config_xds.lua
Outdated
|
||
local sync_data | ||
local latest_version | ||
sync_data = function(self) |
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 local function xxx
?
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.
fix
|
||
-- blocking until xds completes initial configuration | ||
while true do | ||
fetch_version() |
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 can use another sleep?
Line 41 in 07d535d
int usleep(useconds_t usec); |
Description
This PR is designed to mock the behavior of xds writing data and reading it from ngx.shared.DICT to complete the request proxy.
It needs to accomplish the following functions:
Fixes # (issue)
Checklist