You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/09/13 03:51:09 UTC
[apisix] branch master updated: change: use a new name to customize
lua_shared_dict in nginx.conf (#5030)
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 f51729a change: use a new name to customize lua_shared_dict in nginx.conf (#5030)
f51729a is described below
commit f51729a24ec0d6c1060b3f1c6b27057951dddc57
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Mon Sep 13 11:51:04 2021 +0800
change: use a new name to customize lua_shared_dict in nginx.conf (#5030)
Co-authored-by: Alex Zhang <to...@apache.org>
---
apisix/cli/ngx_tpl.lua | 5 +++++
apisix/cli/ops.lua | 7 +++++-
conf/config-default.yaml | 2 +-
t/cli/test_http_config.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++++
t/cli/test_main.sh | 20 -----------------
5 files changed, 68 insertions(+), 22 deletions(-)
diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
index 3b9b841..4bc02fc 100644
--- a/apisix/cli/ngx_tpl.lua
+++ b/apisix/cli/ngx_tpl.lua
@@ -189,6 +189,11 @@ http {
lua_shared_dict access-tokens {* http.lua_shared_dict["access-tokens"] *}; # cache for service account access tokens
# for custom shared dict
+ {% if http.custom_lua_shared_dict then %}
+ {% for cache_key, cache_size in pairs(http.custom_lua_shared_dict) do %}
+ lua_shared_dict {*cache_key*} {*cache_size*};
+ {% end %}
+ {% end %}
{% if http.lua_shared_dicts then %}
{% for cache_key, cache_size in pairs(http.lua_shared_dicts) do %}
lua_shared_dict {*cache_key*} {*cache_size*};
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index 0fcfa13..ef0be7f 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -265,7 +265,7 @@ local config_schema = {
http = {
type = "object",
properties = {
- lua_shared_dicts = {
+ custom_lua_shared_dict = {
type = "object",
}
}
@@ -750,6 +750,11 @@ Please modify "admin_key" in conf/config.yaml .
sys_conf["worker_processes"] = floor(tonumber(env_worker_processes))
end
+ if sys_conf["http"]["lua_shared_dicts"] then
+ stderr:write("lua_shared_dicts is deprecated, " ..
+ "use custom_lua_shared_dict instead\n")
+ end
+
local exported_vars = file.get_exported_vars()
if exported_vars then
if not sys_conf["envs"] then
diff --git a/conf/config-default.yaml b/conf/config-default.yaml
index 781239b..5e3a0db 100644
--- a/conf/config-default.yaml
+++ b/conf/config-default.yaml
@@ -217,7 +217,7 @@ nginx_config: # config for render the template to generate n
real_ip_from: # http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
- 127.0.0.1
- "unix:"
- #lua_shared_dicts: # add custom shared cache to nginx.conf
+ #custom_lua_shared_dict: # add custom shared cache to nginx.conf
# ipc_shared_dict: 100m # custom shared cache, format: `cache-key: cache-size`
# Enables or disables passing of the server name through TLS Server Name Indication extension (SNI, RFC 6066)
diff --git a/t/cli/test_http_config.sh b/t/cli/test_http_config.sh
new file mode 100755
index 0000000..6e87741
--- /dev/null
+++ b/t/cli/test_http_config.sh
@@ -0,0 +1,56 @@
+#!/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
+
+git checkout conf/config.yaml
+
+echo '
+nginx_config:
+ http:
+ custom_lua_shared_dict:
+ my_dict: 1m
+' > conf/config.yaml
+
+make init
+
+if ! grep "lua_shared_dict my_dict 1m;" conf/nginx.conf > /dev/null; then
+ echo "failed: define custom shdict"
+ exit 1
+fi
+
+echo "passed: define custom shdict"
+
+git checkout conf/config.yaml
+
+echo '
+nginx_config:
+ http:
+ lua_shared_dicts:
+ my_dict: 1m
+' > conf/config.yaml
+
+make init
+
+if ! grep "lua_shared_dict my_dict 1m;" conf/nginx.conf > /dev/null; then
+ echo "failed: define custom shdict in the old way"
+ exit 1
+fi
+
+echo "passed: define custom shdict in the old way"
diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh
index d267f6f..ec1476b 100755
--- a/t/cli/test_main.sh
+++ b/t/cli/test_main.sh
@@ -514,26 +514,6 @@ fi
rm conf/config_original.yaml conf/customized_config.yaml
echo "passed: customized config.yaml copied and reverted succeeded"
-# allow to merge configuration without middle layer
-
-git checkout conf/config.yaml
-
-echo '
-nginx_config:
- http:
- lua_shared_dicts:
- my_dict: 1m
-' > conf/config.yaml
-
-make init
-
-if ! grep "lua_shared_dict my_dict 1m;" conf/nginx.conf > /dev/null; then
- echo "failed: 'my_dict' not in nginx.conf"
- exit 1
-fi
-
-echo "passed: found 'my_dict' in nginx.conf"
-
# check disable cpu affinity
git checkout conf/config.yaml