-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(opentelemetry): increase default queue batch size
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
1 parent
e42933e
commit 72379e9
Showing
6 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- Helper module for 331_to_332 migration operations. | ||
-- | ||
-- Operations are versioned and specific to a migration so they remain | ||
-- fixed in time and are not modified for use in future migrations. | ||
-- | ||
-- If you want to reuse these operations in a future migration, | ||
-- copy the functions over to a new versioned module. | ||
|
||
|
||
local function render(template, keys) | ||
return (template:gsub("$%(([A-Z_]+)%)", keys)) | ||
end | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
-- Postgres operations for Workspace migration | ||
-------------------------------------------------------------------------------- | ||
|
||
|
||
local postgres = { | ||
|
||
up = {}, | ||
|
||
teardown = { | ||
|
||
------------------------------------------------------------------------------ | ||
-- General function to fixup a plugin configuration | ||
fixup_plugin_config = function(_, connector, plugin_name, fixup_fn) | ||
local pgmoon_json = require("pgmoon.json") | ||
local select_plugin = render( | ||
"SELECT id, name, config FROM plugins WHERE name = '$(NAME)'", { | ||
NAME = plugin_name | ||
}) | ||
|
||
local plugins, err = connector:query(select_plugin) | ||
if not plugins then | ||
return nil, err | ||
end | ||
|
||
for _, plugin in ipairs(plugins) do | ||
local fix = fixup_fn(plugin.config) | ||
if fix then | ||
local sql = render( | ||
"UPDATE plugins SET config = $(NEW_CONFIG)::jsonb WHERE id = '$(ID)'", { | ||
NEW_CONFIG = pgmoon_json.encode_json(plugin.config), | ||
ID = plugin.id, | ||
}) | ||
|
||
local _, err = connector:query(sql) | ||
if err then | ||
return nil, err | ||
end | ||
end | ||
end | ||
|
||
return true | ||
end, | ||
}, | ||
|
||
} | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
|
||
|
||
return { | ||
postgres = postgres, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
local operations = require "kong.db.migrations.operations.331_to_332" | ||
|
||
|
||
local function ws_migration_teardown(ops) | ||
return function(connector) | ||
return ops:fixup_plugin_config(connector, "opentelemetry", function(config) | ||
if config.queue.max_batch_size == 1 then | ||
config.queue.max_batch_size = 200 | ||
return true | ||
end | ||
|
||
return false | ||
end) | ||
end | ||
end | ||
|
||
|
||
return { | ||
postgres = { | ||
up = "", | ||
teardown = ws_migration_teardown(operations.postgres.teardown), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
return { | ||
"001_331_to_332", | ||
} |
55 changes: 55 additions & 0 deletions
55
spec/05-migration/plugins/opentelemetry/migrations/001_331_to_332_spec.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters