fix(resource): add plugin_configs support for fetch_latest_conf, fix ai-proxy-multi plugin with multi instance not support plugin_config_id#13458
Conversation
When the ai-proxy-multi plugin uses plugin_config_id to reference a PluginConfig containing multiple instances, APISIX returns a 503 error: "fetch_latest_conf(): unsupported resource type: plugin_configs". Root cause: - pick_target() in ai-proxy-multi.lua calls resource.fetch_latest_conf() to fetch the parent configuration for load balancing and health checking. - When referencing via plugin_config_id, the _meta.parent.resource_key is set to "/plugin_configs/<id>". - resource.fetch_latest_conf() previously only supported upstreams, routes, services, and stream_routes, causing it to reject "plugin_configs". Why single instance works: - Single instance scenarios bypass pick_target() entirely since no load balancing is needed, so resource.fetch_latest_conf() is never invoked. Fix: - Add "plugin_configs" to the supported resource types in resource.lua. Verification: - Single instance + plugin_config_id: 200 (unchanged) - Multi-instance + plugin_config_id: 503 -> 200 (fixed) - Multi-instance + embedded plugins: 200 (unchanged) Signed-off-by: lichunhan <chryancc.lee@gmail.com>
When the ai-proxy-multi plugin uses plugin_config_id to reference a PluginConfig containing multiple instances, APISIX returns a 503 error: "fetch_latest_conf(): unsupported resource type: plugin_configs". Root cause: - pick_target() in ai-proxy-multi.lua calls resource.fetch_latest_conf() to fetch the parent configuration for load balancing and health checking. - When referencing via plugin_config_id, the _meta.parent.resource_key is set to "/plugin_configs/<id>". - resource.fetch_latest_conf() previously only supported upstreams, routes, services, and stream_routes, causing it to reject "plugin_configs". Why single instance works: - Single instance scenarios bypass pick_target() entirely since no load balancing is needed, so resource.fetch_latest_conf() is never invoked. Fix: - Add "plugin_configs" to the supported resource types in resource.lua. Verification: - Single instance + plugin_config_id: 200 (unchanged) - Multi-instance + plugin_config_id: 503 -> 200 (fixed) - Multi-instance + embedded plugins: 200 (unchanged) Signed-off-by: lichunhan <chryancc.lee@gmail.com>
Baoyuantop
left a comment
There was a problem hiding this comment.
Please provide the corresponding test cases.
| key = "/services" | ||
| elseif resource_type == "stream_routes" then | ||
| key = "/stream_routes" | ||
| elseif resource_type == "plugin_configs" then |
There was a problem hiding this comment.
This fixes plugin_configs, but the same 503 still exists for the other resource types that attach plugins with _meta.parent: apisix/global_rules.lua, apisix/consumer_group.lua and apisix/consumer.lua all call plugin.set_plugins_meta_parent too, so e.g. ai-proxy-multi with multiple instances in a global_rule fails with the exact same unsupported resource type error. Since every supported prefix here just maps to itself, maybe turn this if/else chain into a lookup table covering all resource types that can carry plugins, instead of adding them one at a time.
| elseif resource_type == "stream_routes" then | ||
| key = "/stream_routes" | ||
| elseif resource_type == "plugin_configs" then | ||
| key = "/plugin_configs" |
There was a problem hiding this comment.
To make Baoyuantop's ask concrete: none of the t/plugin/ai-proxy-multi*.t files currently exercise plugin_config_id, so this bug had no coverage. A minimal regression block would fit in t/plugin/ai-proxy-multi.balancer.t: create a plugin_config with ai-proxy-multi and 2 instances, create a route referencing it via plugin_config_id, then assert the request succeeds — before this fix it returns 503 with failed to fetch the parent config. The existing multi-instance setup in that file can be reused almost as-is.
When the ai-proxy-multi plugin uses plugin_config_id to reference a PluginConfig containing multiple instances, APISIX returns a 503 error: "fetch_latest_conf(): unsupported resource type: plugin_configs".
Root cause:
Why single instance works:
Fix:
Verification:
Checklist