Skip to content

feat: support reading configuration form xds(mvp)#6614

Merged
spacewander merged 33 commits into
apache:masterfrom
tzssangglass:cgtf
Mar 22, 2022
Merged

feat: support reading configuration form xds(mvp)#6614
spacewander merged 33 commits into
apache:masterfrom
tzssangglass:cgtf

Conversation

@tzssangglass

@tzssangglass tzssangglass commented Mar 15, 2022

Copy link
Copy Markdown
Member

Description

Fixes # (issue)

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added in this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backwards compatible (If not, please discuss on the APISIX mailing list first)

Comment thread t/amesh-agent/config_shdict.t Outdated
Comment thread apisix/core/config_shdict.lua Outdated


ffi.cdef[[
extern void CreateMock(void* writeRoute);

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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()

Comment thread apisix/core/config_shdict.lua Outdated
Comment thread apisix/core/config_shdict.lua Outdated
Comment thread apisix/core/config_shdict.lua Outdated
Comment thread apisix/core/config_shdict.lua Outdated
Comment thread apisix/core/config_shdict.lua Outdated
@tzssangglass
tzssangglass marked this pull request as ready for review March 17, 2022 02:27
Comment thread .github/workflows/build.yml Outdated
- 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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread apisix/cli/ops.lua Outdated
end
sys_conf["wasm"] = yaml_conf.wasm

sys_conf["config_center"] = yaml_conf.apisix.config_center

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Handled in

for k,v in pairs(yaml_conf.apisix) do

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

rm this

Comment thread apisix/cli/schema.lua Outdated
properties = {
config_center = {
enum = {"etcd", "yaml"},
enum = {"etcd", "yaml", "shdict"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
enum = {"etcd", "yaml", "shdict"},
enum = {"etcd", "yaml", "xds"},

would be better?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread apisix/core/config_shdict.lua Outdated


local function load_libamesh(lib_name)
ngx_timer_at(0, function(premature)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why use the timer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread apisix/core/config_shdict.lua Outdated
end


function _M.new(key, opts)

Copy link
Copy Markdown
Member

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?

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_

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread .github/workflows/build.yml Outdated
- 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is amesh?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed, use xds

Comment thread .github/workflows/build.yml Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread apisix/core/config_xds.lua Outdated
Comment on lines +55 to +58
local string_gmatch = string.gmatch
local string_match = string.match
local io_open = io.open
local io_close = io.close

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread apisix/core/config_xds.lua Outdated
local tried_paths = new_tab(32, 0)
local i = 1

for k, _ in string_gmatch(cpath, "[^;]+") do

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread apisix/core/config_xds.lua Outdated
local i = 1

for k, _ in string_gmatch(cpath, "[^;]+") do
local fpath = string_match(k, "(.*/)")

Copy link
Copy Markdown
Contributor

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?

Comment thread apisix/init.lua Outdated
require("apisix.balancer").init_worker()
load_balancer = require("apisix.balancer")

if core.config == require("apisix.core.config_shdict") then

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member

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

Signed-off-by: tzssangglass <[email protected]>
Signed-off-by: tzssangglass <[email protected]>
Signed-off-by: tzssangglass <[email protected]>
Comment thread apisix/core/config_xds.lua Outdated


function _M.init_worker()
local lib_name = "libxds.so"

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

@tao12345666333 tao12345666333 left a comment

Copy link
Copy Markdown
Member

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.

@spacewander

Copy link
Copy Markdown
Member

IMHO, external is too general to know what it does. As etcd is an external service, what is the difference between etcd and external?
Moreover, we don't promise any API spec about the xds exchange format and we might optimize it for xds in the future. So I think using the name xds is specific enough for this feature.

Comment thread t/xds-library/config_xds.t Outdated
__DATA__

=== TEST 1: load Amesh library so successfully
--- yaml_config

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread apisix/init.lua Outdated
require("apisix.balancer").init_worker()
load_balancer = require("apisix.balancer")

if core.config == require("apisix.core.config_xds") then

Copy link
Copy Markdown
Member

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:

if core.config.init then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

@tao12345666333

Copy link
Copy Markdown
Member

So I think using the name xds is specific enough for this feature.

OK so we can keep this naming for now and let's move forward.

Comment thread apisix/cli/ngx_tpl.lua Outdated
{% end %}

{% if config_center == "xds" then %}
lua_shared_dict router-config 10m;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
lua_shared_dict router-config 10m;
lua_shared_dict xds-route-config 10m;

would that be better?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread 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"]

@spacewander spacewander Mar 20, 2022

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread 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: " ..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
error("can not load Amesh library, tried paths: " ..
error("can not load xds library, tried paths: " ..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread 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"]

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

local new_tab = base.new_tab
local ffi = require ("ffi")
local C = ffi.C
local route_config = ngx.shared["xds-route-config"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
local route_config = ngx.shared["xds-route-config"]
local route_config = ngx.shared["xds-route-config"]

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK

Comment thread t/APISIX.pm
lua_shared_dict ext-plugin 1m;
lua_shared_dict kubernetes 1m;
lua_shared_dict tars 1m;
lua_shared_dict xds-route-config 1m;

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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.

@spacewander
spacewander merged commit d2e3380 into apache:master Mar 22, 2022
@tzssangglass
tzssangglass deleted the cgtf branch March 25, 2022 02:04
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.

7 participants