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

feat: move tinyyaml to lyaml #11312

Merged
merged 35 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f89d78b
feat: move tinyyaml to lyaml
bzp2010 Jun 1, 2024
bc4f467
fix: schema
bzp2010 Jun 1, 2024
1eed81e
chore: use yaml var name
bzp2010 Jun 1, 2024
22a96fe
feat: change nil checker
bzp2010 Jun 1, 2024
db3e4e9
fix
bzp2010 Jun 1, 2024
a51a4b5
fix
bzp2010 Jun 1, 2024
86af9ba
fix
bzp2010 Jun 1, 2024
af0f798
fix
bzp2010 Jun 1, 2024
e5863b9
fix log rotate 2
bzp2010 Jun 1, 2024
7a81fce
fix otel 3
bzp2010 Jun 1, 2024
15ea62a
fix zipkin 3
bzp2010 Jun 1, 2024
be53239
fix admin cli
bzp2010 Jun 1, 2024
06c0022
fix kubernetes 3
bzp2010 Jun 1, 2024
2b4089c
fix plugin metadata
bzp2010 Jun 1, 2024
fbaad05
fix https proxy
bzp2010 Jun 1, 2024
d33cff4
fix config etcd
bzp2010 Jun 1, 2024
3665a04
fix least conn
bzp2010 Jun 1, 2024
32a7c37
fix consumer
bzp2010 Jun 1, 2024
1d40318
fix plugin
bzp2010 Jun 1, 2024
0e7f69f
fix cli main
bzp2010 Jun 1, 2024
d711411
fix etcd mtls
bzp2010 Jun 1, 2024
5731118
fix stream kubernetes
bzp2010 Jun 1, 2024
5a70b97
fix cli main 2
bzp2010 Jun 1, 2024
2858ed3
fix pb health checker
bzp2010 Jun 1, 2024
b7b3aad
fix cli main 3
bzp2010 Jun 1, 2024
a10e136
fix pb sanity
bzp2010 Jun 1, 2024
6ab3c29
fix upstream discovery
bzp2010 Jun 1, 2024
bfad49e
fix cli pm rip
bzp2010 Jun 1, 2024
a349951
fix nodes
bzp2010 Jun 1, 2024
44a01c7
fix shellcheck 1
bzp2010 Jun 1, 2024
b2972e0
fix radixtree host uri2
bzp2010 Jun 1, 2024
be658f5
fix cli pm rip
bzp2010 Jun 1, 2024
c660936
proxy mode type hint
bzp2010 Jun 1, 2024
8f0bd8a
remove tinyyaml
bzp2010 Jun 2, 2024
7cd15fb
fix prometheus 4
bzp2010 Jun 2, 2024
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
1 change: 0 additions & 1 deletion apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dependencies = {
"lua-protobuf = 0.5.0-1",
"lua-resty-openidc = 1.7.6-3",
"luafilesystem = 1.7.0-2",
"api7-lua-tinyyaml = 0.4.4",
"nginx-lua-prometheus-api7 = 0.20240201-1",
"jsonschema = 0.9.8",
"lua-resty-ipmatcher = 0.6.1",
Expand Down
19 changes: 5 additions & 14 deletions apisix/cli/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
-- limitations under the License.
--

local yaml = require("tinyyaml")
local yaml = require("lyaml")
local profile = require("apisix.core.profile")
local util = require("apisix.cli.util")
local dkjson = require("dkjson")

local pairs = pairs
local type = type
local tonumber = tonumber
local getmetatable = getmetatable
local getenv = os.getenv
local str_gmatch = string.gmatch
local str_find = string.find
Expand Down Expand Up @@ -157,14 +156,6 @@ local function replace_by_reserved_env_vars(conf)
end


local function tinyyaml_type(t)
local mt = getmetatable(t)
if mt then
return mt.__type
end
end


local function path_is_multi_type(path, type_val)
if str_sub(path, 1, 14) == "nginx_config->" and
(type_val == "number" or type_val == "string") then
Expand All @@ -188,7 +179,7 @@ local function merge_conf(base, new_tab, ppath)

for key, val in pairs(new_tab) do
if type(val) == "table" then
if tinyyaml_type(val) == "null" then
if val == yaml.null then
base[key] = nil

elseif tab_is_array(val) then
Expand Down Expand Up @@ -243,7 +234,7 @@ function _M.read_yaml_conf(apisix_home)
return nil, err
end

local default_conf = yaml.parse(default_conf_yaml)
local default_conf = yaml.load(default_conf_yaml)
if not default_conf then
return nil, "invalid config-default.yaml file"
end
Expand All @@ -266,7 +257,7 @@ function _M.read_yaml_conf(apisix_home)
end

if not is_empty_file then
local user_conf = yaml.parse(user_conf_yaml)
local user_conf = yaml.load(user_conf_yaml)
if not user_conf then
return nil, "invalid config.yaml file"
end
Expand Down Expand Up @@ -306,7 +297,7 @@ function _M.read_yaml_conf(apisix_home)
local apisix_conf_path = profile:yaml_path("apisix")
local apisix_conf_yaml, _ = util.read_file(apisix_conf_path)
if apisix_conf_yaml then
local apisix_conf = yaml.parse(apisix_conf_yaml)
local apisix_conf = yaml.load(apisix_conf_yaml)
if apisix_conf then
local ok, err = resolve_conf_var(apisix_conf)
if not ok then
Expand Down
4 changes: 2 additions & 2 deletions apisix/core/config_yaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

local config_local = require("apisix.core.config_local")
local config_util = require("apisix.core.config_util")
local yaml = require("tinyyaml")
local yaml = require("lyaml")
local log = require("apisix.core.log")
local json = require("apisix.core.json")
local new_tab = require("table.new")
Expand Down Expand Up @@ -100,7 +100,7 @@ local function read_apisix_yaml(premature, pre_mtime)
local yaml_config = f:read("*a")
f:close()

local apisix_yaml_new = yaml.parse(yaml_config)
local apisix_yaml_new = yaml.load(yaml_config)
if not apisix_yaml_new then
log.error("failed to parse the content of file " .. apisix_yaml_path)
return
Expand Down
4 changes: 2 additions & 2 deletions apisix/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-- limitations under the License.
--
local require = require
local yaml = require("tinyyaml")
local yaml = require("lyaml")
local log = require("apisix.core.log")
local profile = require("apisix.core.profile")
local lfs = require("lfs")
Expand Down Expand Up @@ -130,7 +130,7 @@ local function read_debug_yaml()
local yaml_config = f:read("*a")
f:close()

local debug_yaml_new = yaml.parse(yaml_config)
local debug_yaml_new = yaml.load(yaml_config)
if not debug_yaml_new then
log.error("failed to parse the content of file " .. debug_yaml_path)
return
Expand Down
4 changes: 2 additions & 2 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ apisix:
memory_size: 50m # Size of the memory to store the cache index.
disk_size: 1G # Size of the disk to store the cache data.
disk_path: /tmp/disk_cache_one # Path to the cache file for disk cache.
cache_levels: 1:2 # Cache hierarchy levels of disk cache.
cache_levels: "1:2" # Cache hierarchy levels of disk cache.
# - name: disk_cache_two
# memory_size: 50m
# disk_size: 1G
Expand All @@ -73,7 +73,7 @@ apisix:
ssl: radixtree_sni # radixtree_sni: match route by SNI

# http is the default proxy mode. proxy_mode can be one of `http`, `stream`, or `http&stream`
proxy_mode: http
proxy_mode: "http"
# stream_proxy: # TCP/UDP L4 proxy
# tcp:
# - addr: 9100 # Set the TCP proxy listening ports.
Expand Down
4 changes: 2 additions & 2 deletions docs/en/latest/plugins/body-transformer.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ For example, parse YAML to JSON yourself:

```
{%
local yaml = require("tinyyaml")
local body = yaml.parse(_body)
local yaml = require("lyaml")
local body = yaml.load(_body)
%}
{"foobar":"{{body.foobar.foo .. " " .. body.foobar.bar}}"}
```
Expand Down
3 changes: 1 addition & 2 deletions t/cli/test_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ deployment:
admin:
allow_admin: ~
admin_key:
-
name: "admin"
- name: "admin"
key: ''
role: admin
' > conf/config.yaml
Expand Down
8 changes: 4 additions & 4 deletions t/cli/test_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ echo "passed: disable ssl_session_tickets by default"
# support 3rd-party plugin
echo '
apisix:
extra_lua_path: "\$prefix/example/?.lua"
extra_lua_cpath: "\$prefix/example/?.lua"
extra_lua_path: "$prefix/example/?.lua"
extra_lua_cpath: "$prefix/example/?.lua"
plugins:
- 3rd-party
stream_plugins:
Expand Down Expand Up @@ -716,7 +716,7 @@ echo "passed: bad lua_module_hook should be rejected"
echo '
apisix:
proxy_mode: http&stream
extra_lua_path: "\$prefix/example/?.lua"
extra_lua_path: "$prefix/example/?.lua"
lua_module_hook: "my_hook"
stream_proxy:
tcp:
Expand Down Expand Up @@ -838,7 +838,7 @@ apisix:
disk_path: /tmp/disk_cache_one
disk_size: 100m
memory_size: 20m
cache_levels: 1:2
cache_levels: "1:2"
' > conf/config.yaml

make init
Expand Down
18 changes: 9 additions & 9 deletions t/cli/test_prometheus_run_in_privileged.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ rm logs/error.log || true

echo '
apisix:
extra_lua_path: "\$prefix/t/lib/?.lua"
extra_lua_path: "$prefix/t/lib/?.lua"
nginx_config:
error_log_level: info
' > conf/config.yaml
Expand All @@ -53,10 +53,10 @@ echo "prometheus run in privileged agent successfully when only http is enabled"
sleep 0.5
rm logs/error.log || true

echo "
echo '
apisix:
proxy_mode: http&stream
extra_lua_path: "\$prefix/t/lib/?.lua"
proxy_mode: "http&stream"
extra_lua_path: "$prefix/t/lib/?.lua"
enable_admin: true
stream_proxy:
tcp:
Expand All @@ -65,7 +65,7 @@ stream_plugins:
- prometheus
nginx_config:
error_log_level: info
" > conf/config.yaml
' > conf/config.yaml

make run
sleep 0.1
Expand All @@ -86,10 +86,10 @@ make stop
sleep 0.5
rm logs/error.log || true

echo "
echo '
apisix:
proxy_mode: http&stream
extra_lua_path: "\$prefix/t/lib/?.lua"
proxy_mode: "http&stream"
extra_lua_path: "$prefix/t/lib/?.lua"
enable_admin: false
stream_proxy:
tcp:
Expand All @@ -98,7 +98,7 @@ stream_plugins:
- prometheus
nginx_config:
error_log_level: info
" > conf/config.yaml
' > conf/config.yaml

make run
sleep 0.1
Expand Down
19 changes: 6 additions & 13 deletions t/config-center-yaml/consumer.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ deployment:
_EOC_

$block->set_value("yaml_config", $yaml_config);

my $routes = <<_EOC_;
routes:
-
uri: /hello
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
_EOC_

$block->set_value("apisix_yaml", $block->apisix_yaml . $routes);
});

