Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions apisix/cli/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ local _M = {
["standalone-config"] = "10m",
["status-report"] = "1m",
["upstream-healthcheck"] = "10m",
}
},
custom_lua_shared_dict = {},
},
stream = {
enable_access_log = false,
Expand All @@ -121,7 +122,8 @@ local _M = {
["plugin-limit-conn-stream"] = "10m",
["worker-events-stream"] = "10m",
["tars-stream"] = "1m",
}
},
custom_lua_shared_dict = {},
},
main_configuration_snippet = "",
http_configuration_snippet = "",
Expand Down
14 changes: 14 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ lua {
{% end %}
lua_shared_dict nacos 10m;
lua_shared_dict upstream-healthcheck {* meta.lua_shared_dict["upstream-healthcheck"] *};

# for custom shared dict shared by http and stream subsystems
{% if meta.custom_lua_shared_dict then %}
{% for dict_name, dict_size in pairs(meta.custom_lua_shared_dict) do %}
lua_shared_dict {*dict_name*} {*dict_size*};
{% end %}
{% end %}
}

{% if enabled_stream_plugins["prometheus"] and not enable_http then %}
Expand Down Expand Up @@ -165,6 +172,13 @@ stream {
{% end %}
{% end %}

# for custom shared dict
{% if stream.custom_lua_shared_dict then %}
{% for dict_name, dict_size in pairs(stream.custom_lua_shared_dict) do %}
lua_shared_dict {*dict_name*} {*dict_size*};
{% end %}
{% end %}

resolver {% for _, dns_addr in ipairs(dns_resolver or {}) do %} {*dns_addr*} {% end %} {% if dns_resolver_valid then %} valid={*dns_resolver_valid*}{% end %} ipv6={% if enable_ipv6 then %}on{% else %}off{% end %};
resolver_timeout {*resolver_timeout*};

Expand Down
18 changes: 17 additions & 1 deletion apisix/cli/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,23 @@ local config_schema = {
items = {
type = "string",
}
}
},
meta = {
type = "object",
properties = {
custom_lua_shared_dict = {
type = "object",
}
}
},
stream = {
type = "object",
properties = {
custom_lua_shared_dict = {
type = "object",
}
}
},
},
},
http = {
Expand Down
131 changes: 131 additions & 0 deletions t/cli/test_custom_shared_dict.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/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

# test: custom_lua_shared_dict in meta (global lua {} block, shared by http and stream)
git checkout conf/config.yaml

echo '
nginx_config:
meta:
custom_lua_shared_dict:
my-global-dict: 1m
another-global-dict: 5m
' > conf/config.yaml

make init

# The meta custom_lua_shared_dict should be rendered in the global lua {} block
if ! grep "lua_shared_dict my-global-dict 1m;" conf/nginx.conf > /dev/null; then
echo "failed: meta custom_lua_shared_dict 'my-global-dict' not in nginx.conf"
exit 1
fi

if ! grep "lua_shared_dict another-global-dict 5m;" conf/nginx.conf > /dev/null; then
echo "failed: meta custom_lua_shared_dict 'another-global-dict' not in nginx.conf"
exit 1
fi

echo "passed: meta custom_lua_shared_dict rendered in global lua {} block"

# test: custom_lua_shared_dict in stream {} block
git checkout conf/config.yaml

echo '
apisix:
proxy_mode: http&stream
stream_proxy:
tcp:
- addr: 9100
nginx_config:
stream:
custom_lua_shared_dict:
my-stream-dict: 2m
another-stream-dict: 8m
' > conf/config.yaml

make init

if ! grep "lua_shared_dict my-stream-dict 2m;" conf/nginx.conf > /dev/null; then
echo "failed: stream custom_lua_shared_dict 'my-stream-dict' not in nginx.conf"
exit 1
fi

if ! grep "lua_shared_dict another-stream-dict 8m;" conf/nginx.conf > /dev/null; then
echo "failed: stream custom_lua_shared_dict 'another-stream-dict' not in nginx.conf"
exit 1
fi

echo "passed: stream custom_lua_shared_dict rendered in stream {} block"

# test: meta and stream custom_lua_shared_dict together
git checkout conf/config.yaml

echo '
apisix:
proxy_mode: http&stream
stream_proxy:
tcp:
- addr: 9100
nginx_config:
meta:
custom_lua_shared_dict:
shared-between-subsystems: 3m
http:
custom_lua_shared_dict:
http-only-dict: 4m
stream:
custom_lua_shared_dict:
stream-only-dict: 6m
' > conf/config.yaml

make init

if ! grep "lua_shared_dict shared-between-subsystems 3m;" conf/nginx.conf > /dev/null; then
echo "failed: meta custom_lua_shared_dict 'shared-between-subsystems' not in nginx.conf"
exit 1
fi

if ! grep "lua_shared_dict http-only-dict 4m;" conf/nginx.conf > /dev/null; then
echo "failed: http custom_lua_shared_dict 'http-only-dict' not in nginx.conf"
exit 1
fi

if ! grep "lua_shared_dict stream-only-dict 6m;" conf/nginx.conf > /dev/null; then
echo "failed: stream custom_lua_shared_dict 'stream-only-dict' not in nginx.conf"
exit 1
fi

echo "passed: meta, http, and stream custom_lua_shared_dict all rendered correctly"

# test: empty custom_lua_shared_dict should not break anything
git checkout conf/config.yaml

echo '
nginx_config:
meta:
custom_lua_shared_dict: {}
stream:
custom_lua_shared_dict: {}
' > conf/config.yaml

make init

echo "passed: empty custom_lua_shared_dict does not break init"
Loading