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

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

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.

@neu-hsc

neu-hsc commented Jun 22, 2026

Copy link
Copy Markdown

Hi, I noticed this PR already contains the minimal resource.lua fix for plugin_configs.

I prepared a local regression test for the ai-proxy-multi + plugin_config_id + multiple instances case discussed in #13456. The test uses apisix_yaml to avoid Admin API/etcd setup flakiness and the existing local AI fixture, so it does not call any external LLM service.

Local focused test result:

TEST_NGINX_BINARY=/usr/local/openresty/bin/openresty \
prove --timer -I/opt/test-nginx/lib -I. -I./t \
t/plugin/ai-proxy-multi-plugin-config.t

Result: All tests successful. Files=1, Tests=4, Result: PASS.

Would it be helpful if I open a small test-only PR based on this PR's fix, or would you prefer me to share the test patch here?

@AlinsRan

AlinsRan commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the thorough root-cause writeup — the fetch_latest_conf() gap on plugin_configs (only reached via pick_target() in the multi-instance path) was diagnosed exactly right.

We ended up fixing this more broadly in #13663 (merged): rather than adding just plugin_configs, it covers all plugin-bearing resource types (plugin_configs, global_rules, consumers, consumer_groups) in fetch_latest_conf in one place, plus a regression test — which closes the same gap this PR targets and then some. #13456 is resolved by it.

Closing as superseded by #13663. Appreciate the clear diagnosis and repro.

@AlinsRan AlinsRan closed this Jul 7, 2026
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.

5 participants