Skip to content
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

feature: support etcd v3 #1943

Closed
wants to merge 11 commits into from
Closed

feature: support etcd v3 #1943

wants to merge 11 commits into from

Conversation

Yiyiyimu
Copy link
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
Member

@Yiyiyimu love you, nice PR

conf/config.yaml Outdated
@@ -122,6 +122,7 @@ etcd:
- "http://127.0.0.1:2379" # multiple etcd address
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 3 seconds
version: "v3" # etcd version
Copy link
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
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
Member

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

@Yiyiyimu
Copy link
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
Member

the same feature as #1941?

@chelintsien
Copy link
Contributor

the same feature as #1941?

yes

@chelintsien chelintsien mentioned this pull request Jul 31, 2020
@Yiyiyimu
Copy link
Member Author

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

@nic-chen
Copy link
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
Copy link
Contributor

chelintsien commented Jul 31, 2020 via email

@chelintsien
Copy link
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
Member

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

@Yiyiyimu
Copy link
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
Copy link
Member Author

Yiyiyimu commented Aug 1, 2020

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

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
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
Copy link
Member Author

Yiyiyimu commented Aug 1, 2020

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]

@@ -19,6 +19,8 @@ local local_conf = require("apisix.core.config_local").local_conf()

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

apisix/core/config_etcd.lua Outdated Show resolved Hide resolved
apisix/http/router/radixtree_host_uri.lua Show resolved Hide resolved
Copy link
Contributor

@chelintsien chelintsien left a comment

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
Copy link
Member Author

Yiyiyimu commented Aug 2, 2020

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

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

@@ -705,20 +705,17 @@ GET /t
"uri": "/index.html"
}]],
[[{
"node": {
Copy link
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
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
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