run_tests();
Expand All @@ -57,6 +44,12 @@ __DATA__
--- apisix_yaml
consumers:
- username: jwt-auth
routes:
- uri: /hello
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
--- request
GET /hello
Expand Down
8 changes: 4 additions & 4 deletions t/config-center-yaml/plugin-configs.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ routes:
plugin_config_id: 1
upstream:
nodes:
"127.0.0.1:1980":1
"127.0.0.1:1980": 1
type: roundrobin
#END
--- response_body
Expand All @@ -74,7 +74,7 @@ routes:
plugin_config_id: 1
upstream:
nodes:
"127.0.0.1:1980":1
"127.0.0.1:1980": 1
type: roundrobin
#END
--- error_code: 503
Expand Down Expand Up @@ -105,7 +105,7 @@ routes:
body: "world\n"
upstream:
nodes:
"127.0.0.1:1980":1
"127.0.0.1:1980": 1
type: roundrobin
#END
--- request
Expand Down Expand Up @@ -135,7 +135,7 @@ routes:
plugin_config_id: 1
upstream:
nodes:
"127.0.0.1:1980":1
"127.0.0.1:1980": 1
type: roundrobin
#END
--- error_code: 503
Expand Down
2 changes: 1 addition & 1 deletion t/config-center-yaml/plugin-metadata.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ routes:
plugin_metadata:
- id: http-logger
log_format:
host: "$host",
host: "$host"
remote_addr: "$remote_addr"
#END
--- request
Expand Down
29 changes: 17 additions & 12 deletions t/config-center-yaml/plugin.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@ _EOC_

$block->set_value("yaml_config", $yaml_config);

my $routes = <<_EOC_;
if (!$block->apisix_yaml) {
my $routes = <<_EOC_;
routes:
-
uri: /hello
- uri: /hello
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
_EOC_

$block->set_value("apisix_yaml", $block->apisix_yaml . $routes);
$block->set_value("apisix_yaml", $block->extra_apisix_yaml . $routes);
}
});

our $debug_config = t::APISIX::read_file("conf/debug.yaml");
$debug_config =~ s/basic:\n enable: false/basic:\n enable: true/;

run_tests();

## TODO: extra_apisix_yaml is specific to this document and is not standard behavior for
## the APISIX testing framework, so it should be standardized or replaced later.

__DATA__

=== TEST 1: sanity
--- apisix_yaml
--- extra_apisix_yaml
plugins:
- name: ip-restriction
- name: jwt-auth
Expand Down Expand Up @@ -111,7 +115,7 @@ plugins:
- jwt-auth
stream_plugins:
- mqtt-proxy
--- apisix_yaml
--- extra_apisix_yaml
plugins:
- name: ip-restriction
- name: jwt-auth
Expand Down Expand Up @@ -144,7 +148,7 @@ qr/(loaded plugin and sort by priority: (3000 name: ip-restriction|2510 name: jw


=== TEST 3: disable plugin and its router
--- apisix_yaml
--- extra_apisix_yaml
plugins:
- name: jwt-auth
--- request
Expand All @@ -162,6 +166,7 @@ routes:
plugins:
- name: public-api
- name: prometheus
#END
--- request
GET /apisix/prometheus/metrics

Expand All @@ -181,7 +186,7 @@ plugins:
- jwt-auth
stream_plugins:
- mqtt-proxy
--- apisix_yaml
--- extra_apisix_yaml
plugins:
- name: xxx
stream: ip-restriction
Expand All @@ -197,7 +202,7 @@ load(): plugins not changed


=== TEST 6: empty plugin list
--- apisix_yaml
--- extra_apisix_yaml
plugins:
stream_plugins:
--- debug_config eval: $::debug_config
Expand Down
Loading
Loading