Skip to content

Commit

Permalink
chore: backport ee next upstream retry runloop change to ce
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Jan 24, 2025
1 parent 0294d7b commit 1cda8bc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions kong-3.10.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ build = {
["kong.runloop.plugin_servers.rpc.util"] = "kong/runloop/plugin_servers/rpc/util.lua",
["kong.runloop.plugin_servers.rpc.mp_rpc"] = "kong/runloop/plugin_servers/rpc/mp_rpc.lua",
["kong.runloop.plugin_servers.rpc.pb_rpc"] = "kong/runloop/plugin_servers/rpc/pb_rpc.lua",
["kong.runloop.upstream_retry"] = "kong/runloop/upstream_retry.lua",
["kong.runloop.wasm"] = "kong/runloop/wasm.lua",
["kong.runloop.wasm.plugins"] = "kong/runloop/wasm/plugins.lua",
["kong.runloop.wasm.properties"] = "kong/runloop/wasm/properties.lua",
Expand Down
2 changes: 1 addition & 1 deletion kong/clustering/compat/removed_fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ return {
session = {
"hash_subject",
"store_metadata",
}
},
}
}
46 changes: 46 additions & 0 deletions kong/runloop/upstream_retry.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- This software is copyright Kong Inc. and its licensors.
-- Use of the software is subject to the agreement between your organization
-- and Kong Inc. If there is no such agreement, use is governed by and
-- subject to the terms of the Kong Master Software License Agreement found
-- at https://konghq.com/enterprisesoftwarelicense/.
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local kset_next_upstream
if ngx.config.subsystem ~= "stream" then
kset_next_upstream = require("resty.kong.upstream").set_next_upstream
end

local ngx = ngx
local log = ngx.log
local ERR = ngx.ERR

local function set_proxy_next_upstream(next_upstream)
local err = kset_next_upstream(unpack(next_upstream))
if err then
log(ERR, "failed to set next upstream: ", err)
end

if ngx.ctx and ngx.ctx.balancer_data then
ngx.ctx.balancer_data.next_upstream = next_upstream
end
end

local function fallback_proxy_next_upstream()
if not ngx.ctx.balancer_data then
return
end

if not ngx.ctx.balancer_data.next_upstream then
return
end

local err = kset_next_upstream(unpack(ngx.ctx.balancer_data.next_upstream))
if err then
log(ERR, "failed to set next upstream: ", err)
end
end

return {
set_proxy_next_upstream = set_proxy_next_upstream,
fallback_proxy_next_upstream = fallback_proxy_next_upstream,
}
2 changes: 2 additions & 0 deletions kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ server {
-- we need to re-set them here to the new nginx request.
local ctx = ngx.ctx
local upstream_ssl = require("kong.runloop.upstream_ssl")
local upstream_retry = require("kong.runloop.upstream_retry")
upstream_ssl.set_service_ssl(ctx)
upstream_ssl.fallback_upstream_client_cert(ctx)
upstream_retry.fallback_proxy_next_upstream()
}
access_by_lua_block {;}
header_filter_by_lua_block {;}
Expand Down

0 comments on commit 1cda8bc

Please sign in to comment.