Skip to content

Commit

Permalink
fix(opentelemetry): increase default queue batch size
Browse files Browse the repository at this point in the history
migration to update the wrongly set default queue batch size to 200

adapt test to run only for 3.x

(cherry picked from commit b0940b2)
  • Loading branch information
samugi authored and hanshuebner committed Feb 20, 2024
1 parent 9a82197 commit 2a19856
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

local cjson = require "cjson"
local uh = require "spec.upgrade_helpers"


if uh.database_type() == 'postgres' then
local handler = uh.get_busted_handler("3.3.0", "3.6.0")
handler("opentelemetry plugin migration", function()
lazy_setup(function()
assert(uh.start_kong())
end)

lazy_teardown(function ()
assert(uh.stop_kong(nil, true))
end)

uh.setup(function ()
local admin_client = assert(uh.admin_client())

local res = assert(admin_client:send {
method = "POST",
path = "/plugins/",
body = {
name = "opentelemetry",
config = {
endpoint = "http://localhost:8080/v1/traces",
}
},
headers = {
["Content-Type"] = "application/json"
}
})
local body = assert.res_status(201, res)
local json = cjson.decode(body)
-- assert that value of old default is 1
assert.equals(json.config.queue.max_batch_size, 1)
admin_client:close()
end)

uh.new_after_finish("has updated opentelemetry queue max_batch_size configuration", function ()
local admin_client = assert(uh.admin_client())
local res = assert(admin_client:send {
method = "GET",
path = "/plugins/"
})
local body = cjson.decode(assert.res_status(200, res))
assert.equal(1, #body.data)

local plugin = body.data[1]
assert.equal("opentelemetry", plugin.name)
assert.equals(200, plugin.config.queue.max_batch_size)
admin_client:close()
end)
end)
end
39 changes: 38 additions & 1 deletion spec/upgrade_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ local function all_phases(phrase, f)
return it_when("all_phases", phrase, f)
end


--- Get a Busted test handler for migration tests.
--
-- This convenience function determines the appropriate Busted handler
-- (`busted.describe` or `busted.pending`) based on the "old Kong version"
-- that migrations are running on and the specified version range.
--
-- @function get_busted_handler
-- @param min_version The minimum Kong version (inclusive)
-- @param max_version The maximum Kong version (inclusive)
-- @return `busted.describe` if Kong's version is within the specified range,
-- `busted.pending` otherwise.
-- @usage
-- local handler = get_busted_handler("3.3.0", "3.6.0")
-- handler("some migration test", function() ... end)
local get_busted_handler
do
local function get_version_num(v1, v2)
if v2 then
assert(#v2 == #v1, string.format("different version format: %s and %s", v1, v2))
end
return assert(tonumber((v1:gsub("%.", ""))), "invalid version: " .. v1)
end

function get_busted_handler(min_version, max_version)
local old_version_var = assert(os.getenv("OLD_KONG_VERSION"), "old version not set")
local old_version = string.match(old_version_var, "[^/]+$")

local old_version_num = get_version_num(old_version)
local min_v_num = min_version and get_version_num(min_version, old_version) or 0
local max_v_num = max_version and get_version_num(max_version, old_version) or math.huge

return old_version_num >= min_v_num and old_version_num <= max_v_num and busted.describe or busted.pending
end
end

return {
database_type = database_type,
get_database = get_database,
Expand All @@ -180,5 +216,6 @@ return {
old_after_up = old_after_up,
new_after_up = new_after_up,
new_after_finish = new_after_finish,
all_phases = all_phases
all_phases = all_phases,
get_busted_handler = get_busted_handler,
}

0 comments on commit 2a19856

Please sign in to comment.