Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion apisix/plugins/ai-proxy-multi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,11 @@ function _M.construct_upstream(instance)
local upstream = {}
local node = instance._dns_value
if not node then
return nil, "failed to resolve endpoint for instance: " .. instance.name
resolve_endpoint(instance)
node = instance._dns_value
if not node then
return nil, "failed to resolve endpoint for instance: " .. instance.name
end
Comment thread
nic-6443 marked this conversation as resolved.
end

if not node.host or not node.port then
Expand Down
47 changes: 47 additions & 0 deletions t/plugin/ai-proxy-multi3.t
Original file line number Diff line number Diff line change
Expand Up @@ -1060,3 +1060,50 @@ failed to get health check target status
--- error_log
releasing existing checker
--- timeout: 5



=== TEST 14: construct_upstream resolves _dns_value when nil (config table replacement scenario)
--- config
location /t {
content_by_lua_block {
local plugin = require("apisix.plugins.ai-proxy-multi")

-- Simulate an instance after config table replacement: _dns_value is lost
local instance = {
name = "test-instance",
provider = "openai",
weight = 1,
priority = 0,
override = {
endpoint = "https://127.0.0.1:443",
},
Comment thread
nic-6443 marked this conversation as resolved.
auth = {
header = {
Authorization = "Bearer test-key",
},
},
}

-- Confirm _dns_value is nil (simulating config table replacement)
assert(instance._dns_value == nil, "_dns_value should be nil initially")

-- construct_upstream should resolve _dns_value as fallback
local upstream, err = plugin.construct_upstream(instance)
if not upstream then
ngx.say("FAIL: " .. err)
return
end

-- Verify _dns_value was populated
assert(instance._dns_value ~= nil, "_dns_value should be set after construct_upstream")

ngx.say("host: ", upstream.nodes[1].host)
ngx.say("port: ", upstream.nodes[1].port)
ngx.say("passed")
}
}
--- response_body
host: 127.0.0.1
port: 443
Comment thread
nic-6443 marked this conversation as resolved.
passed
Loading