Skip to content

Commit

Permalink
Revert "feat(runloop): reconfiguration completion detection" (#12369)
Browse files Browse the repository at this point in the history
* feat(testing): Remove reconfiguration detection completion mechanism

This mechanism did not work to our satisfaction in traditional mode.  We're
going to try a different approach based on a plugin.

* Delete changelog/unreleased/reconfiguration-completion-detection.yml

KAG-3265

---------

Co-authored-by: Datong Sun <[email protected]>
  • Loading branch information
hanshuebner and dndx authored Jan 25, 2024
1 parent d289c8c commit a6d0bf8
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 239 deletions.
3 changes: 0 additions & 3 deletions changelog/unreleased/reconfiguration-completion-detection.yml

This file was deleted.

8 changes: 1 addition & 7 deletions kong/clustering/config_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ end
---@field config_table table
---@field config_hash string
---@field hashes table<string, string>
---@field current_transaction_id? string|number


---@param declarative_config table
Expand Down Expand Up @@ -343,7 +342,7 @@ local function update(declarative_config, msg)
-- executed by worker 0

local res
res, err = declarative.load_into_cache_with_events(entities, meta, new_hash, hashes, msg.current_transaction_id)
res, err = declarative.load_into_cache_with_events(entities, meta, new_hash, hashes)
if not res then
---@type kong.clustering.config_helper.update.err_t.reload
err_t = {
Expand All @@ -355,11 +354,6 @@ local function update(declarative_config, msg)
return nil, err, err_t
end

if kong.configuration.log_level == "debug" then
ngx_log(ngx.DEBUG, _log_prefix, "loaded configuration with transaction ID ",
msg.current_transaction_id)
end

return true
end

Expand Down
11 changes: 0 additions & 11 deletions kong/clustering/control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local compat = require("kong.clustering.compat")
local constants = require("kong.constants")
local events = require("kong.clustering.events")
local calculate_config_hash = require("kong.clustering.config_helper").calculate_config_hash
local global = require("kong.global")


local string = string
Expand Down Expand Up @@ -134,12 +133,6 @@ function _M:export_deflated_reconfigure_payload()
hashes = hashes,
}

local current_transaction_id
if kong.configuration.log_level == "debug" then
current_transaction_id = global.get_current_transaction_id()
payload.current_transaction_id = current_transaction_id
end

self.reconfigure_payload = payload

payload, err = cjson_encode(payload)
Expand All @@ -160,10 +153,6 @@ function _M:export_deflated_reconfigure_payload()
self.current_config_hash = config_hash
self.deflated_reconfigure_payload = payload

if kong.configuration.log_level == "debug" then
ngx_log(ngx_DEBUG, _log_prefix, "exported configuration with transaction id ", current_transaction_id)
end

return payload, nil, config_hash
end

Expand Down
6 changes: 1 addition & 5 deletions kong/db/declarative/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ do
local DECLARATIVE_LOCK_KEY = "declarative:lock"

-- make sure no matter which path it exits, we released the lock.
load_into_cache_with_events = function(entities, meta, hash, hashes, transaction_id)
load_into_cache_with_events = function(entities, meta, hash, hashes)
local kong_shm = ngx.shared.kong

local ok, err = kong_shm:add(DECLARATIVE_LOCK_KEY, 0, DECLARATIVE_LOCK_TTL)
Expand All @@ -588,10 +588,6 @@ do

ok, err = load_into_cache_with_events_no_lock(entities, meta, hash, hashes)

if ok and transaction_id then
ok, err = kong_shm:set("declarative:current_transaction_id", transaction_id)
end

kong_shm:delete(DECLARATIVE_LOCK_KEY)

return ok, err
Expand Down
11 changes: 0 additions & 11 deletions kong/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ end

local _GLOBAL = {
phases = phase_checker.phases,
CURRENT_TRANSACTION_ID = 0,
}


Expand Down Expand Up @@ -295,14 +294,4 @@ function _GLOBAL.init_timing()
end


function _GLOBAL.get_current_transaction_id()
local rows, err = kong.db.connector:query("select txid_current() as _pg_transaction_id")
if not rows then
return nil, "could not query postgres for current transaction id: " .. err
else
return tonumber(rows[1]._pg_transaction_id)
end
end


return _GLOBAL
4 changes: 0 additions & 4 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1832,10 +1832,6 @@ local function serve_content(module)

ngx.header["Access-Control-Allow-Origin"] = ngx.req.get_headers()["Origin"] or "*"

if kong.configuration.log_level == "debug" then
ngx.header["Kong-Test-Transaction-Id"] = kong_global.get_current_transaction_id()
end

lapis.serve(module)

ctx.KONG_ADMIN_CONTENT_ENDED_AT = get_updated_now_ms()
Expand Down
40 changes: 0 additions & 40 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local concurrency = require "kong.concurrency"
local lrucache = require "resty.lrucache"
local ktls = require "resty.kong.tls"
local request_id = require "kong.tracing.request_id"
local global = require "kong.global"


local PluginsIterator = require "kong.runloop.plugins_iterator"
Expand Down Expand Up @@ -51,7 +50,6 @@ local http_version = ngx.req.http_version
local request_id_get = request_id.get
local escape = require("kong.tools.uri").escape
local encode = require("string.buffer").encode
local yield = require("kong.tools.yield").yield

local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks

Expand Down Expand Up @@ -87,7 +85,6 @@ local QUESTION_MARK = byte("?")
local ARRAY_MT = require("cjson.safe").array_mt

local HOST_PORTS = {}
local IS_DEBUG = false


local SUBSYSTEMS = constants.PROTOCOLS_WITH_SUBSYSTEM
Expand Down Expand Up @@ -751,8 +748,6 @@ do
wasm.set_state(wasm_state)
end

global.CURRENT_TRANSACTION_ID = kong_shm:get("declarative:current_transaction_id") or 0

return true
end) -- concurrency.with_coroutine_mutex

