diff --git a/apisix/core/config_yaml.lua b/apisix/core/config_yaml.lua index fbf3106f..e8eabb64 100644 --- a/apisix/core/config_yaml.lua +++ b/apisix/core/config_yaml.lua @@ -332,6 +332,16 @@ function _M.new(key, opts) return nil, "missing `key` argument" end + local ok, ok2, err = pcall(sync_data, obj) + if not ok then + err = ok2 + end + + if err then + log.error("failed to fetch data from local file ", apisix_yaml_path, ": ", + err, ", ", key) + end + ngx_timer_at(0, _automatic_fetch, obj) end diff --git a/apisix/init.lua b/apisix/init.lua index 2fea8416..d71fd70c 100644 --- a/apisix/init.lua +++ b/apisix/init.lua @@ -718,8 +718,8 @@ function _M.stream_init_worker() -- for testing only core.log.info("random stream test in [1, 10000]: ", math.random(1, 10000)) - router.stream_init_worker() plugin.init_worker() + router.stream_init_worker() if core.config == require("apisix.core.config_yaml") then core.config.init_worker() diff --git a/apisix/plugin.lua b/apisix/plugin.lua index ea0a54b4..8af3dd79 100644 --- a/apisix/plugin.lua +++ b/apisix/plugin.lua @@ -267,14 +267,12 @@ function _M.load(config) -- called during synchronizing plugin data http_plugin_names = {} stream_plugin_names = {} - for _, conf_value in config_util.iterate_values(config.values) do - local plugins_conf = conf_value.value - for _, conf in ipairs(plugins_conf) do - if conf.stream then - core.table.insert(stream_plugin_names, conf.name) - else - core.table.insert(http_plugin_names, conf.name) - end + local plugins_conf = config.value + for _, conf in ipairs(plugins_conf) do + if conf.stream then + core.table.insert(stream_plugin_names, conf.name) + else + core.table.insert(http_plugin_names, conf.name) end end end @@ -486,8 +484,10 @@ do automatic = true, item_schema = core.schema.plugins, single_item = true, - filter = function() - _M.load(plugins_conf) + filter = function(item) + -- we need to pass 'item' instead of plugins_conf because + -- the latter one is nil at the first run + _M.load(item) end, }) if not plugins_conf then