This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new b41287131 feat(deployment): data_plane does not write data to etcd
(#7294)
b41287131 is described below
commit b412871319925f9ad01cfaaabc16b00a54a8d9b7
Author: tzssangglass <[email protected]>
AuthorDate: Wed Jun 22 18:18:57 2022 +0800
feat(deployment): data_plane does not write data to etcd (#7294)
---
apisix/cli/ops.lua | 9 ++++++-
apisix/plugins/server-info.lua | 9 +++++++
docs/en/latest/plugins/request-id.md | 6 +++++
docs/zh/latest/plugins/request-id.md | 6 +++++
t/cli/test_deployment_data_plane.sh | 52 ++++++++++++++++++++++++++++++++++++
5 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index 9a275648e..d2275bed5 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -545,6 +545,10 @@ Please modify "admin_key" in conf/config.yaml .
util.die(err, "\n")
end
+ if yaml_conf.deployment and yaml_conf.deployment.role then
+ env.deployment_role = yaml_conf.deployment.role
+ end
+
-- Using template.render
local sys_conf = {
use_openresty_1_17 = use_openresty_1_17,
@@ -810,7 +814,10 @@ local function start(env, ...)
end
init(env)
- init_etcd(env, args)
+
+ if env.deployment_role ~= "data_plane" then
+ init_etcd(env, args)
+ end
util.execute_cmd(env.openresty_args)
end
diff --git a/apisix/plugins/server-info.lua b/apisix/plugins/server-info.lua
index 055bafa28..b7cd67793 100644
--- a/apisix/plugins/server-info.lua
+++ b/apisix/plugins/server-info.lua
@@ -261,6 +261,15 @@ function _M.init()
return
end
+
+ local local_conf = core.config.local_conf()
+ local deployment_role = core.table.try_read_attr(
+ local_conf, "deployment", "role")
+ if deployment_role == "data_plane" then
+ -- data_plane should not write to etcd
+ return
+ end
+
local attr = plugin.plugin_attr(plugin_name)
local ok, err = core.schema.check(attr_schema, attr)
if not ok then
diff --git a/docs/en/latest/plugins/request-id.md
b/docs/en/latest/plugins/request-id.md
index 05505ac8d..cc18b75ee 100644
--- a/docs/en/latest/plugins/request-id.md
+++ b/docs/en/latest/plugins/request-id.md
@@ -47,6 +47,12 @@ The Plugin will not add a unique ID if the request already
has a header with the
| include_in_response | boolean | False | true |
| When set to `true`, adds the unique request ID in the response
header. |
| algorithm | string | False | "uuid" | ["uuid",
"snowflake", "nanoid"] | Algorithm to use for generating the unique request ID.
|
+:::warning
+
+When you need to use `snowflake` algorithm, make sure APISIX has the
permission to write to the etcd.
+
+:::
+
### Using snowflake algorithm to generate unique ID
To use the snowflake algorithm, you have to enable it first on your
configuration file (`conf/config.yaml`):
diff --git a/docs/zh/latest/plugins/request-id.md
b/docs/zh/latest/plugins/request-id.md
index 5482672ea..03490f197 100644
--- a/docs/zh/latest/plugins/request-id.md
+++ b/docs/zh/latest/plugins/request-id.md
@@ -33,6 +33,12 @@ title: request-id
| include_in_response | boolean | 可选 | true | |
是否需要在返回头中包含该唯一 ID |
| algorithm | string | 可选 | "uuid" | ["uuid", "snowflake",
"nanoid"] | ID 生成算法 |
+:::warning
+
+当使用 `snowflake` 算法时,请确保 APISIX 有权限写入 etcd。
+
+:::
+
## 如何启用
创建一条路由并在该路由上启用 `request-id` 插件:
diff --git a/t/cli/test_deployment_data_plane.sh
b/t/cli/test_deployment_data_plane.sh
new file mode 100755
index 000000000..379265319
--- /dev/null
+++ b/t/cli/test_deployment_data_plane.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# clean etcd data
+etcdctl del / --prefix
+
+# data_plane does not write data to etcd
+echo '
+deployment:
+ role: data_plane
+ role_data_plane:
+ config_provider: control_plane
+ control_plane:
+ host:
+ - http://127.0.0.1:2379
+ timeout: 30
+ certs:
+ cert: /path/to/ca-cert
+ cert_key: /path/to/ca-cert
+ trusted_ca_cert: /path/to/ca-cert
+' > conf/config.yaml
+
+make run
+
+sleep 1
+
+res=$(etcdctl get / --prefix | wc -l)
+
+if [ ! $res -eq 0 ]; then
+ echo "failed: data_plane should not write data to etcd"
+ exit 1
+fi
+
+echo "passed: data_plane does not write data to etcd"