-
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: support reading configuration form xds(mvp) #6614
Conversation
apisix/core/config_shdict.lua
Outdated
|
||
|
||
ffi.cdef[[ | ||
extern void CreateMock(void* writeRoute); |
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.
change it to standard C style: create_mock
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 should call a init()
function 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.
init()
is the name of a reserved function of go, with special meaning, I replaced it with initial()
Signed-off-by: tzssangglass <tzssangglass@gmail.com>
.github/workflows/build.yml
Outdated
@@ -29,7 +29,7 @@ jobs: | |||
test_dir: | |||
- t/plugin | |||
- t/admin t/cli t/config-center-yaml t/control t/core t/debug t/discovery t/error_page t/misc | |||
- t/node t/router t/script t/stream-node t/utils t/wasm | |||
- t/node t/router t/script t/stream-node t/utils t/wasm t/amesh-library |
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.
Should be sorted in order
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.
fixed
apisix/cli/ops.lua
Outdated
@@ -560,6 +560,7 @@ Please modify "admin_key" in conf/config.yaml . | |||
end | |||
sys_conf["wasm"] = yaml_conf.wasm | |||
|
|||
sys_conf["config_center"] = yaml_conf.apisix.config_center |
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.
Handled in
Line 555 in 15517fe
for k,v in pairs(yaml_conf.apisix) 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.
rm this
apisix/cli/schema.lua
Outdated
@@ -28,7 +28,7 @@ local config_schema = { | |||
apisix = { | |||
properties = { | |||
config_center = { | |||
enum = {"etcd", "yaml"}, | |||
enum = {"etcd", "yaml", "shdict"}, |
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.
enum = {"etcd", "yaml", "shdict"}, | |
enum = {"etcd", "yaml", "xds"}, |
would be better?
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.
updated
apisix/core/config_shdict.lua
Outdated
|
||
|
||
local function load_libamesh(lib_name) | ||
ngx_timer_at(0, function(premature) |
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 use the timer?
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.
fixed
apisix/core/config_shdict.lua
Outdated
end | ||
|
||
|
||
function _M.new(key, opts) |
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 injection for test?
Lines 32 to 50 in 15517fe
my $extra_init_by_lua = <<_EOC_; | |
-- reduce default report interval | |
local client = require("skywalking.client") | |
client.backendTimerDelay = 0.5 | |
local sw_tracer = require("skywalking.tracer") | |
local inject = function(mod, name) | |
local old_f = mod[name] | |
mod[name] = function (...) | |
ngx.log(ngx.WARN, "skywalking run ", name) | |
return old_f(...) | |
end | |
end | |
inject(sw_tracer, "start") | |
inject(sw_tracer, "finish") | |
inject(sw_tracer, "prepareForReport") | |
_EOC_ | |
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.
fixed
.github/workflows/build.yml
Outdated
@@ -29,7 +29,7 @@ jobs: | |||
test_dir: | |||
- t/plugin | |||
- t/admin t/cli t/config-center-yaml t/control t/core t/debug t/discovery t/error_page t/misc | |||
- t/node t/router t/script t/stream-node t/utils t/wasm | |||
- t/amesh-library t/node t/router t/script t/stream-node t/utils t/wasm |
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.
What is amesh?
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.
fixed, use xds
.github/workflows/build.yml
Outdated
@@ -90,6 +90,11 @@ jobs: | |||
sudo dpkg -i tinygo_${TINYGO_VER}_amd64.deb | |||
cd t/wasm && find . -type f -name "*.go" | xargs -Ip tinygo build -o p.wasm -scheduler=none -target=wasi p | |||
|
|||
- name: Build Amesh library |
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.
Ditto.
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.
updated
apisix/core/config_xds.lua
Outdated
local string_gmatch = string.gmatch | ||
local string_match = string.match | ||
local io_open = io.open | ||
local io_close = io.close |
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.
Put them to the module level?
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.
updated
apisix/core/config_xds.lua
Outdated
local tried_paths = new_tab(32, 0) | ||
local i = 1 | ||
|
||
for k, _ in string_gmatch(cpath, "[^;]+") 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.
Why not use ngx.re.gmatch
?
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.
updated
apisix/core/config_xds.lua
Outdated
local i = 1 | ||
|
||
for k, _ in string_gmatch(cpath, "[^;]+") do | ||
local fpath = string_match(k, "(.*/)") |
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.
What about ngx.re.match
?
apisix/init.lua
Outdated
@@ -110,6 +110,11 @@ function _M.http_init_worker() | |||
end | |||
require("apisix.balancer").init_worker() | |||
load_balancer = require("apisix.balancer") | |||
|
|||
if core.config == require("apisix.core.config_shdict") 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.
I think we may need to unify the term, the shdict is the container, the xds is the way, I think here config_xds
will be better.
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.
another option, we can use amesh
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.
@membphis I don't think so, from the point of view of Apache APISIX, what is amesh
? Why do we need to care about a commercial product?
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, you are right. config_xds
is fine
apisix/core/config_xds.lua
Outdated
|
||
|
||
function _M.init_worker() | ||
local lib_name = "libxds.so" |
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.
Put it at the module level?
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.
updated
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.
In my opinion, I think all xds should be replaced with external
or other names of similar meaning.
Although we are currently integrating Istio/xds, APISIX does not actually need to pay attention to whether the external Go application is docking with xDS or other protocols. If we name it external
library, then users can use this mode to interface with any service, and even we can use it to watch etcd directly, it will be a very big change, and it will be more clear.
IMHO, |
t/xds-library/config_xds.t
Outdated
__DATA__ | ||
|
||
=== TEST 1: load Amesh library so successfully | ||
--- yaml_config |
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.
Let's set the yaml_config in the file level?
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.
updated
apisix/init.lua
Outdated
@@ -110,6 +110,11 @@ function _M.http_init_worker() | |||
end | |||
require("apisix.balancer").init_worker() | |||
load_balancer = require("apisix.balancer") | |||
|
|||
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.
We can call it like:
Line 83 in 9d450d7
if core.config.init 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.
updated
OK so we can keep this naming for now and let's move forward. |
apisix/cli/ngx_tpl.lua
Outdated
@@ -235,6 +235,10 @@ http { | |||
lua_shared_dict ext-plugin {* http.lua_shared_dict["ext-plugin"] *}; # cache for ext-plugin | |||
{% end %} | |||
|
|||
{% if config_center == "xds" then %} | |||
lua_shared_dict router-config 10m; |
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.
lua_shared_dict router-config 10m; | |
lua_shared_dict xds-route-config 10m; |
would that be better?
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.
updated
apisix/core/config_xds.lua
Outdated
local new_tab = base.new_tab | ||
local ffi = require ("ffi") | ||
local C = ffi.C | ||
local router_config = ngx.shared["router-config"] |
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 is not configuration for router, but for route.
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.
updated
apisix/core/config_xds.lua
Outdated
|
||
if not xdsagent then | ||
tried_paths[#tried_paths + 1] = 'tried above paths but can not load ' .. lib_name | ||
error("can not load Amesh library, tried paths: " .. |
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.
error("can not load Amesh library, tried paths: " .. | |
error("can not load xds library, tried paths: " .. |
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.
updated
# Conflicts: # t/APISIX.pm
apisix/core/config_xds.lua
Outdated
local new_tab = base.new_tab | ||
local ffi = require ("ffi") | ||
local C = ffi.C | ||
local router_config = ngx.shared["xds-route-config"] |
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.
There are still using router
in some places.
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.
updated
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
# Conflicts: # t/APISIX.pm
local new_tab = base.new_tab | ||
local ffi = require ("ffi") | ||
local C = ffi.C | ||
local route_config = ngx.shared["xds-route-config"] |
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.
local route_config = ngx.shared["xds-route-config"] | |
local route_config = ngx.shared["xds-route-config"] |
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.
I want to change it in the next PR😅, otherwise it will dismiss the previous approval.
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.
OK
@@ -509,6 +509,7 @@ _EOC_ | |||
lua_shared_dict ext-plugin 1m; | |||
lua_shared_dict kubernetes 1m; | |||
lua_shared_dict tars 1m; | |||
lua_shared_dict xds-route-config 1m; |
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.
Should we sync the setting in apisix/cli/ngx_tpl.lua
?
Change 1m
to 10m
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 is enough in the test.
Description
Fixes # (issue)
Checklist