Skip to content

Commit

Permalink
change: use a new name to customize lua_shared_dict in nginx.conf (#5030
Browse files Browse the repository at this point in the history
)

Co-authored-by: Alex Zhang <[email protected]>
  • Loading branch information
spacewander and tokers authored Sep 13, 2021
1 parent 9c73271 commit f51729a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 22 deletions.
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 = {
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, " ..
"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
Expand Down
2 changes: 1 addition & 1 deletion conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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

0 comments on commit f51729a

Please sign in to comment.