Skip to content

fix(resource): add plugin_configs support for fetch_latest_conf, fix ai-proxy-multi plugin with multi instance not support plugin_config_id#13458

Open
chryancclee-boop wants to merge 3 commits into
apache:masterfrom
chryancclee-boop:master
Open

Conversation

@chryancclee-boop

@chryancclee-boop chryancclee-boop commented May 30, 2026

Copy link
Copy Markdown

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/".
  • 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:

Verification:

  • Single instance + plugin_config_id: 200 (unchanged)
  • Multi-instance + plugin_config_id: 503 -> 200 (fixed)
  • Multi-instance + embedded plugins: 200 (unchanged)

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

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>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels May 30, 2026
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 Baoyuantop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide the corresponding test cases.

Comment thread apisix/resource.lua
key = "/services"
elseif resource_type == "stream_routes" then
key = "/stream_routes"
elseif resource_type == "plugin_configs" then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apisix/resource.lua
elseif resource_type == "stream_routes" then
key = "/stream_routes"
elseif resource_type == "plugin_configs" then
key = "/plugin_configs"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants