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

change: use a new name to customize lua_shared_dict in nginx.conf #5030

Merged
merged 2 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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*};
Expand Down
7 changes: 6 additions & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ local config_schema = {
http = {
type = "object",
properties = {
lua_shared_dicts = {
custom_lua_shared_dict = {
Copy link
Member

Choose a reason for hiding this comment

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

will this impact the users upgrade from old version of APISIX?

Copy link
Member Author

Choose a reason for hiding this comment

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

lua_shared_dicts is still available now (only a warn message will generate).

type = "object",
}
}
Expand Down Expand Up @@ -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, " ..
"custom_lua_shared_dict instead\n")
spacewander marked this conversation as resolved.
Show resolved Hide resolved
end

local exported_vars = file.get_exported_vars()
if exported_vars then
if not sys_conf["envs"] then
Expand Down
2 changes: 1 addition & 1 deletion conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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)
Expand Down
56 changes: 56 additions & 0 deletions t/cli/test_http_config.sh
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 0 additions & 20 deletions t/cli/test_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down