From bcc85ea552daa3aa0a8cd534133a2134ab95b7fc Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 10 Oct 2023 19:39:06 +0800 Subject: [PATCH 01/26] perf(request-id): introduce $kong_request_id --- .requirements | 2 +- kong/templates/nginx_kong.lua | 4 ++-- kong/tracing/request_id.lua | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.requirements b/.requirements index 161d807efc9..3db21243bf8 100644 --- a/.requirements +++ b/.requirements @@ -6,7 +6,7 @@ OPENSSL=3.1.2 PCRE=8.45 LIBEXPAT=2.5.0 -LUA_KONG_NGINX_MODULE=8296b70ee1256b2cd59f246137b727f049174787 # 0.7.1 +LUA_KONG_NGINX_MODULE=feat/var_kong_request_id # 0.7.x LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index 931992d667f..2f4d2bf89bc 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -54,7 +54,7 @@ exit_worker_by_lua_block { log_format kong_log_format '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' - 'kong_request_id: "$request_id"'; + 'kong_request_id: "$kong_request_id"'; # Load variable indexes lua_kong_load_var_index default; @@ -87,7 +87,7 @@ server { # Append the kong request id to the error log # https://github.com/Kong/lua-kong-nginx-module#lua_kong_error_log_request_id - lua_kong_error_log_request_id $request_id; + lua_kong_error_log_request_id $kong_request_id; > if proxy_access_log_enabled then access_log ${{PROXY_ACCESS_LOG}} kong_log_format; diff --git a/kong/tracing/request_id.lua b/kong/tracing/request_id.lua index c16f7a5d705..f8e33a71d0d 100644 --- a/kong/tracing/request_id.lua +++ b/kong/tracing/request_id.lua @@ -28,7 +28,7 @@ local function get() -- first access to the request id for this request: -- initialize with the value of $request_id - rid = ngx.var.request_id + rid = ngx.var.kong_request_id ngx.ctx.request_id = rid end From 6bb7a4660fa4438d28ed09c111caecf47f4fbff6 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 10 Oct 2023 21:19:26 +0800 Subject: [PATCH 02/26] fix uint test --- spec/01-unit/26-tracing/03-request-id_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/01-unit/26-tracing/03-request-id_spec.lua b/spec/01-unit/26-tracing/03-request-id_spec.lua index 7b6bf3537f4..b1cae577526 100644 --- a/spec/01-unit/26-tracing/03-request-id_spec.lua +++ b/spec/01-unit/26-tracing/03-request-id_spec.lua @@ -3,7 +3,7 @@ local request_id = require "kong.tracing.request_id" local function reset_globals(id) _G.ngx.ctx = {} _G.ngx.var = { - request_id = id, + kong_request_id = id, } _G.ngx.get_phase = function() -- luacheck: ignore return "access" From 61d0d43dd599f0ee7cb65dd287935c52b6a41451 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 07:42:48 +0800 Subject: [PATCH 03/26] fix unit test --- spec/01-unit/10-log_serializer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/01-unit/10-log_serializer_spec.lua b/spec/01-unit/10-log_serializer_spec.lua index d3ba2970a96..bd465d22805 100644 --- a/spec/01-unit/10-log_serializer_spec.lua +++ b/spec/01-unit/10-log_serializer_spec.lua @@ -22,7 +22,7 @@ describe("kong.log.serialize", function() }, }, var = { - request_id = "1234", + kong_request_id = "1234", request_uri = "/request_uri", upstream_uri = "/upstream_uri", scheme = "http", From e812a90a7b1f1092a7aca992c29ff15bd05920ab Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 07:44:56 +0800 Subject: [PATCH 04/26] fix tests --- spec/03-plugins/11-correlation-id/01-access_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/03-plugins/11-correlation-id/01-access_spec.lua b/spec/03-plugins/11-correlation-id/01-access_spec.lua index 3bd73572f2f..492bbdf1d9b 100644 --- a/spec/03-plugins/11-correlation-id/01-access_spec.lua +++ b/spec/03-plugins/11-correlation-id/01-access_spec.lua @@ -481,7 +481,7 @@ for _, strategy in helpers.each_strategy() do local json_log = wait_json_log() local request_id = json_log and json_log.request and json_log.request.id assert.matches("^[a-f0-9]+$", request_id) - assert.True(request_id:len() == 32) + assert.True(request_id:len() == 16) local logged_id = json_log and json_log.correlation_id assert.equals(correlation_id, logged_id) From 97afccb5df602576c8bf2d2b9ec72493c314404e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 07:59:14 +0800 Subject: [PATCH 05/26] update requirements --- .requirements | 2 +- changelog/unreleased/kong/kong_request_id.yml | 3 +++ kong/tracing/request_id.lua | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/kong/kong_request_id.yml diff --git a/.requirements b/.requirements index 3db21243bf8..32ae265bec5 100644 --- a/.requirements +++ b/.requirements @@ -6,7 +6,7 @@ OPENSSL=3.1.2 PCRE=8.45 LIBEXPAT=2.5.0 -LUA_KONG_NGINX_MODULE=feat/var_kong_request_id # 0.7.x +LUA_KONG_NGINX_MODULE=5f619a58c76478c2406038c297d3c4bae1a1a18e # 0.7.x LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 diff --git a/changelog/unreleased/kong/kong_request_id.yml b/changelog/unreleased/kong/kong_request_id.yml new file mode 100644 index 00000000000..47240a603e7 --- /dev/null +++ b/changelog/unreleased/kong/kong_request_id.yml @@ -0,0 +1,3 @@ +message: Bumped lua-kong-nginx-module from 0.7.1 to 0.7.x +type: dependency +scope: Core diff --git a/kong/tracing/request_id.lua b/kong/tracing/request_id.lua index f8e33a71d0d..bb38a1e3d62 100644 --- a/kong/tracing/request_id.lua +++ b/kong/tracing/request_id.lua @@ -27,7 +27,7 @@ local function get() end -- first access to the request id for this request: - -- initialize with the value of $request_id + -- initialize with the value of $kong_request_id rid = ngx.var.kong_request_id ngx.ctx.request_id = rid end From 56bc958160fc1fc1ff5ad2b9ba658ea501b9a310 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 09:00:19 +0800 Subject: [PATCH 06/26] localize ngx.* --- kong/tracing/request_id.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kong/tracing/request_id.lua b/kong/tracing/request_id.lua index bb38a1e3d62..bab196df1bb 100644 --- a/kong/tracing/request_id.lua +++ b/kong/tracing/request_id.lua @@ -1,4 +1,6 @@ local ngx = ngx +local var = ngx.var +local get_phase = ngx.get_phase local NGX_VAR_PHASES = { set = true, @@ -21,14 +23,14 @@ local function get() local rid = get_ctx_request_id() if not rid then - local phase = ngx.get_phase() + local phase = get_phase() if not NGX_VAR_PHASES[phase] then return nil, "cannot access ngx.var in " .. phase .. " phase" end -- first access to the request id for this request: -- initialize with the value of $kong_request_id - rid = ngx.var.kong_request_id + rid = var.kong_request_id ngx.ctx.request_id = rid end From 9f8f0814585b9d8f02ce21b6ef3739998af37fb0 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 09:40:07 +0800 Subject: [PATCH 07/26] fix unit tests --- spec/01-unit/26-tracing/03-request-id_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/01-unit/26-tracing/03-request-id_spec.lua b/spec/01-unit/26-tracing/03-request-id_spec.lua index b1cae577526..b7ad7757de3 100644 --- a/spec/01-unit/26-tracing/03-request-id_spec.lua +++ b/spec/01-unit/26-tracing/03-request-id_spec.lua @@ -43,6 +43,10 @@ describe("Request ID unit tests", function() end) it("returns the expected Request ID and caches it in ctx", function() + + package.loaded["kong.tracing.request_id"] = nil + request_id = require "kong.tracing.request_id" + local id, err = request_id.get() assert.is_nil(err) assert.equal(ngx_var_request_id, id) @@ -54,6 +58,9 @@ describe("Request ID unit tests", function() it("fails if accessed from phase that cannot read ngx.var", function() _G.ngx.get_phase = function() return "init" end + package.loaded["kong.tracing.request_id"] = nil + request_id = require "kong.tracing.request_id" + local id, err = request_id.get() assert.is_nil(id) assert.equal("cannot access ngx.var in init phase", err) From 9f4cfad592809cf5e7e227bff8fd93a1ed0839b8 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 09:46:43 +0800 Subject: [PATCH 08/26] refactor tests --- spec/01-unit/26-tracing/03-request-id_spec.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/01-unit/26-tracing/03-request-id_spec.lua b/spec/01-unit/26-tracing/03-request-id_spec.lua index b7ad7757de3..e4b85be593d 100644 --- a/spec/01-unit/26-tracing/03-request-id_spec.lua +++ b/spec/01-unit/26-tracing/03-request-id_spec.lua @@ -1,4 +1,8 @@ -local request_id = require "kong.tracing.request_id" +local function reload_module(name) + package.loaded[name] = nil + return require(name) +end + local function reset_globals(id) _G.ngx.ctx = {} @@ -44,8 +48,7 @@ describe("Request ID unit tests", function() it("returns the expected Request ID and caches it in ctx", function() - package.loaded["kong.tracing.request_id"] = nil - request_id = require "kong.tracing.request_id" + local request_id = reload_module("kong.tracing.request_id") local id, err = request_id.get() assert.is_nil(err) @@ -58,8 +61,7 @@ describe("Request ID unit tests", function() it("fails if accessed from phase that cannot read ngx.var", function() _G.ngx.get_phase = function() return "init" end - package.loaded["kong.tracing.request_id"] = nil - request_id = require "kong.tracing.request_id" + local request_id = reload_module("kong.tracing.request_id") local id, err = request_id.get() assert.is_nil(id) From 234f7ecc7517823dd17dffd3405db6d50380720e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 10:31:10 +0800 Subject: [PATCH 09/26] updated lua-kong dev branch --- .requirements | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.requirements b/.requirements index 32ae265bec5..ced182c7a1a 100644 --- a/.requirements +++ b/.requirements @@ -6,7 +6,7 @@ OPENSSL=3.1.2 PCRE=8.45 LIBEXPAT=2.5.0 -LUA_KONG_NGINX_MODULE=5f619a58c76478c2406038c297d3c4bae1a1a18e # 0.7.x +LUA_KONG_NGINX_MODULE=bbe6d90cc67b106149ccb2d16ed5840f0915749b # 0.7.x LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 From a5588f3d6e09580e0a92bce4ec88330b764b4147 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 11 Oct 2023 15:07:02 +0800 Subject: [PATCH 10/26] 16 bytes $kong_request_id --- .requirements | 2 +- spec/03-plugins/11-correlation-id/01-access_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.requirements b/.requirements index ced182c7a1a..6168b4a4f8e 100644 --- a/.requirements +++ b/.requirements @@ -6,7 +6,7 @@ OPENSSL=3.1.2 PCRE=8.45 LIBEXPAT=2.5.0 -LUA_KONG_NGINX_MODULE=bbe6d90cc67b106149ccb2d16ed5840f0915749b # 0.7.x +LUA_KONG_NGINX_MODULE=d844ea05227664ad479a11449f092fff0a3c9895 # 0.7.x LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 diff --git a/spec/03-plugins/11-correlation-id/01-access_spec.lua b/spec/03-plugins/11-correlation-id/01-access_spec.lua index 492bbdf1d9b..3bd73572f2f 100644 --- a/spec/03-plugins/11-correlation-id/01-access_spec.lua +++ b/spec/03-plugins/11-correlation-id/01-access_spec.lua @@ -481,7 +481,7 @@ for _, strategy in helpers.each_strategy() do local json_log = wait_json_log() local request_id = json_log and json_log.request and json_log.request.id assert.matches("^[a-f0-9]+$", request_id) - assert.True(request_id:len() == 16) + assert.True(request_id:len() == 32) local logged_id = json_log and json_log.correlation_id assert.equals(correlation_id, logged_id) From 4e86504145d4de077c372eac171dd72750f1d731 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 15:54:46 +0800 Subject: [PATCH 11/26] dont index $request_id --- kong/templates/nginx_kong.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index 2f4d2bf89bc..3f229bf70c9 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -58,7 +58,6 @@ log_format kong_log_format '$remote_addr - $remote_user [$time_local] ' # Load variable indexes lua_kong_load_var_index default; -lua_kong_load_var_index $request_id; lua_kong_load_var_index $http_x_kong_request_debug; lua_kong_load_var_index $http_x_kong_request_debug_token; lua_kong_load_var_index $http_x_kong_request_debug_log; From bb4e56c02bf2aa32c02f3965e15bc581c6484029 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 15:55:18 +0800 Subject: [PATCH 12/26] use $kong_request_id --- kong/tools/request_aware_table.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/tools/request_aware_table.lua b/kong/tools/request_aware_table.lua index 34e67370450..1cc489d65ed 100644 --- a/kong/tools/request_aware_table.lua +++ b/kong/tools/request_aware_table.lua @@ -35,7 +35,7 @@ local function enforce_sequential_access(table) return end - local curr_request_id = var.request_id + local curr_request_id = var.kong_request_id local allowed_request_id = rawget(table, ALLOWED_REQUEST_ID_K) if not allowed_request_id then -- first access. Set allowed request ID and allow access From 268db895b1a90faa23d8d9de26758e66b9722527 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 15:56:19 +0800 Subject: [PATCH 13/26] update lua-kong-module --- .requirements | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.requirements b/.requirements index 6168b4a4f8e..9187c88b13b 100644 --- a/.requirements +++ b/.requirements @@ -6,7 +6,7 @@ OPENSSL=3.1.2 PCRE=8.45 LIBEXPAT=2.5.0 -LUA_KONG_NGINX_MODULE=d844ea05227664ad479a11449f092fff0a3c9895 # 0.7.x +LUA_KONG_NGINX_MODULE=b150e70933cb30d8c5a99fffcb8adc068bfd02c4 # 0.7.x LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 From ccbeb46a6e05d54423b8fb3368816f17c65b386b Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:05:01 +0800 Subject: [PATCH 14/26] use tracing.request_id --- kong/tools/request_aware_table.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kong/tools/request_aware_table.lua b/kong/tools/request_aware_table.lua index 1cc489d65ed..9d36f1cc501 100644 --- a/kong/tools/request_aware_table.lua +++ b/kong/tools/request_aware_table.lua @@ -1,8 +1,9 @@ --- NOTE: tool is designed to assist with **detecting** request contamination -- issues on CI, during test runs. It does not offer security safeguards. -local table_new = require "table.new" -local table_clear = require "table.clear" +local table_new = require("table.new") +local table_clear = require("table.clear") +local get_request_id = require("tracing.request_id").get local is_not_debug_mode = (kong.configuration.log_level ~= "debug") @@ -35,7 +36,7 @@ local function enforce_sequential_access(table) return end - local curr_request_id = var.kong_request_id + local curr_request_id = get_request_id() local allowed_request_id = rawget(table, ALLOWED_REQUEST_ID_K) if not allowed_request_id then -- first access. Set allowed request ID and allow access From 335d6c93cef8c8e36acef38adb2578cb0ca63fa6 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:06:34 +0800 Subject: [PATCH 15/26] fix require mistake --- kong/tools/request_aware_table.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/tools/request_aware_table.lua b/kong/tools/request_aware_table.lua index 9d36f1cc501..0a01a181753 100644 --- a/kong/tools/request_aware_table.lua +++ b/kong/tools/request_aware_table.lua @@ -3,7 +3,7 @@ local table_new = require("table.new") local table_clear = require("table.clear") -local get_request_id = require("tracing.request_id").get +local get_request_id = require("kong.tracing.request_id").get local is_not_debug_mode = (kong.configuration.log_level ~= "debug") From cc3220b57ac7d2752e496a651dbee320b879d512 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:13:38 +0800 Subject: [PATCH 16/26] lint fix --- kong/tools/request_aware_table.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/kong/tools/request_aware_table.lua b/kong/tools/request_aware_table.lua index 0a01a181753..e67d18e9eac 100644 --- a/kong/tools/request_aware_table.lua +++ b/kong/tools/request_aware_table.lua @@ -12,7 +12,6 @@ local error = error local rawset = rawset local setmetatable = setmetatable local get_phase = ngx.get_phase -local var = ngx.var local NGX_VAR_PHASES = { From 32bd4b9256ba40550530dd7db4e9e2a9bd399f30 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:26:09 +0800 Subject: [PATCH 17/26] plugins/aws-lambda/request-util.lua --- kong/plugins/aws-lambda/request-util.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kong/plugins/aws-lambda/request-util.lua b/kong/plugins/aws-lambda/request-util.lua index 136e48272ec..7a5f241824d 100644 --- a/kong/plugins/aws-lambda/request-util.lua +++ b/kong/plugins/aws-lambda/request-util.lua @@ -4,7 +4,8 @@ local ngx_decode_base64 = ngx.decode_base64 local cjson = require "cjson.safe" local pl_stringx = require("pl.stringx") -local date = require "date" +local date = require("date") +local get_request_id = require("kong.tracing.request_id").get local EMPTY = {} @@ -221,7 +222,7 @@ local function aws_serializer(ctx, config) sourceIp = var.realip_remote_addr or var.remote_addr, userAgent = headers["user-agent"], } - local requestId = var.request_id + local requestId = get_request_id() local start_time = ngx_req_start_time() -- The CLF-formatted request time (dd/MMM/yyyy:HH:mm:ss +-hhmm). local requestTime = date(start_time):fmt("%d/%b/%Y:%H:%M:%S %z") From 1e14412dc8db697e4bc0171f50d729f5bb493976 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:34:04 +0800 Subject: [PATCH 18/26] bump lua-kong-module to 0.8.0 --- .requirements | 2 +- changelog/unreleased/kong/kong_request_id.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.requirements b/.requirements index 9187c88b13b..7c6d9812e05 100644 --- a/.requirements +++ b/.requirements @@ -6,7 +6,7 @@ OPENSSL=3.1.2 PCRE=8.45 LIBEXPAT=2.5.0 -LUA_KONG_NGINX_MODULE=b150e70933cb30d8c5a99fffcb8adc068bfd02c4 # 0.7.x +LUA_KONG_NGINX_MODULE=4fbc3ddc7dcbc706ed286b95344f3cb6da17e637 # 0.8.0 LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 diff --git a/changelog/unreleased/kong/kong_request_id.yml b/changelog/unreleased/kong/kong_request_id.yml index 47240a603e7..f2575bd7dda 100644 --- a/changelog/unreleased/kong/kong_request_id.yml +++ b/changelog/unreleased/kong/kong_request_id.yml @@ -1,3 +1,3 @@ -message: Bumped lua-kong-nginx-module from 0.7.1 to 0.7.x +message: Bumped lua-kong-nginx-module from 0.7.1 to 0.8.0 type: dependency scope: Core From b356593708934cf9c2667b00749cade41d476108 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:53:31 +0800 Subject: [PATCH 19/26] rename change log file --- .../kong/{kong_request_id.yml => bump_lua_kong_nginx_module.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog/unreleased/kong/{kong_request_id.yml => bump_lua_kong_nginx_module.yml} (100%) diff --git a/changelog/unreleased/kong/kong_request_id.yml b/changelog/unreleased/kong/bump_lua_kong_nginx_module.yml similarity index 100% rename from changelog/unreleased/kong/kong_request_id.yml rename to changelog/unreleased/kong/bump_lua_kong_nginx_module.yml From f74c125b818a8aa4707a5c1604677132478a00c3 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 20:19:19 +0800 Subject: [PATCH 20/26] fix aws plugin test --- spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua index e70b30e4f07..64815dff430 100644 --- a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua +++ b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua @@ -60,7 +60,7 @@ describe("[AWS Lambda] aws-gateway input", function() var = { request_method = "GET", upstream_uri = "/123/strip/more?boolean=;multi-query=first;single-query=hello%20world;multi-query=second", - request_id = "1234567890", + kong_request_id = "1234567890", host = "abc.myhost.com", remote_addr = "123.123.123.123" }, From 5e476031b1512e2175d77eb920e84100eaa645be Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 20:20:48 +0800 Subject: [PATCH 21/26] fix mock request_id in aws plugin --- spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua index 64815dff430..0a7364af987 100644 --- a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua +++ b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua @@ -140,7 +140,7 @@ describe("[AWS Lambda] aws-gateway input", function() var = { request_method = "GET", upstream_uri = "/plain/strip/more?boolean=;multi-query=first;single-query=hello%20world;multi-query=second", - request_id = "1234567890", + kong_request_id = "1234567890", host = "def.myhost.com", remote_addr = "123.123.123.123" }, @@ -235,7 +235,7 @@ describe("[AWS Lambda] aws-gateway input", function() request_method = "GET", upstream_uri = "/plain/strip/more", http_content_type = tdata.ct, - request_id = "1234567890", + kong_request_id = "1234567890", host = "def.myhost.com", remote_addr = "123.123.123.123" }, From fef896e506dc898cac35d05cd69afcc8572748b1 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 22:01:25 +0800 Subject: [PATCH 22/26] reload module --- spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua index 0a7364af987..8a5940b9f63 100644 --- a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua +++ b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua @@ -30,6 +30,7 @@ describe("[AWS Lambda] aws-gateway input", function() -- make sure to reload the module + package.loaded["kong.tracing.request_id"] = nil package.loaded["kong.plugins.aws-lambda.request-util"] = nil aws_serialize = require "kong.plugins.aws-lambda.request-util".aws_serializer end) From 28b19416026c6cfe8f6044f14ffa960f1515e452 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Fri, 13 Oct 2023 06:34:40 +0800 Subject: [PATCH 23/26] mock get_phase --- spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua index 8a5940b9f63..45f8afe981f 100644 --- a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua +++ b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua @@ -20,6 +20,9 @@ describe("[AWS Lambda] aws-gateway input", function() start_time = function() return mock_request.start_time end, }, log = function() end, + get_phase = function() -- luacheck: ignore + return "access" + end, encode_base64 = old_ngx.encode_base64 }, { -- look up any unknown key in the mock request, eg. .var and .ctx tables From 5866818bcdec762f09492fd20163ee5c16104fab Mon Sep 17 00:00:00 2001 From: chronolaw Date: Fri, 13 Oct 2023 07:43:10 +0800 Subject: [PATCH 24/26] reload aws module --- .../27-aws-lambda/05-aws-serializer_spec.lua | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua index 45f8afe981f..934803cd39d 100644 --- a/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua +++ b/spec/03-plugins/27-aws-lambda/05-aws-serializer_spec.lua @@ -7,6 +7,15 @@ describe("[AWS Lambda] aws-gateway input", function() local old_ngx local aws_serialize + + local function reload_module() + -- make sure to reload the module + package.loaded["kong.tracing.request_id"] = nil + package.loaded["kong.plugins.aws-lambda.request-util"] = nil + aws_serialize = require "kong.plugins.aws-lambda.request-util".aws_serializer + end + + setup(function() old_ngx = ngx local body_data @@ -30,12 +39,6 @@ describe("[AWS Lambda] aws-gateway input", function() return mock_request and mock_request[key] end, }) - - - -- make sure to reload the module - package.loaded["kong.tracing.request_id"] = nil - package.loaded["kong.plugins.aws-lambda.request-util"] = nil - aws_serialize = require "kong.plugins.aws-lambda.request-util".aws_serializer end) teardown(function() @@ -80,6 +83,8 @@ describe("[AWS Lambda] aws-gateway input", function() }, } + reload_module() + local out = aws_serialize() assert.same({ @@ -155,6 +160,8 @@ describe("[AWS Lambda] aws-gateway input", function() }, } + reload_module() + local out = aws_serialize() assert.same({ @@ -250,6 +257,8 @@ describe("[AWS Lambda] aws-gateway input", function() }, } + reload_module() + local out = aws_serialize() assert.same({ From a748f895f329a89aed90866802aadf20960e2e5f Mon Sep 17 00:00:00 2001 From: chronolaw Date: Fri, 13 Oct 2023 10:22:01 +0800 Subject: [PATCH 25/26] rename chagne log yml --- ...ule.yml => bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog/unreleased/kong/{bump_lua_kong_nginx_module.yml => bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml} (100%) diff --git a/changelog/unreleased/kong/bump_lua_kong_nginx_module.yml b/changelog/unreleased/kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml similarity index 100% rename from changelog/unreleased/kong/bump_lua_kong_nginx_module.yml rename to changelog/unreleased/kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml From 594d0550ccbb56b073f4eef9741726baa0b448f7 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Fri, 13 Oct 2023 10:26:31 +0800 Subject: [PATCH 26/26] lua-kong bump --- .../kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml | 3 --- changelog/unreleased/kong/lua_kong_nginx_module_bump.yml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 changelog/unreleased/kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml diff --git a/changelog/unreleased/kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml b/changelog/unreleased/kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml deleted file mode 100644 index f2575bd7dda..00000000000 --- a/changelog/unreleased/kong/bump_lua_kong_nginx_module_from_0_7_1_to_0_8_0.yml +++ /dev/null @@ -1,3 +0,0 @@ -message: Bumped lua-kong-nginx-module from 0.7.1 to 0.8.0 -type: dependency -scope: Core diff --git a/changelog/unreleased/kong/lua_kong_nginx_module_bump.yml b/changelog/unreleased/kong/lua_kong_nginx_module_bump.yml index 6a8f9ac1ff7..92918640e20 100644 --- a/changelog/unreleased/kong/lua_kong_nginx_module_bump.yml +++ b/changelog/unreleased/kong/lua_kong_nginx_module_bump.yml @@ -1,3 +1,3 @@ -message: Bump lua-kong-nginx-module from 0.6.0 to 0.7.1 +message: Bump lua-kong-nginx-module from 0.6.0 to 0.8.0 type: dependency scope: Core