diff --git a/kong-3.10.0-0.rockspec b/kong-3.10.0-0.rockspec index 827a13ed6bf..f1b503720b8 100644 --- a/kong-3.10.0-0.rockspec +++ b/kong-3.10.0-0.rockspec @@ -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", diff --git a/kong/clustering/compat/removed_fields.lua b/kong/clustering/compat/removed_fields.lua index 77284a91011..7c50ef514bc 100644 --- a/kong/clustering/compat/removed_fields.lua +++ b/kong/clustering/compat/removed_fields.lua @@ -233,6 +233,6 @@ return { session = { "hash_subject", "store_metadata", - } + }, } } diff --git a/kong/runloop/upstream_retry.lua b/kong/runloop/upstream_retry.lua new file mode 100644 index 00000000000..d38147f9da6 --- /dev/null +++ b/kong/runloop/upstream_retry.lua @@ -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, +} diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index 470fa61e459..1320e8c70cc 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -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 {;}