From 3dd6966a692db184ea521c510866dec49c1107de Mon Sep 17 00:00:00 2001 From: samugi Date: Mon, 2 Oct 2023 12:49:03 +0200 Subject: [PATCH] fix(hybrid): opentelemetry and zipkin header_type address compatibility for older DPs for the opentelemetry and zipkin configuration option: `header_type` and for zipkin's `default_heder_type` --- kong/clustering/compat/checkers.lua | 68 ++++++++++++++ .../09-hybrid_mode/09-config-compat_spec.lua | 89 ++++++++++++++++++- 2 files changed, 156 insertions(+), 1 deletion(-) diff --git a/kong/clustering/compat/checkers.lua b/kong/clustering/compat/checkers.lua index 7fbfca3cec22..78498222e726 100644 --- a/kong/clustering/compat/checkers.lua +++ b/kong/clustering/compat/checkers.lua @@ -23,6 +23,74 @@ end local compatible_checkers = { + { 3005000000, --[[ 3.5.0.0 ]] + function(config_table, dp_version, log_suffix) + local has_update + + for _, plugin in ipairs(config_table.plugins or {}) do + if plugin.name == 'opentelemetry' or plugin.name == 'zipkin' then + local config = plugin.config + if config.header_type == 'gcp' then + config.header_type = 'preserve' + log_warn_message('configures ' .. plugin.name .. ' plugin with:' .. + ' header_type == gcp', + 'overwritten with default value `preserve`', + dp_version, log_suffix) + has_update = true + end + end + + if plugin.name == 'zipkin' then + local config = plugin.config + if config.default_header_type == 'gcp' then + config.default_header_type = 'b3' + log_warn_message('configures ' .. plugin.name .. ' plugin with:' .. + ' default_header_type == gcp', + 'overwritten with default value `b3`', + dp_version, log_suffix) + has_update = true + end + end + end + + return has_update + end, + }, + + { 3004000000, --[[ 3.4.0.0 ]] + function(config_table, dp_version, log_suffix) + local has_update + + for _, plugin in ipairs(config_table.plugins or {}) do + if plugin.name == 'opentelemetry' or plugin.name == 'zipkin' then + local config = plugin.config + if config.header_type == 'aws' then + config.header_type = 'preserve' + log_warn_message('configures ' .. plugin.name .. ' plugin with:' .. + ' header_type == aws', + 'overwritten with default value `preserve`', + dp_version, log_suffix) + has_update = true + end + end + + if plugin.name == 'zipkin' then + local config = plugin.config + if config.default_header_type == 'aws' then + config.default_header_type = 'b3' + log_warn_message('configures ' .. plugin.name .. ' plugin with:' .. + ' default_header_type == aws', + 'overwritten with default value `b3`', + dp_version, log_suffix) + has_update = true + end + end + end + + return has_update + end, + }, + { 3003000000, --[[ 3.3.0.0 ]] function(config_table, dp_version, log_suffix) local has_update diff --git a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua index 3e4470c05f7d..ce941e445abd 100644 --- a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua +++ b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua @@ -108,7 +108,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() end) describe("plugin config fields", function() - local rate_limit, cors + local rate_limit, cors, opentelemetry, zipkin lazy_setup(function() rate_limit = admin.plugins:insert { @@ -195,6 +195,93 @@ describe("CP/DP config compat transformations #" .. strategy, function() do_assert(utils.uuid(), "3.5.0", cors) end) end) + + describe("compatibility tests for opentelemetry plugin", function() + it("replaces `aws` values of `header_type` property with default `preserve`", function() + -- [[ 3.5.x ]] -- + opentelemetry = admin.plugins:insert { + name = "opentelemetry", + enabled = true, + config = { + endpoint = "http://1.1.1.1:12345/v1/trace", + -- [[ new value 3.5.0 + header_type = "gcp" + -- ]] + } + } + + local expected_otel_prior_35 = utils.cycle_aware_deep_copy(opentelemetry) + expected_otel_prior_35.config.header_type = "preserve" + do_assert(utils.uuid(), "3.4.0", expected_otel_prior_35) + + -- cleanup + admin.plugins:remove({ id = opentelemetry.id }) + + -- [[ 3.4.x ]] -- + opentelemetry = admin.plugins:insert { + name = "opentelemetry", + enabled = true, + config = { + endpoint = "http://1.1.1.1:12345/v1/trace", + -- [[ new value 3.4.0 + header_type = "aws" + -- ]] + } + } + + local expected_otel_prior_34 = utils.cycle_aware_deep_copy(opentelemetry) + expected_otel_prior_34.config.header_type = "preserve" + do_assert(utils.uuid(), "3.3.0", expected_otel_prior_34) + + -- cleanup + admin.plugins:remove({ id = opentelemetry.id }) + end) + + end) + + describe("compatibility tests for zipkin plugin", function() + it("replaces `aws` and `gcp` values of `header_type` property with default `preserve`", function() + -- [[ 3.5.x ]] -- + zipkin = admin.plugins:insert { + name = "zipkin", + enabled = true, + config = { + http_endpoint = "http://1.1.1.1:12345/v1/trace", + -- [[ new value 3.5.0 + header_type = "gcp" + -- ]] + } + } + + local expected_zipkin_prior_35 = utils.cycle_aware_deep_copy(zipkin) + expected_zipkin_prior_35.config.header_type = "preserve" + expected_zipkin_prior_35.config.default_header_type = "b3" + do_assert(utils.uuid(), "3.4.0", expected_zipkin_prior_35) + + -- cleanup + admin.plugins:remove({ id = zipkin.id }) + + -- [[ 3.4.x ]] -- + zipkin = admin.plugins:insert { + name = "zipkin", + enabled = true, + config = { + http_endpoint = "http://1.1.1.1:12345/v1/trace", + -- [[ new value 3.4.0 + header_type = "aws" + -- ]] + } + } + + local expected_zipkin_prior_34 = utils.cycle_aware_deep_copy(zipkin) + expected_zipkin_prior_34.config.header_type = "preserve" + expected_zipkin_prior_34.config.default_header_type = "b3" + do_assert(utils.uuid(), "3.3.0", expected_zipkin_prior_34) + + -- cleanup + admin.plugins:remove({ id = zipkin.id }) + end) + end) end) end)