Expand Down Expand Up @@ -897,7 +892,6 @@ return {

init_worker = {
before = function()
IS_DEBUG = (kong.configuration.log_level == "debug")
-- TODO: PR #9337 may affect the following line
local prefix = kong.configuration.prefix or ngx.config.prefix()

Expand Down Expand Up @@ -973,13 +967,6 @@ return {
return
end

-- Before rebuiding the internal structures, retrieve the current PostgreSQL transaction ID to make it the
-- current transaction ID after the rebuild has finished.
local rebuild_transaction_id, err = global.get_current_transaction_id()
if not rebuild_transaction_id then
log(ERR, err)
end

local router_update_status, err = rebuild_router({
name = "router",
timeout = 0,
Expand Down Expand Up @@ -1008,14 +995,6 @@ return {
log(ERR, "could not rebuild wasm filter chains via timer: ", err)
end
end

if rebuild_transaction_id then
-- Yield to process any pending invalidations
yield()

log(DEBUG, "configuration processing completed for transaction ID ", rebuild_transaction_id)
global.CURRENT_TRANSACTION_ID = rebuild_transaction_id
end
end

local _, err = kong.timer:named_every("rebuild",
Expand Down Expand Up @@ -1113,25 +1092,6 @@ return {
},
access = {
before = function(ctx)
if IS_DEBUG then
-- If this is a version-conditional request, abort it if this dataplane has not processed at least the
-- specified configuration version yet.
local if_kong_transaction_id = kong.request and kong.request.get_header('if-kong-test-transaction-id')
if if_kong_transaction_id then
if_kong_transaction_id = tonumber(if_kong_transaction_id)
if if_kong_transaction_id and if_kong_transaction_id >= global.CURRENT_TRANSACTION_ID then
return kong.response.error(
503,
"Service Unavailable",
{
["X-Kong-Reconfiguration-Status"] = "pending",
["Retry-After"] = tostring(kong.configuration.worker_state_update_frequency or 1),
}
)
end
end
end

-- if there is a gRPC service in the context, don't re-execute the pre-access
-- phase handler - it has been executed before the internal redirect
if ctx.service and (ctx.service.protocol == "grpc" or
Expand Down
2 changes: 0 additions & 2 deletions spec/02-integration/04-admin_api/02-kong_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ describe("Admin API - Kong routes with strategy #" .. strategy, function()
res2.headers["Date"] = nil
res1.headers["X-Kong-Admin-Latency"] = nil
res2.headers["X-Kong-Admin-Latency"] = nil
res1.headers["Kong-Test-Transaction-Id"] = nil
res2.headers["Kong-Test-Transaction-Id"] = nil

assert.same(res1.headers, res2.headers)
end)
Expand Down

This file was deleted.

0 comments on commit a6d0bf8

Please sign in to comment.