Skip to content

feature: support etcd v3#1943

Closed
Yiyiyimu wants to merge 11 commits into
apache:masterfrom
Yiyiyimu:etcdv3
Closed

feature: support etcd v3#1943
Yiyiyimu wants to merge 11 commits into
apache:masterfrom
Yiyiyimu:etcdv3

Conversation

@Yiyiyimu

Copy link
Copy Markdown
Member

What this PR does / why we need it:

fix #1767

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible?

@membphis

Copy link
Copy Markdown
Member

@Yiyiyimu love you, nice PR

Comment thread conf/config.yaml Outdated
- "http://127.0.0.1:2379" # multiple etcd address
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 3 seconds
version: "v3" # etcd version

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.

I think we can only support etcd v3

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.

In my plan, I'll implement for etcd v3 only at first, and then go to multi-version etcd, if necessary. And of course I'll be glad if we support v3 only.

@moonming

Copy link
Copy Markdown
Member

@Yiyiyimu do we need to update lua-resty-etcd first?

@Yiyiyimu

Copy link
Copy Markdown
Member Author

@Yiyiyimu do we need to update lua-resty-etcd first?

Hi @moonming I think v1.0 would be enough for now.

I'm trying to make all the changes on the APISIX side but there might be some modifications on lua-resty-etcd later, for example, compact(to avoid revision accumulation) has not been fully implemented yet. So I think it would be better to release newer version of lua-resty-etcd sometime later when everything on this side is settled down.

@moonming

Copy link
Copy Markdown
Member

the same feature as #1941?

@chelintsien

Copy link
Copy Markdown
Contributor

the same feature as #1941?

yes

@chelintsien chelintsien mentioned this pull request Jul 31, 2020
@Yiyiyimu

Copy link
Copy Markdown
Member Author

Hi @chelintsien @moonming supporting etcd v3 is a task of ISCAS summer plan (#1542)

@nic-chen

Copy link
Copy Markdown
Member

Hi, @chelintsien, Thank you for your contribution!
As @Yiyiyimu said, etcd v3 support is a task of summer 2020. He spent a lot of time studying and researching and working with APISIX and lua-resty-etcd. And judging from the code submitted by this pr, I think he can do this job well. We should give him the opportunity to complete this task. You can help review the code, which is also a great contribution. What do you think?

@Yiyiyimu etcd v3 support is an urgent need, we should hurry up and complete it as soon as possible.

@chelintsien

chelintsien commented Jul 31, 2020 via email

Copy link
Copy Markdown
Contributor

@chelintsien

Copy link
Copy Markdown
Contributor

Since the production environment uses apisix and apisix doesn't support etcd v3 at the moment so it took almost a day to deal with this issue, sorry for not seeing this assignment, agree with you! @nic-chen

@nic-chen

Copy link
Copy Markdown
Member

@chelintsien Thank you for your hard work and the understanding. :)

@Yiyiyimu

Copy link
Copy Markdown
Member Author

@Yiyiyimu etcd v3 support is an urgent need, we should hurry up and complete it as soon as possible.

Sure I'll try to provide the minimum working PR ASAP

@Yiyiyimu

Yiyiyimu commented Aug 1, 2020

Copy link
Copy Markdown
Member Author

Feature implemented in this commit:

  • Change etcd version directly in config.yaml and core.lua would do the job to select etcd.lua and config_etcd.lua of a certain version. Thanks to @nic-chen's idea.
  • Trying to make the output of v2&v3 stay the same, so we don't need to make a copy of test files just a little bit different from each other. The main modification is inside test_admin.t for now. And I'm still in the middle of trying to modify each test file to make it compatible with both v2 and v3 output. I'm not so sure if there would be a more elegant way to implement this feature

And another question hasn't been solved here is do we need multi-version of etcd? @moonming

Comment thread t/lib/test_admin.lua
end
res_data = res_data.node and res_data.node or res_data
res_data = res_data.nodes and res_data.nodes or res_data
res_data = #res_data == 1 and res_data[1] or res_data

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.

The main modification to make the output of v2&v3 stay the same

@Yiyiyimu

Yiyiyimu commented Aug 1, 2020

Copy link
Copy Markdown
Member Author

Some difference of v2/v3 being solved:

-- v2 v3
delete key not exist return 404 return 200, but response body.deleted(num) would become nil
implicitly get dir the same of readdir(don't know why) only return single k-v
response of set return key and value only return headers
normal response k-v is under body/node k-v is under body/kvs[1]
readdir response k-v is under body/node/nodes[1..n] k-v is under body/kvs[1..n]

Comment thread apisix/core.lua

local config_center = local_conf.apisix and local_conf.apisix.config_center
or "etcd"
local etcd_version = local_conf.etcd.version == "v3" and "_v3" or ""

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.

all code in one line is not easy to read.

split it into multiple lines is better for this case.

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.

Sure, just which one would be better, if-else, or like config_center to split or case into next line

Comment thread apisix/core/config_etcd.lua Outdated
Comment thread apisix/http/router/radixtree_host_uri.lua

@chelintsien chelintsien left a comment

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.

need to support etcd v3 in file : bin/apisix (init_etcd function)

@Yiyiyimu

Yiyiyimu commented Aug 2, 2020

Copy link
Copy Markdown
Member Author

need to support etcd v3 in file : bin/apisix (init_etcd function)

Thank you and your work! I've overlooked this part before

Comment thread t/admin/routes.t
"uri": "/index.html"
}]],
[[{
"node": {

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'd better keep the old response structure.

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.

Hi @membphis! Response of etcd v3 is quite different from v2. For example like this, v3 would not return action, and flatten "node-nodes" structure into one layer "kvs". Thus I try to only return content inside node/nodes and kvs, to develop compatibility of different etcd version,

But modifying all test files is quite a big work. So I just submit a PR to mock etcd v2 response in #2036, keeping the old structure if we need.
But I still believe it could be better to get closer to v3 structure, since v2 could be deprecated one day, and there are some new functions of v3 that could not been mocked into v2.

@Yiyiyimu

Copy link
Copy Markdown
Member Author

Close since #2036 is merged

@Yiyiyimu Yiyiyimu closed this Sep 16, 2020
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.

feature: support etcd v3

5 participants