From 4cffb6f236ad0937af89f359e619e65c2f1d6006 Mon Sep 17 00:00:00 2001 From: Vinicius Mignot Date: Wed, 22 May 2024 12:06:11 -0300 Subject: [PATCH 01/16] docs(changelog): apply suggestions --- changelog/unreleased/kong/cleanup_ai.yml | 2 +- changelog/unreleased/kong/log-serializer-kong-latency.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changelog/unreleased/kong/cleanup_ai.yml b/changelog/unreleased/kong/cleanup_ai.yml index 61e9c2c70dc4..9f3be7ab16de 100644 --- a/changelog/unreleased/kong/cleanup_ai.yml +++ b/changelog/unreleased/kong/cleanup_ai.yml @@ -1,4 +1,4 @@ message: | - Cleanup some AI plugins, and improve errorhandling. + Improve error handling in AI plugins. type: bugfix scope: Plugin diff --git a/changelog/unreleased/kong/log-serializer-kong-latency.yml b/changelog/unreleased/kong/log-serializer-kong-latency.yml index b1760fca7df1..219e2979245c 100644 --- a/changelog/unreleased/kong/log-serializer-kong-latency.yml +++ b/changelog/unreleased/kong/log-serializer-kong-latency.yml @@ -5,6 +5,7 @@ message: | the new `latencies.receive` metric, so if desired, the old value can be calculated as `latencies.kong + latencies.receive`. **Note:** this also affects payloads from all logging plugins that use the log serializer: - `file-log`, `tcp-log`, `udp-log`,`http-log`, `syslog`, and `loggly`. + `file-log`, `tcp-log`, `udp-log`,`http-log`, `syslog`, and `loggly`, e.g. + [descriptions of JSON objects for the HTTP Log Plugin's log format](https://docs.konghq.com/hub/kong-inc/http-log/log-format/#json-object-descriptions). type: bugfix scope: PDK From 8807aa73462988773a97ecacaf604633a9b8a18d Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Thu, 23 May 2024 14:29:41 +0800 Subject: [PATCH 02/16] tests(dns): fix the flakiness of the individual_toip test case (#13060) KAG-4520 --- spec/01-unit/21-dns-client/02-client_spec.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spec/01-unit/21-dns-client/02-client_spec.lua b/spec/01-unit/21-dns-client/02-client_spec.lua index 6b2685b870f6..9fdf281511d6 100644 --- a/spec/01-unit/21-dns-client/02-client_spec.lua +++ b/spec/01-unit/21-dns-client/02-client_spec.lua @@ -1501,10 +1501,11 @@ describe("[DNS client]", function() assert.are.equal("recursion detected", port) end) - it("individual_noip - force no sync", function() + it("individual_toip - force no sync", function() local resolve_count = 10 assert(client.init({ noSynchronisation = false, + order = { "A" }, })) local callcount = 0 @@ -1522,15 +1523,15 @@ describe("[DNS client]", function() end) end + for i=1,#threads do + ngx.thread.wait(threads[i]) + end + -- only one thread must have called the query_func assert.are.equal(1, callcount, "synchronisation failed - out of " .. resolve_count .. " toip() calls " .. callcount .. " queries were made") - for i=1,#threads do - ngx.thread.wait(threads[i]) - end - callcount = 0 threads = {} for i=1,resolve_count do @@ -1540,14 +1541,15 @@ describe("[DNS client]", function() end) end + for i=1,#threads do + ngx.thread.wait(threads[i]) + end + -- all threads must have called the query_func assert.are.equal(resolve_count, callcount, "force no sync failed - out of " .. resolve_count .. " toip() calls" .. callcount .. " queries were made") - for i=1,#threads do - ngx.thread.wait(threads[i]) - end end) end) From 5f4d0c6b96029ef1d56f8fd10dc3c30719d46ed3 Mon Sep 17 00:00:00 2001 From: Andy Zhang Date: Mon, 27 May 2024 13:15:40 +0800 Subject: [PATCH 03/16] docs(changelog): apply changelog suggestions (#13086) Co-authored-by: Vinicius Mignot --- changelog/unreleased/kong/add-ai-data-report.yml | 2 +- .../unreleased/kong/add-messages-api-to-anthropic.yml | 2 +- changelog/unreleased/kong/add_tzdata.yml | 2 +- changelog/unreleased/kong/ai-proxy-client-params.yml | 6 +++--- changelog/unreleased/kong/ai-proxy-preserve-mode.yml | 6 +++--- changelog/unreleased/kong/analytics-for-anthropic.yml | 2 +- changelog/unreleased/kong/bump-lua-protobuf.yml | 2 +- changelog/unreleased/kong/bump-lua-resty-http-0.17.2.yml | 2 +- changelog/unreleased/kong/bump-ngx-wasm-module.yml | 2 +- changelog/unreleased/kong/bump-v8.yml | 2 +- changelog/unreleased/kong/bump-wasmtime.yml | 2 +- .../kong/decrease-cocurrency-limit-of-timer-ng.yml | 2 +- changelog/unreleased/kong/disable-TLSv1_1-in-openssl3.yml | 2 +- changelog/unreleased/kong/feat-ai-proxy-add-streaming.yml | 2 +- .../kong/feat-hybrid-sync-mixed-route-policy.yml | 8 ++++---- ...feat-increase-ai-anthropic-regex-expression-length.yml | 2 +- changelog/unreleased/kong/feat-wasm-general-shm-kv.yml | 2 +- changelog/unreleased/kong/fix-aws-lambda-kong-latency.yml | 2 +- changelog/unreleased/kong/fix-cjson-t-end.yml | 2 +- changelog/unreleased/kong/fix-ctx-host-port.yml | 4 ++-- .../unreleased/kong/fix-dbless-duplicate-target-error.yml | 2 +- ...x-default-value-of-upstream-keepalive-max-requests.yml | 4 ++-- .../unreleased/kong/fix-external-plugin-instance.yml | 2 +- .../unreleased/kong/fix-file-permission-of-logrotate.yml | 2 +- .../fix-hybrid-dp-certificate-with-vault-not-refresh.yml | 2 +- changelog/unreleased/kong/fix-jwt-plugin-check.yml | 2 +- .../fix-missing-router-section-of-request-debugging.yml | 2 +- .../unreleased/kong/fix-mlcache-renew-lock-leaks.yml | 2 +- changelog/unreleased/kong/fix-router-rebuing-flag.yml | 4 ++-- .../kong/fix-snis-tls-passthrough-in-trad-compat.yml | 4 ++-- changelog/unreleased/kong/fix-upstream-status-unset.yml | 2 +- changelog/unreleased/kong/fix-vault-init-worker.yml | 2 +- .../unreleased/kong/fix-wasm-disable-pwm-lua-resolver.yml | 2 +- .../flavor-expressions-supports-traditional-fields.yml | 6 +++--- changelog/unreleased/kong/key_auth_www_authenticate.yml | 2 +- .../unreleased/kong/log-serializer-receive-latency.yml | 2 +- .../kong/otel-increase-queue-max-batch-size.yml | 2 +- .../otel-sampling-panic-when-header-trace-id-enable.yml | 2 +- changelog/unreleased/kong/plugin_server_restart.yml | 2 +- changelog/unreleased/kong/propagation-module-rework.yml | 2 +- .../unreleased/kong/revert-req-body-limitation-patch.yml | 2 +- changelog/unreleased/kong/set_grpc_tls_seclevel.yml | 2 +- changelog/unreleased/kong/speed_up_router.yml | 2 +- changelog/unreleased/kong/update-ai-proxy-telemetry.yml | 2 +- changelog/unreleased/kong/wasm-bundled-filters.yml | 2 +- 45 files changed, 58 insertions(+), 58 deletions(-) diff --git a/changelog/unreleased/kong/add-ai-data-report.yml b/changelog/unreleased/kong/add-ai-data-report.yml index 1e074769daef..1119cd0073d4 100644 --- a/changelog/unreleased/kong/add-ai-data-report.yml +++ b/changelog/unreleased/kong/add-ai-data-report.yml @@ -1,3 +1,3 @@ -"message": Add `events:ai:response_tokens`, `events:ai:prompt_tokens` and `events:ai:requests` to the anonymous report to start counting AI usage +"message": Added `events:ai:response_tokens`, `events:ai:prompt_tokens` and `events:ai:requests` to the anonymous report to start counting AI usage "type": feature "scope": Core diff --git a/changelog/unreleased/kong/add-messages-api-to-anthropic.yml b/changelog/unreleased/kong/add-messages-api-to-anthropic.yml index 09513bff3848..538020199e37 100644 --- a/changelog/unreleased/kong/add-messages-api-to-anthropic.yml +++ b/changelog/unreleased/kong/add-messages-api-to-anthropic.yml @@ -1,5 +1,5 @@ "message": | - **AI-Proxy**: To support the new messages API of `Anthropic`, the upstream path of the `Anthropic` for `llm/v1/chat` route type is changed from `/v1/complete` to `/v1/messages` + **AI Proxy**: To support the new messages API of `Anthropic`, the upstream path of the `Anthropic` for `llm/v1/chat` route type has changed from `/v1/complete` to `/v1/messages`. "type": breaking_change "scope": Plugin "jiras": diff --git a/changelog/unreleased/kong/add_tzdata.yml b/changelog/unreleased/kong/add_tzdata.yml index 91c8df9c2ad0..bf635996c367 100644 --- a/changelog/unreleased/kong/add_tzdata.yml +++ b/changelog/unreleased/kong/add_tzdata.yml @@ -1,3 +1,3 @@ message: | - Add package `tzdata` to DEB Docker image for convenient timezone setting. + Added package `tzdata` to DEB Docker image for convenient timezone setting. type: dependency diff --git a/changelog/unreleased/kong/ai-proxy-client-params.yml b/changelog/unreleased/kong/ai-proxy-client-params.yml index 2d76256a190a..9b23aee2ba29 100644 --- a/changelog/unreleased/kong/ai-proxy-client-params.yml +++ b/changelog/unreleased/kong/ai-proxy-client-params.yml @@ -1,6 +1,6 @@ message: | - AI Proxy now reads most prompt tuning parameters from the client, whilst the - plugin config 'model options' are now just defaults. This fixes support for - using the respective provider's native SDK. + AI Proxy now reads most prompt tuning parameters from the client, + while the plugin config parameters under `model_options` are now just defaults. + This fixes support for using the respective provider's native SDK. type: feature scope: Plugin diff --git a/changelog/unreleased/kong/ai-proxy-preserve-mode.yml b/changelog/unreleased/kong/ai-proxy-preserve-mode.yml index ff7af94add2c..996783b3e4a5 100644 --- a/changelog/unreleased/kong/ai-proxy-preserve-mode.yml +++ b/changelog/unreleased/kong/ai-proxy-preserve-mode.yml @@ -1,6 +1,6 @@ message: | - AI Proxy now has a 'preserve' route_type option, where the requests and responses - are passed directly to the upstream LLM. This is to enable compatilibity with any - and all models and SDKs, that may be used when calling the AI services. + AI Proxy now has a `preserve` option for `route_type`, where the requests and responses + are passed directly to the upstream LLM. This is to enable compatibility with any + and all models and SDKs that may be used when calling the AI services. type: feature scope: Plugin diff --git a/changelog/unreleased/kong/analytics-for-anthropic.yml b/changelog/unreleased/kong/analytics-for-anthropic.yml index 04de991390df..b0f5b1734e9b 100644 --- a/changelog/unreleased/kong/analytics-for-anthropic.yml +++ b/changelog/unreleased/kong/analytics-for-anthropic.yml @@ -1,4 +1,4 @@ message: | - **AI-proxy-plugin**: Fix the bug that the route_type `/llm/v1/chat` does not include the analytics in the responses. + **AI-proxy-plugin**: Fixed the bug that the `route_type` `/llm/v1/chat` didn't include the analytics in the responses. scope: Plugin type: bugfix diff --git a/changelog/unreleased/kong/bump-lua-protobuf.yml b/changelog/unreleased/kong/bump-lua-protobuf.yml index 769747d7b9a8..5121fbe4a306 100644 --- a/changelog/unreleased/kong/bump-lua-protobuf.yml +++ b/changelog/unreleased/kong/bump-lua-protobuf.yml @@ -1,3 +1,3 @@ -message: "Bump lua-protobuf to 0.5.1" +message: "Bumped lua-protobuf to 0.5.1" type: dependency scope: Core diff --git a/changelog/unreleased/kong/bump-lua-resty-http-0.17.2.yml b/changelog/unreleased/kong/bump-lua-resty-http-0.17.2.yml index 584a721f1789..2f655eefc2d8 100644 --- a/changelog/unreleased/kong/bump-lua-resty-http-0.17.2.yml +++ b/changelog/unreleased/kong/bump-lua-resty-http-0.17.2.yml @@ -1,2 +1,2 @@ -message: Bump lua-resty-http to 0.17.2. +message: Bumped lua-resty-http to 0.17.2. type: dependency diff --git a/changelog/unreleased/kong/bump-ngx-wasm-module.yml b/changelog/unreleased/kong/bump-ngx-wasm-module.yml index cddaf5cf0e1d..4eee2f9c0f4c 100644 --- a/changelog/unreleased/kong/bump-ngx-wasm-module.yml +++ b/changelog/unreleased/kong/bump-ngx-wasm-module.yml @@ -1,2 +1,2 @@ -message: "Bump `ngx_wasm_module` to `91d447ffd0e9bb08f11cc69d1aa9128ec36b4526`" +message: "Bumped `ngx_wasm_module` to `91d447ffd0e9bb08f11cc69d1aa9128ec36b4526`" type: dependency diff --git a/changelog/unreleased/kong/bump-v8.yml b/changelog/unreleased/kong/bump-v8.yml index 299dc747ad57..963121a5ede6 100644 --- a/changelog/unreleased/kong/bump-v8.yml +++ b/changelog/unreleased/kong/bump-v8.yml @@ -1,2 +1,2 @@ -message: "Bump `V8` version to `12.0.267.17`" +message: "Bumped `V8` version to `12.0.267.17`" type: dependency diff --git a/changelog/unreleased/kong/bump-wasmtime.yml b/changelog/unreleased/kong/bump-wasmtime.yml index 7d5374c59823..4b48ea0e3c7a 100644 --- a/changelog/unreleased/kong/bump-wasmtime.yml +++ b/changelog/unreleased/kong/bump-wasmtime.yml @@ -1,2 +1,2 @@ -message: "Bump `Wasmtime` version to `19.0.0`" +message: "Bumped `Wasmtime` version to `19.0.0`" type: dependency diff --git a/changelog/unreleased/kong/decrease-cocurrency-limit-of-timer-ng.yml b/changelog/unreleased/kong/decrease-cocurrency-limit-of-timer-ng.yml index 4e62daeb58db..ca5dd937aea9 100644 --- a/changelog/unreleased/kong/decrease-cocurrency-limit-of-timer-ng.yml +++ b/changelog/unreleased/kong/decrease-cocurrency-limit-of-timer-ng.yml @@ -1,3 +1,3 @@ message: | - Fix a bug where the ulimit setting (open files) is low Kong will fail to start as the lua-resty-timer-ng exhausts the available worker_connections. Decrease the concurrency range of the lua-resty-timer-ng library from [512, 2048] to [256, 1024] to fix this bug. + Fixed a bug where, if the the ulimit setting (open files) was low, Kong would fail to start as the `lua-resty-timer-ng` exhausted the available `worker_connections`. Decreased the concurrency range of the `lua-resty-timer-ng` library from `[512, 2048]` to `[256, 1024]` to fix this bug. type: bugfix diff --git a/changelog/unreleased/kong/disable-TLSv1_1-in-openssl3.yml b/changelog/unreleased/kong/disable-TLSv1_1-in-openssl3.yml index aa9305e77316..4ae267860471 100644 --- a/changelog/unreleased/kong/disable-TLSv1_1-in-openssl3.yml +++ b/changelog/unreleased/kong/disable-TLSv1_1-in-openssl3.yml @@ -1,3 +1,3 @@ -message: now TLSv1.1 and lower is by default disabled in OpenSSL 3.x +message: TLSv1.1 and lower versions are disabled by default in OpenSSL 3.x. type: feature scope: Configuration diff --git a/changelog/unreleased/kong/feat-ai-proxy-add-streaming.yml b/changelog/unreleased/kong/feat-ai-proxy-add-streaming.yml index 4f4f348fefc1..860545117130 100644 --- a/changelog/unreleased/kong/feat-ai-proxy-add-streaming.yml +++ b/changelog/unreleased/kong/feat-ai-proxy-add-streaming.yml @@ -1,4 +1,4 @@ message: | - **AI-Proxy**: add support for streaming event-by-event responses back to client on supported providers + **AI Proxy**: Added support for streaming event-by-event responses back to the client on supported providers. scope: Plugin type: feature diff --git a/changelog/unreleased/kong/feat-hybrid-sync-mixed-route-policy.yml b/changelog/unreleased/kong/feat-hybrid-sync-mixed-route-policy.yml index 4d469c5e9790..874c8220b02f 100644 --- a/changelog/unreleased/kong/feat-hybrid-sync-mixed-route-policy.yml +++ b/changelog/unreleased/kong/feat-hybrid-sync-mixed-route-policy.yml @@ -1,7 +1,7 @@ message: | - When CP runs with `expressions` flavor: - - if mixed config is detected and a lower DP is attached to the CP, no config will be sent at all - - if the expression is invalid on CP, no config will be sent at all - - if the expression is invalid on lower DP, it will be sent to the DP and DP validation will catch this and communicate back to the CP (this could result in partial config application) + Improved config handling when the CP runs with the router set to the `expressions` flavor: + - If mixed config is detected and a lower DP is attached to the CP, no config will be sent at all + - If the expression is invalid on the CP, no config will be sent at all + - If the expression is invalid on a lower DP, it will be sent to the DP and DP validation will catch this and communicate back to the CP (this could result in partial config application) type: feature scope: Core diff --git a/changelog/unreleased/kong/feat-increase-ai-anthropic-regex-expression-length.yml b/changelog/unreleased/kong/feat-increase-ai-anthropic-regex-expression-length.yml index 9d7d15da0b00..83fb98320185 100644 --- a/changelog/unreleased/kong/feat-increase-ai-anthropic-regex-expression-length.yml +++ b/changelog/unreleased/kong/feat-increase-ai-anthropic-regex-expression-length.yml @@ -1,4 +1,4 @@ message: | - **AI-Prompt-Guard**: increase the maximum length of regex expression to 500 for both allow and deny parameter + **AI Prompt Guard**: Increased the maximum length of regex expressions to 500 for the allow and deny parameters. scope: Plugin type: feature diff --git a/changelog/unreleased/kong/feat-wasm-general-shm-kv.yml b/changelog/unreleased/kong/feat-wasm-general-shm-kv.yml index 0c8eef3c5ec9..1171dca85a2b 100644 --- a/changelog/unreleased/kong/feat-wasm-general-shm-kv.yml +++ b/changelog/unreleased/kong/feat-wasm-general-shm-kv.yml @@ -1,5 +1,5 @@ message: | - Introduce `nginx_wasm_main_shm_kv` configuration entry, which enables + Introduced `nginx_wasm_main_shm_kv` configuration parameter, which enables Wasm filters to use the Proxy-Wasm operations `get_shared_data` and `set_shared_data` without namespaced keys. type: feature diff --git a/changelog/unreleased/kong/fix-aws-lambda-kong-latency.yml b/changelog/unreleased/kong/fix-aws-lambda-kong-latency.yml index 04d5ab637096..3475c8347bc6 100644 --- a/changelog/unreleased/kong/fix-aws-lambda-kong-latency.yml +++ b/changelog/unreleased/kong/fix-aws-lambda-kong-latency.yml @@ -1,3 +1,3 @@ -message: "**AWS-Lambda**: fix an issue that the latency attributed to AWS Lambda API requests will be counted as part of the latency in Kong" +message: "**AWS-Lambda**: Fixed an issue where the latency attributed to AWS Lambda API requests was counted as part of the latency in Kong." type: bugfix scope: Plugin diff --git a/changelog/unreleased/kong/fix-cjson-t-end.yml b/changelog/unreleased/kong/fix-cjson-t-end.yml index 3977de7b12f0..251b176367cc 100644 --- a/changelog/unreleased/kong/fix-cjson-t-end.yml +++ b/changelog/unreleased/kong/fix-cjson-t-end.yml @@ -1,3 +1,3 @@ message: | - Improve the robustness of lua-cjson when handling unexpected input. + Improved the robustness of lua-cjson when handling unexpected input. type: dependency diff --git a/changelog/unreleased/kong/fix-ctx-host-port.yml b/changelog/unreleased/kong/fix-ctx-host-port.yml index a6faa8c5d8fd..467029fb6307 100644 --- a/changelog/unreleased/kong/fix-ctx-host-port.yml +++ b/changelog/unreleased/kong/fix-ctx-host-port.yml @@ -1,5 +1,5 @@ message: | - **PDK:** fix kong.request.get_forwarded_port to always return a number which was caused by an incorrectly - stored string value in ngx.ctx.host_port. + **PDK:** Fixed `kong.request.get_forwarded_port` to always return a number, + which was caused by an incorrectly stored string value in `ngx.ctx.host_port`. type: bugfix scope: PDK diff --git a/changelog/unreleased/kong/fix-dbless-duplicate-target-error.yml b/changelog/unreleased/kong/fix-dbless-duplicate-target-error.yml index 082e5dd52180..1c13d09c7636 100644 --- a/changelog/unreleased/kong/fix-dbless-duplicate-target-error.yml +++ b/changelog/unreleased/kong/fix-dbless-duplicate-target-error.yml @@ -1,3 +1,3 @@ -message: "Fixed an issue wherein `POST /config?flatten_errors=1` could not return a proper response if the input included duplicate upstream targets" +message: "Fixed an issue where `POST /config?flatten_errors=1` could not return a proper response if the input included duplicate upstream targets." type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-default-value-of-upstream-keepalive-max-requests.yml b/changelog/unreleased/kong/fix-default-value-of-upstream-keepalive-max-requests.yml index 45eedd995d64..2628170265da 100644 --- a/changelog/unreleased/kong/fix-default-value-of-upstream-keepalive-max-requests.yml +++ b/changelog/unreleased/kong/fix-default-value-of-upstream-keepalive-max-requests.yml @@ -1,5 +1,5 @@ message: | - Fixed default value in kong.conf.default documentation from 1000 to 10000 - for upstream_keepalive_max_requests option. + Fixed the default value in kong.conf.default documentation from 1000 to 10000 + for the `upstream_keepalive_max_requests` option. type: bugfix scope: Configuration diff --git a/changelog/unreleased/kong/fix-external-plugin-instance.yml b/changelog/unreleased/kong/fix-external-plugin-instance.yml index b92665f2d9be..6d3973bdbe27 100644 --- a/changelog/unreleased/kong/fix-external-plugin-instance.yml +++ b/changelog/unreleased/kong/fix-external-plugin-instance.yml @@ -1,5 +1,5 @@ message: | - Fix an issue where an external plugin (Go, Javascript, or Python) would fail to + Fixed an issue where an external plugin (Go, Javascript, or Python) would fail to apply a change to the plugin config via the Admin API. type: bugfix scope: Configuration diff --git a/changelog/unreleased/kong/fix-file-permission-of-logrotate.yml b/changelog/unreleased/kong/fix-file-permission-of-logrotate.yml index 2fb24c9e2f54..45452f2e5fdc 100644 --- a/changelog/unreleased/kong/fix-file-permission-of-logrotate.yml +++ b/changelog/unreleased/kong/fix-file-permission-of-logrotate.yml @@ -1,3 +1,3 @@ -message: update file permission of kong.logrotate to 644 +message: Updated the file permission of `kong.logrotate` to 644. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-hybrid-dp-certificate-with-vault-not-refresh.yml b/changelog/unreleased/kong/fix-hybrid-dp-certificate-with-vault-not-refresh.yml index 12f89fee2eca..17ef367fba9b 100644 --- a/changelog/unreleased/kong/fix-hybrid-dp-certificate-with-vault-not-refresh.yml +++ b/changelog/unreleased/kong/fix-hybrid-dp-certificate-with-vault-not-refresh.yml @@ -1,3 +1,3 @@ -message: Fixed a problem that in hybrid DP mode a certificate entity configured with vault reference may not get refreshed on time +message: Fixed a problem on hybrid mode DPs, where a certificate entity configured with a vault reference may not get refreshed on time. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-jwt-plugin-check.yml b/changelog/unreleased/kong/fix-jwt-plugin-check.yml index bbf3ed71b848..fa58f7b7d042 100644 --- a/changelog/unreleased/kong/fix-jwt-plugin-check.yml +++ b/changelog/unreleased/kong/fix-jwt-plugin-check.yml @@ -1,3 +1,3 @@ -message: "**Jwt**: fix an issue where the plugin would fail when using invalid public keys for ES384 and ES512 algorithms." +message: "**Jwt**: Fixed an issue where the plugin would fail when using invalid public keys for ES384 and ES512 algorithms." type: bugfix scope: Plugin diff --git a/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml b/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml index 7ae106f21bb3..b1fe73fced0c 100644 --- a/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml +++ b/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml @@ -1,3 +1,3 @@ -message: Fix the missing router section for the output of the request-debugging +message: Fixed the missing router section for the output of the request-debugging. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-mlcache-renew-lock-leaks.yml b/changelog/unreleased/kong/fix-mlcache-renew-lock-leaks.yml index d81d08171c70..06041d1b1154 100644 --- a/changelog/unreleased/kong/fix-mlcache-renew-lock-leaks.yml +++ b/changelog/unreleased/kong/fix-mlcache-renew-lock-leaks.yml @@ -1,4 +1,4 @@ message: | - Fixed an issue that leaking locks in the internal caching logic + Fixed an issue in the internal caching logic where mutexes could get never unlocked. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-router-rebuing-flag.yml b/changelog/unreleased/kong/fix-router-rebuing-flag.yml index 62740912f3c0..e13bd1c16e9b 100644 --- a/changelog/unreleased/kong/fix-router-rebuing-flag.yml +++ b/changelog/unreleased/kong/fix-router-rebuing-flag.yml @@ -1,5 +1,5 @@ message: | - Fixed an issue where router may not work correctly - when the routes configuration changed. + Fixed an issue where the router didn't work correctly + when the route's configuration changed. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-snis-tls-passthrough-in-trad-compat.yml b/changelog/unreleased/kong/fix-snis-tls-passthrough-in-trad-compat.yml index ab00e318f639..d806836e14ce 100644 --- a/changelog/unreleased/kong/fix-snis-tls-passthrough-in-trad-compat.yml +++ b/changelog/unreleased/kong/fix-snis-tls-passthrough-in-trad-compat.yml @@ -1,5 +1,5 @@ message: | - Fixed an issue where SNI-based routing does not work - using tls_passthrough and the traditional_compatible router flavor + Fixed an issue where SNI-based routing didn't work + using `tls_passthrough` and the `traditional_compatible` router flavor. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-upstream-status-unset.yml b/changelog/unreleased/kong/fix-upstream-status-unset.yml index eefb1e02bcf4..96fc0c1ee6d3 100644 --- a/changelog/unreleased/kong/fix-upstream-status-unset.yml +++ b/changelog/unreleased/kong/fix-upstream-status-unset.yml @@ -1,3 +1,3 @@ -message: fix a bug that `X-Kong-Upstream-Status` will not appear in the response headers even if it is set in the `headers` parameter in the kong.conf when the response is hit and returned by proxy cache plugin. +message: Fixed a bug that `X-Kong-Upstream-Status` didn't appear in the response headers even if it was set in the `headers` parameter in the `kong.conf` file when the response was hit and returned by the Proxy Cache plugin. scope: Core type: bugfix diff --git a/changelog/unreleased/kong/fix-vault-init-worker.yml b/changelog/unreleased/kong/fix-vault-init-worker.yml index d5315d0d7c28..e43ebfd529e3 100644 --- a/changelog/unreleased/kong/fix-vault-init-worker.yml +++ b/changelog/unreleased/kong/fix-vault-init-worker.yml @@ -1,3 +1,3 @@ -message: fix vault initialization by postponing vault reference resolving on init_worker +message: Fixed vault initialization by postponing vault reference resolving on init_worker type: bugfix scope: Core diff --git a/changelog/unreleased/kong/fix-wasm-disable-pwm-lua-resolver.yml b/changelog/unreleased/kong/fix-wasm-disable-pwm-lua-resolver.yml index f8c49499ee91..e7113efc506b 100644 --- a/changelog/unreleased/kong/fix-wasm-disable-pwm-lua-resolver.yml +++ b/changelog/unreleased/kong/fix-wasm-disable-pwm-lua-resolver.yml @@ -1,4 +1,4 @@ message: | - Disable usage of the Lua DNS resolver from proxy-wasm by default. + Disabled usage of the Lua DNS resolver from proxy-wasm by default. type: bugfix scope: Configuration diff --git a/changelog/unreleased/kong/flavor-expressions-supports-traditional-fields.yml b/changelog/unreleased/kong/flavor-expressions-supports-traditional-fields.yml index e6169297461e..13a86d486fec 100644 --- a/changelog/unreleased/kong/flavor-expressions-supports-traditional-fields.yml +++ b/changelog/unreleased/kong/flavor-expressions-supports-traditional-fields.yml @@ -1,7 +1,7 @@ message: | - Supported fields `methods`, `hosts`, `paths`, `headers`, - `snis`, `sources`, `destinations` and `regex_priority` - for the `route` entity when the `router_flavor` is `expressions`. + The route entity now supports the following fields when the + `router_flavor` is `expressions`: `methods`, `hosts`, `paths`, `headers`, + `snis`, `sources`, `destinations`, and `regex_priority`. The meaning of these fields are consistent with the traditional route entity. type: feature scope: Core diff --git a/changelog/unreleased/kong/key_auth_www_authenticate.yml b/changelog/unreleased/kong/key_auth_www_authenticate.yml index 3d1e12b085d7..c9d8fbb8f6fa 100644 --- a/changelog/unreleased/kong/key_auth_www_authenticate.yml +++ b/changelog/unreleased/kong/key_auth_www_authenticate.yml @@ -1,3 +1,3 @@ -message: Add WWW-Authenticate headers to all 401 response in key auth plugin. +message: Added WWW-Authenticate headers to all 401 responses in the Key Auth plugin. type: bugfix scope: Plugin diff --git a/changelog/unreleased/kong/log-serializer-receive-latency.yml b/changelog/unreleased/kong/log-serializer-receive-latency.yml index 75aaae7a75df..a032cd3a52d8 100644 --- a/changelog/unreleased/kong/log-serializer-receive-latency.yml +++ b/changelog/unreleased/kong/log-serializer-receive-latency.yml @@ -1,3 +1,3 @@ -message: 'Add `latencies.receive` property to log serializer' +message: 'Added the `latencies.receive` property to the log serializer' type: feature scope: PDK diff --git a/changelog/unreleased/kong/otel-increase-queue-max-batch-size.yml b/changelog/unreleased/kong/otel-increase-queue-max-batch-size.yml index 6936adcf7615..b6fec110784d 100644 --- a/changelog/unreleased/kong/otel-increase-queue-max-batch-size.yml +++ b/changelog/unreleased/kong/otel-increase-queue-max-batch-size.yml @@ -1,3 +1,3 @@ -message: "**Opentelemetry**: increase queue max batch size to 200" +message: "**Opentelemetry**: Increased queue max batch size to 200." type: performance scope: Plugin diff --git a/changelog/unreleased/kong/otel-sampling-panic-when-header-trace-id-enable.yml b/changelog/unreleased/kong/otel-sampling-panic-when-header-trace-id-enable.yml index 5efdededa3b4..5354c83e9f7f 100644 --- a/changelog/unreleased/kong/otel-sampling-panic-when-header-trace-id-enable.yml +++ b/changelog/unreleased/kong/otel-sampling-panic-when-header-trace-id-enable.yml @@ -1,3 +1,3 @@ -message: "**Opentelemetry**: fix otel sampling mode lua panic bug when http_response_header_for_traceid option enable" +message: "**Opentelemetry**: Fixed an OTEL sampling mode Lua panic bug, which happened when the `http_response_header_for_traceid` option was enabled." type: bugfix scope: Plugin diff --git a/changelog/unreleased/kong/plugin_server_restart.yml b/changelog/unreleased/kong/plugin_server_restart.yml index ed46b92bb16e..7e368b05c81c 100644 --- a/changelog/unreleased/kong/plugin_server_restart.yml +++ b/changelog/unreleased/kong/plugin_server_restart.yml @@ -1,3 +1,3 @@ -message: "**Plugin Server**: fix an issue where Kong fails to properly restart MessagePack-based pluginservers (used in Python and Javascript plugins, for example)" +message: "**Plugin Server**: Fixed an issue where Kong failed to properly restart MessagePack-based pluginservers (used in Python and Javascript plugins, for example)." type: bugfix scope: Core diff --git a/changelog/unreleased/kong/propagation-module-rework.yml b/changelog/unreleased/kong/propagation-module-rework.yml index 69f3dcb76752..249954c4a762 100644 --- a/changelog/unreleased/kong/propagation-module-rework.yml +++ b/changelog/unreleased/kong/propagation-module-rework.yml @@ -1,5 +1,5 @@ message: | - **OpenTelemetry, Zipkin**: the propagation module has been reworked, new + **OpenTelemetry, Zipkin**: The propagation module has been reworked. The new options allow better control over the configuration of tracing headers propagation. type: feature scope: Plugin diff --git a/changelog/unreleased/kong/revert-req-body-limitation-patch.yml b/changelog/unreleased/kong/revert-req-body-limitation-patch.yml index 55da8ff91977..4eb1d36f69f5 100644 --- a/changelog/unreleased/kong/revert-req-body-limitation-patch.yml +++ b/changelog/unreleased/kong/revert-req-body-limitation-patch.yml @@ -1,3 +1,3 @@ -message: revert the hard-coded limitation of the ngx.read_body() API in OpenResty upstreams' new versions when downstream connections are in HTTP/2 or HTTP/3 stream modes. +message: Reverted the hard-coded limitation of the `ngx.read_body()` API in OpenResty upstreams' new versions when downstream connections are in HTTP/2 or HTTP/3 stream modes. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/set_grpc_tls_seclevel.yml b/changelog/unreleased/kong/set_grpc_tls_seclevel.yml index 02d068713e9f..a6b749e5b8dc 100644 --- a/changelog/unreleased/kong/set_grpc_tls_seclevel.yml +++ b/changelog/unreleased/kong/set_grpc_tls_seclevel.yml @@ -1,3 +1,3 @@ -message: Set security level of gRPC's TLS to 0 when ssl_cipher_suite is set to old +message: Set security level of gRPC's TLS to 0 when `ssl_cipher_suite` is set to `old`. type: bugfix scope: Configuration diff --git a/changelog/unreleased/kong/speed_up_router.yml b/changelog/unreleased/kong/speed_up_router.yml index c7e92efbe83c..5bafe74c293e 100644 --- a/changelog/unreleased/kong/speed_up_router.yml +++ b/changelog/unreleased/kong/speed_up_router.yml @@ -1,3 +1,3 @@ -message: Speeded up the router matching when the `router_flavor` is `traditional_compatible` or `expressions`. +message: Sped up the router matching when the `router_flavor` is `traditional_compatible` or `expressions`. type: performance scope: Performance diff --git a/changelog/unreleased/kong/update-ai-proxy-telemetry.yml b/changelog/unreleased/kong/update-ai-proxy-telemetry.yml index fcb68b218de6..d07e42b2fb18 100644 --- a/changelog/unreleased/kong/update-ai-proxy-telemetry.yml +++ b/changelog/unreleased/kong/update-ai-proxy-telemetry.yml @@ -1,3 +1,3 @@ -message: Update telemetry collection for AI Plugins to allow multiple plugins data to be set for the same request. +message: Updated telemetry collection for AI Plugins to allow multiple plugins data to be set for the same request. type: bugfix scope: Core diff --git a/changelog/unreleased/kong/wasm-bundled-filters.yml b/changelog/unreleased/kong/wasm-bundled-filters.yml index 836140270440..e826d6dcf6ee 100644 --- a/changelog/unreleased/kong/wasm-bundled-filters.yml +++ b/changelog/unreleased/kong/wasm-bundled-filters.yml @@ -1,3 +1,3 @@ -message: Add `wasm_filters` configuration value for enabling individual filters +message: Added the `wasm_filters` configuration parameter for enabling individual filters type: feature scope: Configuration From 1d1056e3d9ed0d6c51bc59695a12a3faf7b3fc6d Mon Sep 17 00:00:00 2001 From: hulk Date: Mon, 27 May 2024 15:44:13 +0800 Subject: [PATCH 04/16] fix(router/atc): URI captures are unavailable when the first capture group is absent (#13024) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/Kong/kong/issues/13014, https://konghq.atlassian.net/browse/KAG-4474 Co-authored-by: Xumin <100666470+StarlightIbuki@users.noreply.github.com> Co-authored-by: Chrono Co-authored-by: MikoĊ‚aj Nowak Co-authored-by: xumin --- .../fix-request-transformer-uri-replace.yml | 4 ++ kong/router/atc.lua | 16 ++++++- spec/01-unit/08-router_spec.lua | 20 +++++++++ .../36-request-transformer/02-access_spec.lua | 42 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/kong/fix-request-transformer-uri-replace.yml diff --git a/changelog/unreleased/kong/fix-request-transformer-uri-replace.yml b/changelog/unreleased/kong/fix-request-transformer-uri-replace.yml new file mode 100644 index 000000000000..02c55a15f70b --- /dev/null +++ b/changelog/unreleased/kong/fix-request-transformer-uri-replace.yml @@ -0,0 +1,4 @@ +message: | + Fixed an issue where the URI captures are unavailable when the first capture group is absent. +type: bugfix +scope: Core diff --git a/kong/router/atc.lua b/kong/router/atc.lua index c41af0da0bde..31aaf6c5a4ed 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -15,6 +15,7 @@ local assert = assert local setmetatable = setmetatable local pairs = pairs local ipairs = ipairs +local next = next local max = math.max @@ -344,6 +345,19 @@ local function set_upstream_uri(req_uri, match_t) end +-- captures has the form { [0] = full_path, [1] = capture1, [2] = capture2, ..., ["named1"] = named1, ... } +-- and captures[0] will be the full matched path +-- this function tests if there are captures other than the full path +-- by checking if there are 2 or more than 2 keys +local function has_capture(captures) + if not captures then + return false + end + local next_i = next(captures) + return next_i and next(captures, next_i) ~= nil +end + + function _M:matching(params) local req_uri = params.uri local req_host = params.host @@ -387,7 +401,7 @@ function _M:matching(params) service = service, prefix = request_prefix, matches = { - uri_captures = (captures and captures[1]) and captures or nil, + uri_captures = has_capture(captures) and captures or nil, }, upstream_url_t = { type = service_hostname_type, diff --git a/spec/01-unit/08-router_spec.lua b/spec/01-unit/08-router_spec.lua index 046cb25bd8b0..025120392ecf 100644 --- a/spec/01-unit/08-router_spec.lua +++ b/spec/01-unit/08-router_spec.lua @@ -3484,6 +3484,26 @@ for _, flavor in ipairs({ "traditional", "traditional_compatible", "expressions" assert.is_nil(match_t.matches.headers) end) + it("uri_captures works well with the optional capture group. Fix #13014", function() + local use_case = { + { + service = service, + route = { + id = "e8fb37f1-102d-461e-9c51-6608a6bb8101", + paths = { [[~/(users/)?1984/(?profile)$]] }, + }, + }, + } + + local router = assert(new_router(use_case)) + local _ngx = mock_ngx("GET", "/1984/profile", { host = "domain.org" }) + router._set_ngx(_ngx) + local match_t = router:exec() + assert.falsy(match_t.matches.uri_captures[1]) + assert.equal("profile", match_t.matches.uri_captures.subpath) + assert.is_nil(match_t.matches.uri_captures.scope) + end) + it("returns uri_captures from a [uri regex]", function() local use_case = { { diff --git a/spec/03-plugins/36-request-transformer/02-access_spec.lua b/spec/03-plugins/36-request-transformer/02-access_spec.lua index bf3de4192826..aeffa72c7f45 100644 --- a/spec/03-plugins/36-request-transformer/02-access_spec.lua +++ b/spec/03-plugins/36-request-transformer/02-access_spec.lua @@ -131,6 +131,12 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() hosts = { "test28.test" } }) + local route29 = bp.routes:insert({ + hosts = { "test29.test" }, + paths = { "~/(gw/)?api/(?htest)$" }, + strip_path = false, + }) + bp.plugins:insert { route = { id = route1.id }, name = "request-transformer", @@ -471,6 +477,16 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() } } + bp.plugins:insert { + route = { id = route29.id }, + name = "request-transformer", + config = { + replace = { + uri = "/api/v2/$(uri_captures[\"subpath\"])", + } + } + } + assert(helpers.start_kong({ database = strategy, plugins = "bundled, request-transformer", @@ -1114,6 +1130,32 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() assert.is_truthy(string.find(json.data, "\"emptyarray\":[]", 1, true)) end) + it("replaces request uri with optional capture prefix", function() + local r = assert(client:send { + method = "GET", + path = "/api/htest", + headers = { + host = "test29.test" + } + }) + assert.response(r).has.status(404) + local body = assert(assert.response(r).has.jsonbody()) + assert.equals("/api/v2/htest", body.vars.request_uri) + end) + + it("replaces request uri with the capature prefix", function() + local r = assert(client:send { + method = "GET", + path = "/gw/api/htest", + headers = { + host = "test29.test" + } + }) + assert.response(r).has.status(404) + local body = assert(assert.response(r).has.jsonbody()) + assert.equals("/api/v2/htest", body.vars.request_uri) + end) + pending("escape UTF-8 characters when replacing upstream path - enable after Kong 2.4", function() local r = assert(client:send { method = "GET", From 80b02ec6b06fecca879e2af6de12a4e53f09e351 Mon Sep 17 00:00:00 2001 From: Chrono Date: Mon, 27 May 2024 16:40:48 +0800 Subject: [PATCH 05/16] refactor(admin_gui): break the loop early and minor style clean (#13079) --- kong/admin_gui/utils.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kong/admin_gui/utils.lua b/kong/admin_gui/utils.lua index fdd2f31943cb..3567f1652fcf 100644 --- a/kong/admin_gui/utils.lua +++ b/kong/admin_gui/utils.lua @@ -1,20 +1,25 @@ local _M = {} + -- return first listener matching filters function _M.select_listener(listeners, filters) for _, listener in ipairs(listeners) do local match = true + for filter, value in pairs(filters) do if listener[filter] ~= value then match = false + break end end + if match then return listener end end end + function _M.prepare_variable(variable) if variable == nil then return "" @@ -23,4 +28,5 @@ function _M.prepare_variable(variable) return tostring(variable) end + return _M From 73fa4a68f96b14ebcd0985905ab47497b32a0422 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:09:55 +0800 Subject: [PATCH 06/16] style(dynamic_hook): remove trailing spaces --- kong/dynamic_hook/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index d5cd940b0f13..5fa6a2acd09a 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -37,7 +37,7 @@ local function should_execute_original_func(group_name) if ALWAYS_ENABLED_GROUPS[group_name] then return end - + local phase = ngx_get_phase() if phase == "init" or phase == "init_worker" then return true @@ -58,7 +58,7 @@ end local function execute_hook_vararg(hook, hook_type, group_name, ...) if not hook then return - end + end local ok, err = pcall(hook, ...) if not ok then ngx_log(ngx_WARN, "failed to run ", hook_type, " hook of ", group_name, ": ", err) @@ -132,7 +132,7 @@ local function execute_original_func(max_args, original_func, a1, a2, a3, a4, a5 return original_func(a1, a2, a3, a4, a5, a6) elseif max_args == 7 then return original_func(a1, a2, a3, a4, a5, a6, a7) - else + else return original_func(a1, a2, a3, a4, a5, a6, a7, a8) end end @@ -142,7 +142,7 @@ local function wrap_function(max_args, group_name, original_func, handlers) return function(a1, a2, a3, a4, a5, a6, a7, a8) if should_execute_original_func(group_name) then a1, a2, a3, a4, a5, a6, a7, a8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) - + else execute_hook(handlers.before_mut, "before_mut", group_name, a1, a2, a3, a4, a5, a6, a7, a8) execute_hooks(handlers.befores, "before", group_name, a1, a2, a3, a4, a5, a6, a7, a8) From 9069d40f3c3c1c6c5edce4ae24d3575993c1378f Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:11:43 +0800 Subject: [PATCH 07/16] style(dynamic_hook): align assignment statements --- kong/dynamic_hook/init.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index 5fa6a2acd09a..d013c78e7849 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -1,20 +1,20 @@ -local ngx = ngx -local type = type -local pcall = pcall -local select = select -local ipairs = ipairs -local assert = assert -local ngx_log = ngx.log -local ngx_WARN = ngx.WARN +local ngx = ngx +local type = type +local pcall = pcall +local select = select +local ipairs = ipairs +local assert = assert +local ngx_log = ngx.log +local ngx_WARN = ngx.WARN local ngx_get_phase = ngx.get_phase local _M = { TYPE = { - BEFORE = 1, - AFTER = 2, - BEFORE_MUT = 3, - AFTER_MUT = 4, + BEFORE = 1, + AFTER = 2, + BEFORE_MUT = 3, + AFTER_MUT = 4, }, } From 78b3118e00773a7fc19b439ca1608c6889f3a6a9 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:22:05 +0800 Subject: [PATCH 08/16] style(dynamic_hook): add blank lines --- kong/dynamic_hook/init.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index d013c78e7849..24ca843c8089 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -59,6 +59,7 @@ local function execute_hook_vararg(hook, hook_type, group_name, ...) if not hook then return end + local ok, err = pcall(hook, ...) if not ok then ngx_log(ngx_WARN, "failed to run ", hook_type, " hook of ", group_name, ": ", err) @@ -70,6 +71,7 @@ local function execute_hooks_vararg(hooks, hook_type, group_name, ...) if not hooks then return end + for _, hook in ipairs(hooks) do execute_hook_vararg(hook, hook_type, group_name, ...) end @@ -88,6 +90,7 @@ local function wrap_function_vararg(group_name, original_func, handlers) if should_execute_original_func(group_name) then return original_func(...) end + execute_hooks_vararg(handlers.befores, "before", group_name, ...) return execute_after_hooks_vararg(handlers, group_name, original_func(...)) end @@ -98,6 +101,7 @@ local function execute_hook(hook, hook_type, group_name, a1, a2, a3, a4, a5, a6, if not hook then return end + local ok, err = pcall(hook, a1, a2, a3, a4, a5, a6, a7, a8) if not ok then ngx_log(ngx_WARN, "failed to run ", hook_type, " hook of ", group_name, ": ", err) @@ -109,6 +113,7 @@ local function execute_hooks(hooks, hook_type, group_name, a1, a2, a3, a4, a5, a if not hooks then return end + for _, hook in ipairs(hooks) do execute_hook(hook, hook_type, group_name, a1, a2, a3, a4, a5, a6, a7, a8) end @@ -150,6 +155,7 @@ local function wrap_function(max_args, group_name, original_func, handlers) execute_hook(handlers.after_mut, "after_mut", group_name, a1, a2, a3, a4, a5, a6, a7, a8) execute_hooks(handlers.afters, "after", group_name, a1, a2, a3, a4, a5, a6, a7, a8) end + return a1, a2, a3, a4, a5, a6, a7, a8 end end @@ -234,6 +240,7 @@ function _M.run_hooks(group_name, hook_name, a1, a2, a3, a4, a5, a6, a7, a8, ... else ok, err = pcall(handler, a1, a2, a3, a4, a5, a6, a7, a8, ...) end + if not ok then ngx_log(ngx_WARN, "failed to run dynamic hook ", group_name, ".", hook_name, ": ", err) end From 5fffa06005401fe150d42a5b672aeea3e9140df3 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:26:29 +0800 Subject: [PATCH 09/16] feat(dynamic_hook): remove hooks types `before_mut` and `after_mut` We haven't used this feature until now, so I removed them to simplify the code logic. --- kong/dynamic_hook/init.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index 24ca843c8089..83ae7faf1469 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -13,8 +13,6 @@ local _M = { TYPE = { BEFORE = 1, AFTER = 2, - BEFORE_MUT = 3, - AFTER_MUT = 4, }, } @@ -79,7 +77,6 @@ end local function execute_after_hooks_vararg(handlers, group_name, ...) - execute_hook_vararg(handlers.after_mut, "after_mut", group_name, ...) execute_hooks_vararg(handlers.afters, "after", group_name, ...) return ... end @@ -149,10 +146,8 @@ local function wrap_function(max_args, group_name, original_func, handlers) a1, a2, a3, a4, a5, a6, a7, a8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) else - execute_hook(handlers.before_mut, "before_mut", group_name, a1, a2, a3, a4, a5, a6, a7, a8) execute_hooks(handlers.befores, "before", group_name, a1, a2, a3, a4, a5, a6, a7, a8) a1, a2, a3, a4, a5, a6, a7, a8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) - execute_hook(handlers.after_mut, "after_mut", group_name, a1, a2, a3, a4, a5, a6, a7, a8) execute_hooks(handlers.afters, "after", group_name, a1, a2, a3, a4, a5, a6, a7, a8) end @@ -166,9 +161,7 @@ function _M.hook_function(group_name, parent, child_key, max_args, handlers) assert(type(child_key) == "string", "child_key must be a string") local is_varargs = max_args == "varargs" - if is_varargs then - assert(handlers.before_mut == nil, "before_mut is not supported for varargs functions") - else + if not is_varargs then assert(type(max_args) == "number", 'max_args must be a number or "varargs"') assert(max_args >= 0 and max_args <= 8, 'max_args must be >= 0 and <= 8, or "varargs"') end From 5dc9c6fd8012ad147a9ac5b25ad5e5379ace6263 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:30:15 +0800 Subject: [PATCH 10/16] fix(dynamic_hook): fix incorrect return values of hooked functions --- kong/dynamic_hook/init.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index 83ae7faf1469..e9b7081da74a 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -142,16 +142,18 @@ end local function wrap_function(max_args, group_name, original_func, handlers) return function(a1, a2, a3, a4, a5, a6, a7, a8) + local r1, r2, r3, r4, r5, r6, r7, r8 + if should_execute_original_func(group_name) then - a1, a2, a3, a4, a5, a6, a7, a8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) + r1, r2, r3, r4, r5, r6, r7, r8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) else execute_hooks(handlers.befores, "before", group_name, a1, a2, a3, a4, a5, a6, a7, a8) - a1, a2, a3, a4, a5, a6, a7, a8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) - execute_hooks(handlers.afters, "after", group_name, a1, a2, a3, a4, a5, a6, a7, a8) + r1, r2, r3, r4, r5, r6, r7, r8 = execute_original_func(max_args, original_func, a1, a2, a3, a4, a5, a6, a7, a8) + execute_hooks(handlers.afters, "after", group_name, r1, r2, r3, r4, r5, r6, r7, r8) end - return a1, a2, a3, a4, a5, a6, a7, a8 + return r1, r2, r3, r4, r5, r6, r7, r8 end end From 01e6b7ee20035a5c3c46bf7627851325cb84fb95 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:35:17 +0800 Subject: [PATCH 11/16] refactor(dynamic_hook): introduce more assertions for robustness --- kong/dynamic_hook/init.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index e9b7081da74a..d8041e3def8c 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -159,6 +159,7 @@ end function _M.hook_function(group_name, parent, child_key, max_args, handlers) + assert(type(group_name) == "string", "group_name must be a string") assert(type(parent) == "table", "parent must be a table") assert(type(child_key) == "string", "child_key must be a string") @@ -195,6 +196,8 @@ end function _M.is_group_enabled(group_name) + assert(type(group_name) == "string", "group_name must be a string") + if ALWAYS_ENABLED_GROUPS[group_name] then return true end @@ -214,6 +217,9 @@ end function _M.run_hooks(group_name, hook_name, a1, a2, a3, a4, a5, a6, a7, a8, ...) + assert(type(group_name) == "string", "group_name must be a string") + assert(type(hook_name) == "string", "hook_name must be a string") + if not _M.is_group_enabled(group_name) then return end @@ -243,6 +249,8 @@ end function _M.enable_on_this_request(group_name, ngx_ctx) + assert(type(group_name) == "string", "group_name must be a string") + ngx_ctx = ngx_ctx or ngx.ctx if ngx_ctx.dynamic_hook then ngx_ctx.dynamic_hook.enabled_groups[group_name] = true @@ -257,6 +265,8 @@ end function _M.always_enable(group_name) + assert(type(group_name) == "string", "group_name must be a string") + ALWAYS_ENABLED_GROUPS[group_name] = true end From ba73506d6b97562c386600c2edac5c0854d1d9a4 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 11:48:13 +0800 Subject: [PATCH 12/16] style(dynamic_code): remove unused code --- kong/dynamic_hook/init.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index d8041e3def8c..cc5ab4683c9d 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -9,12 +9,7 @@ local ngx_WARN = ngx.WARN local ngx_get_phase = ngx.get_phase -local _M = { - TYPE = { - BEFORE = 1, - AFTER = 2, - }, -} +local _M = {} local NON_FUNCTION_HOOKS = { From 9b8c63f099ac5316e49f61af91b65dc89d5e5b80 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 14:54:42 +0800 Subject: [PATCH 13/16] style(dynamic_hook): rename `run_hooks` to `run_hook` as it only run a single hook --- kong/dynamic_hook/init.lua | 2 +- kong/init.lua | 72 +++++++++++++++++++------------------- kong/resty/dns/client.lua | 4 +-- kong/runloop/handler.lua | 8 ++--- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index cc5ab4683c9d..76826226eb76 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -211,7 +211,7 @@ function _M.is_group_enabled(group_name) end -function _M.run_hooks(group_name, hook_name, a1, a2, a3, a4, a5, a6, a7, a8, ...) +function _M.run_hook(group_name, hook_name, a1, a2, a3, a4, a5, a6, a7, a8, ...) assert(type(group_name) == "string", "group_name must be a string") assert(type(hook_name) == "string", "hook_name must be a string") diff --git a/kong/init.lua b/kong/init.lua index 0a16660a1962..225d6683174c 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -135,7 +135,7 @@ local get_start_time_ms = utils.get_start_time_ms local get_updated_now_ms = utils.get_updated_now_ms -local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks +local req_dyn_hook_run_hook = req_dyn_hook.run_hook local req_dyn_hook_is_group_enabled = req_dyn_hook.is_group_enabled @@ -326,7 +326,7 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx) local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:plugin_iterator") + req_dyn_hook_run_hook("timing", "before:plugin_iterator") end for _, plugin, configuration in iterator, plugins, 0 do @@ -338,13 +338,13 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx) setup_plugin_context(ctx, plugin, configuration) if has_timing then - req_dyn_hook_run_hooks("timing", "before:plugin", plugin.name, ctx.plugin_id) + req_dyn_hook_run_hook("timing", "before:plugin", plugin.name, ctx.plugin_id) end plugin.handler[phase](plugin.handler, configuration) if has_timing then - req_dyn_hook_run_hooks("timing", "after:plugin") + req_dyn_hook_run_hook("timing", "after:plugin") end reset_plugin_context(ctx, old_ws) @@ -355,7 +355,7 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx) end if has_timing then - req_dyn_hook_run_hooks("timing", "after:plugin_iterator") + req_dyn_hook_run_hook("timing", "after:plugin_iterator") end end @@ -376,7 +376,7 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx) local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:plugin_iterator") + req_dyn_hook_run_hook("timing", "before:plugin_iterator") end for _, plugin, configuration in iterator, plugins, 0 do @@ -389,14 +389,14 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx) setup_plugin_context(ctx, plugin, configuration) if has_timing then - req_dyn_hook_run_hooks( "timing", "before:plugin", plugin.name, ctx.plugin_id) + req_dyn_hook_run_hook( "timing", "before:plugin", plugin.name, ctx.plugin_id) end local co = coroutine.create(plugin.handler[phase]) local cok, cerr = coroutine.resume(co, plugin.handler, configuration) if has_timing then - req_dyn_hook_run_hooks("timing", "after:plugin") + req_dyn_hook_run_hook("timing", "after:plugin") end if not cok then @@ -426,7 +426,7 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx) end if has_timing then - req_dyn_hook_run_hooks("timing", "after:plugin_iterator") + req_dyn_hook_run_hook("timing", "after:plugin_iterator") end ctx.delay_response = nil @@ -447,7 +447,7 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx) local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:plugin_iterator") + req_dyn_hook_run_hook("timing", "before:plugin_iterator") end for _, plugin, configuration in iterator, plugins, 0 do @@ -459,13 +459,13 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx) setup_plugin_context(ctx, plugin, configuration) if has_timing then - req_dyn_hook_run_hooks("timing", "before:plugin", plugin.name, ctx.plugin_id) + req_dyn_hook_run_hook("timing", "before:plugin", plugin.name, ctx.plugin_id) end plugin.handler[phase](plugin.handler, configuration) if has_timing then - req_dyn_hook_run_hooks("timing", "after:plugin") + req_dyn_hook_run_hook("timing", "after:plugin") end reset_plugin_context(ctx, old_ws) @@ -476,7 +476,7 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx) end if has_timing then - req_dyn_hook_run_hooks("timing", "after:plugin_iterator") + req_dyn_hook_run_hook("timing", "after:plugin_iterator") end end @@ -1119,7 +1119,7 @@ function Kong.rewrite() ctx.KONG_PHASE = PHASES.rewrite local has_timing - req_dyn_hook_run_hooks("timing:auth", "auth") + req_dyn_hook_run_hook("timing:auth", "auth") if req_dyn_hook_is_group_enabled("timing") then ctx.has_timing = true @@ -1127,7 +1127,7 @@ function Kong.rewrite() end if has_timing then - req_dyn_hook_run_hooks("timing", "before:rewrite") + req_dyn_hook_run_hook("timing", "before:rewrite") end kong_resty_ctx.stash_ref(ctx) @@ -1156,7 +1156,7 @@ function Kong.rewrite() ctx.KONG_REWRITE_TIME = ctx.KONG_REWRITE_ENDED_AT - ctx.KONG_REWRITE_START if has_timing then - req_dyn_hook_run_hooks("timing", "after:rewrite") + req_dyn_hook_run_hook("timing", "after:rewrite") end end @@ -1166,7 +1166,7 @@ function Kong.access() local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:access") + req_dyn_hook_run_hook("timing", "before:access") end if not ctx.KONG_ACCESS_START then @@ -1192,7 +1192,7 @@ function Kong.access() ctx.KONG_RESPONSE_LATENCY = ctx.KONG_ACCESS_ENDED_AT - ctx.KONG_PROCESSING_START if has_timing then - req_dyn_hook_run_hooks("timing", "after:access") + req_dyn_hook_run_hook("timing", "after:access") end return flush_delayed_response(ctx) @@ -1208,7 +1208,7 @@ function Kong.access() ctx.buffered_proxying = nil if has_timing then - req_dyn_hook_run_hooks("timing", "after:access") + req_dyn_hook_run_hook("timing", "after:access") end return kong.response.error(503, "no Service found with those values") @@ -1229,7 +1229,7 @@ function Kong.access() local upgrade = var.upstream_upgrade or "" if version < 2 and upgrade == "" then if has_timing then - req_dyn_hook_run_hooks("timing", "after:access") + req_dyn_hook_run_hook("timing", "after:access") end return Kong.response() @@ -1245,7 +1245,7 @@ function Kong.access() end if has_timing then - req_dyn_hook_run_hooks("timing", "after:access") + req_dyn_hook_run_hook("timing", "after:access") end end @@ -1255,7 +1255,7 @@ function Kong.balancer() local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:balancer") + req_dyn_hook_run_hook("timing", "before:balancer") end -- This may be called multiple times, and no yielding here! @@ -1337,7 +1337,7 @@ function Kong.balancer() ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START if has_timing then - req_dyn_hook_run_hooks("timing", "after:balancer") + req_dyn_hook_run_hook("timing", "after:balancer") end return ngx.exit(errcode) @@ -1349,7 +1349,7 @@ function Kong.balancer() ngx_log(ngx_ERR, "failed to set balancer Host header: ", err) if has_timing then - req_dyn_hook_run_hooks("timing", "after:balancer") + req_dyn_hook_run_hook("timing", "after:balancer") end return ngx.exit(500) @@ -1404,7 +1404,7 @@ function Kong.balancer() ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START if has_timing then - req_dyn_hook_run_hooks("timing", "after:balancer") + req_dyn_hook_run_hook("timing", "after:balancer") end return ngx.exit(500) @@ -1444,7 +1444,7 @@ function Kong.balancer() ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START if has_timing then - req_dyn_hook_run_hooks("timing", "after:balancer") + req_dyn_hook_run_hook("timing", "after:balancer") end end @@ -1473,7 +1473,7 @@ do local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:response") + req_dyn_hook_run_hook("timing", "before:response") end local plugins_iterator = runloop.get_plugins_iterator() @@ -1494,7 +1494,7 @@ do ngx.status = res.status or 502 if has_timing then - req_dyn_hook_run_hooks("timing", "after:response") + req_dyn_hook_run_hook("timing", "after:response") end return kong_error_handlers(ctx) @@ -1548,7 +1548,7 @@ do ngx.print(body) if has_timing then - req_dyn_hook_run_hooks("timing", "after:response") + req_dyn_hook_run_hook("timing", "after:response") end -- jump over the balancer to header_filter @@ -1562,7 +1562,7 @@ function Kong.header_filter() local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:header_filter") + req_dyn_hook_run_hook("timing", "before:header_filter") end if not ctx.KONG_PROCESSING_START then @@ -1634,7 +1634,7 @@ function Kong.header_filter() ctx.KONG_HEADER_FILTER_TIME = ctx.KONG_HEADER_FILTER_ENDED_AT - ctx.KONG_HEADER_FILTER_START if has_timing then - req_dyn_hook_run_hooks("timing", "after:header_filter") + req_dyn_hook_run_hook("timing", "after:header_filter") end end @@ -1644,7 +1644,7 @@ function Kong.body_filter() local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:body_filter") + req_dyn_hook_run_hook("timing", "before:body_filter") end if not ctx.KONG_BODY_FILTER_START then @@ -1703,7 +1703,7 @@ function Kong.body_filter() if not arg[2] then if has_timing then - req_dyn_hook_run_hooks("timing", "after:body_filter") + req_dyn_hook_run_hook("timing", "after:body_filter") end return @@ -1725,7 +1725,7 @@ function Kong.body_filter() end if has_timing then - req_dyn_hook_run_hooks("timing", "after:body_filter") + req_dyn_hook_run_hook("timing", "after:body_filter") end end @@ -1735,7 +1735,7 @@ function Kong.log() local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:log") + req_dyn_hook_run_hook("timing", "before:log") end if not ctx.KONG_LOG_START then @@ -1830,7 +1830,7 @@ function Kong.log() runloop.log.after(ctx) if has_timing then - req_dyn_hook_run_hooks("timing", "after:log") + req_dyn_hook_run_hook("timing", "after:log") end release_table(CTX_NS, ctx) diff --git a/kong/resty/dns/client.lua b/kong/resty/dns/client.lua index f7e23049ab68..874515badeb1 100644 --- a/kong/resty/dns/client.lua +++ b/kong/resty/dns/client.lua @@ -49,7 +49,7 @@ local table_concat = table.concat local string_lower = string.lower local string_byte = string.byte -local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks +local req_dyn_hook_run_hook = req_dyn_hook.run_hook local DOT = string_byte(".") @@ -145,7 +145,7 @@ local cachelookup = function(qname, qtype) local ctx = ngx.ctx if ctx and ctx.has_timing then - req_dyn_hook_run_hooks("timing", "dns:cache_lookup", cached ~= nil) + req_dyn_hook_run_hook("timing", "dns:cache_lookup", cached ~= nil) end if cached then diff --git a/kong/runloop/handler.lua b/kong/runloop/handler.lua index 84fb8493c89b..b743e3241717 100644 --- a/kong/runloop/handler.lua +++ b/kong/runloop/handler.lua @@ -51,7 +51,7 @@ local request_id_get = request_id.get local escape = require("kong.tools.uri").escape local encode = require("string.buffer").encode -local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks +local req_dyn_hook_run_hook = req_dyn_hook.run_hook local is_http_module = subsystem == "http" local is_stream_module = subsystem == "stream" @@ -1112,7 +1112,7 @@ return { local has_timing = ctx.has_timing if has_timing then - req_dyn_hook_run_hooks("timing", "before:router") + req_dyn_hook_run_hook("timing", "before:router") end -- routing request @@ -1120,7 +1120,7 @@ return { local match_t = router:exec(ctx) if has_timing then - req_dyn_hook_run_hooks("timing", "after:router") + req_dyn_hook_run_hook("timing", "after:router") end if not match_t then @@ -1141,7 +1141,7 @@ return { ctx.workspace = match_t.route and match_t.route.ws_id if has_timing then - req_dyn_hook_run_hooks("timing", "workspace_id:got", ctx.workspace) + req_dyn_hook_run_hook("timing", "workspace_id:got", ctx.workspace) end local host = var.host From b4999557d6d9df4684e5236b6fd1bd4f14142548 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 27 May 2024 15:58:46 +0800 Subject: [PATCH 14/16] style(dynamic_hook): rename the third argument of function `hook_function` from `child_key` to `function_key` for readability Co-authored-by: samugi --- kong/dynamic_hook/init.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kong/dynamic_hook/init.lua b/kong/dynamic_hook/init.lua index 76826226eb76..1e1ec18ffb19 100644 --- a/kong/dynamic_hook/init.lua +++ b/kong/dynamic_hook/init.lua @@ -153,10 +153,10 @@ local function wrap_function(max_args, group_name, original_func, handlers) end -function _M.hook_function(group_name, parent, child_key, max_args, handlers) +function _M.hook_function(group_name, parent, function_key, max_args, handlers) assert(type(group_name) == "string", "group_name must be a string") assert(type(parent) == "table", "parent must be a table") - assert(type(child_key) == "string", "child_key must be a string") + assert(type(function_key) == "string", "function_key must be a string") local is_varargs = max_args == "varargs" if not is_varargs then @@ -164,13 +164,13 @@ function _M.hook_function(group_name, parent, child_key, max_args, handlers) assert(max_args >= 0 and max_args <= 8, 'max_args must be >= 0 and <= 8, or "varargs"') end - local original_func = parent[child_key] - assert(type(original_func) == "function", "parent[" .. child_key .. "] must be a function") + local original_func = parent[function_key] + assert(type(original_func) == "function", "parent[" .. function_key .. "] must be a function") if is_varargs then - parent[child_key] = wrap_function_vararg(group_name, original_func, handlers) + parent[function_key] = wrap_function_vararg(group_name, original_func, handlers) else - parent[child_key] = wrap_function(max_args, group_name, original_func, handlers) + parent[function_key] = wrap_function(max_args, group_name, original_func, handlers) end end From ecf4314ac394903eab119f82d86994c855a682b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20H=C3=BCbner?= Date: Thu, 23 May 2024 16:55:35 +0200 Subject: [PATCH 15/16] feat(emmy-lua-debugger): support busted & multi worker debugging + docs --- DEVELOPER.md | 31 ++++++++++++- bin/busted | 13 ++++++ kong/tools/emmy_debugger.lua | 85 ++++++++++++++++++++++++------------ 3 files changed, 98 insertions(+), 31 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index e797f934faa9..b847a0f00739 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -473,7 +473,7 @@ The [EmmyLuaDebugger](https://github.com/EmmyLua/EmmyLuaDebugger) is a standalon that runs on the same machine as Kong Gateway and that mediates between the IDE's debugger and the Lua code running in Kong Gateway. It can be downloaded from [GitHub](https://github.com/EmmyLua/EmmyLuaDebugger/releases). The release -ZIP file contains a single share library named emmy_core.so (Linux) or emmy_core.dylib (macOS). +ZIP file contains a single shared library named emmy_core.so (Linux) or emmy_core.dylib (macOS). Place this file in a directory that is convenient for you and remember the path. Depending on your Linux version, you may need to compile @@ -486,7 +486,7 @@ recent version of GLIBC to be present. To enable the EmmyLua debugger, the `KONG_EMMY_DEBUGGER` environment variable must be set to the absolute path of the debugger shared library file when Kong Gateway is started. It is also advisable to start Kong Gateway with only one worker process, as debugging multiple worker -processes is not supported. For example: +processes requires special care. For example: ```shell KONG_EMMY_DEBUGGER=/path/to/emmy_core.so KONG_NGINX_WORKER_PROCESSES=1 kong start @@ -515,6 +515,33 @@ a breakpoint in the global `access` function that is defined `runloop/handler.lu a proxy request to the Gateway. The debugger should stop at the breakpoint and you can inspect the variables in the request context. +### Debugging `busted` tests + +To debug `busted` tests, you can set the `BUSTED_EMMY_DEBUGGER` environment variable to the path +to the EmmyLua debugger shared library. When debugging is enabled, `busted` will always wait for +the IDE to connect during startup. + +### Debugging environment variables + +The following environment variables can be set to control the behavior of the EmmyLua debugger +integration: + +- `KONG_EMMY_DEBUGGER`: The path to the EmmyLua debugger shared library. +- `KONG_EMMY_DEBUGGER_HOST`: The IP address that the EmmyLua debugger will listen on. The default + is `localhost`. +- `KONG_EMMY_DEBUGGER_PORT`: The port that the EmmyLua debugger will listen on. The default is + `9966`. +- `KONG_EMMY_DEBUGGER_WAIT`: If set, Kong Gateway will wait for the debugger to connect + before starting continuing to start. +- `KONG_EMMY_DEBUGGER_SOURCE_PATH`: The path to the source code that the EmmyLua debugger will + use to resolve source code locations. The default is the current working directory. +- `KONG_EMMY_DEBUGGER_MULTI_WORKER`: If set, a debugger will be started for each worker process, using + incrementing port numbers starting at `KONG_EMMY_DEBUGGER_PORT`. The default is to start + only one debugger for worker zero. + +To control debugger behavior while running `busted` tests, a similar set of environment variables +prefixed with `BUSTED_` instead of `KONG_` can be used. + ## What's next - Refer to the [Kong Gateway Docs](https://docs.konghq.com/gateway/) for more information. diff --git a/bin/busted b/bin/busted index 348eff4e1584..021e13a79241 100755 --- a/bin/busted +++ b/bin/busted @@ -8,6 +8,8 @@ local pl_file = require("pl.file") local tools_system = require("kong.tools.system") +local emmy_debugger = require("kong.tools.emmy_debugger") + local cert_path do local busted_cert_file = pl_path.tmpname() local busted_cert_content = pl_file.read("spec/fixtures/kong_spec.crt") @@ -72,6 +74,16 @@ end pcall(require, "luarocks.loader") +if os.getenv("BUSTED_EMMY_DEBUGGER") then + emmy_debugger.init({ + debugger = os.getenv("BUSTED_EMMY_DEBUGGER"), + host = os.getenv("BUSTED_EMMY_DEBUGGER_HOST"), + port = os.getenv("BUSTED_EMMY_DEBUGGER_PORT"), + wait = true, + source_path = os.getenv("BUSTED_EMMY_DEBUGGER_SOURCE_PATH"), + }) +end + require("kong.globalpatches")({ cli = true, rbusted = true @@ -88,4 +100,5 @@ _G.require = require "spec.require".require -- Busted command-line runner require 'busted.runner'({ standalone = false }) + -- vim: set ft=lua ts=2 sw=2 sts=2 et : diff --git a/kong/tools/emmy_debugger.lua b/kong/tools/emmy_debugger.lua index 9053a041f16c..25793ae85591 100644 --- a/kong/tools/emmy_debugger.lua +++ b/kong/tools/emmy_debugger.lua @@ -1,11 +1,17 @@ local pl_path = require "pl.path" local utils = require "kong.tools.utils" -local debugger = os.getenv("KONG_EMMY_DEBUGGER") -local emmy_debugger_host = os.getenv("KONG_EMMY_DEBUGGER_HOST") or "localhost" -local emmy_debugger_port = os.getenv("KONG_EMMY_DEBUGGER_PORT") or 9966 -local emmy_debugger_wait = os.getenv("KONG_EMMY_DEBUGGER_WAIT") -local emmy_debugger_source_path = utils.split(os.getenv("KONG_EMMY_DEBUGGER_SOURCE_PATH") or "", ":") +local env_config = { + debugger = os.getenv("KONG_EMMY_DEBUGGER"), + host = os.getenv("KONG_EMMY_DEBUGGER_HOST"), + port = os.getenv("KONG_EMMY_DEBUGGER_PORT"), + wait = os.getenv("KONG_EMMY_DEBUGGER_WAIT"), + source_path = os.getenv("KONG_EMMY_DEBUGGER_SOURCE_PATH"), + multi_worker = os.getenv("KONG_EMMY_DEBUGGER_MULTI_WORKER"), +} + +local source_path +local env_prefix local function find_source(path) if pl_path.exists(path) then @@ -17,60 +23,80 @@ local function find_source(path) return path end - for _, source_path in ipairs(emmy_debugger_source_path) do - local full_path = pl_path.join(source_path, path) + if path:match("^jsonschema:") then + -- code is executing from jsonschema, don't attempt to map + return path + end + + for _, p in ipairs(source_path) do + local full_path = pl_path.join(p, path) if pl_path.exists(full_path) then return full_path end end - ngx.log(ngx.ERR, "source file " .. path .. " not found in KONG_EMMY_DEBUGGER_SOURCE_PATH") + ngx.log(ngx.ERR, "source file " .. path .. " not found in " .. env_prefix .. "_EMMY_DEBUGGER_SOURCE_PATH") return path end -local function init() +local function load_debugger(path) + _G.emmy = { + fixPath = find_source + } + + local ext = pl_path.extension(path) + local name = pl_path.basename(path):sub(1, -#ext - 1) + + local save_cpath = package.cpath + package.cpath = pl_path.dirname(path) .. '/?' .. ext + local dbg = require(name) + package.cpath = save_cpath + return dbg +end + +local function init(config_) + local config = config_ or {} + local debugger = config.debugger or env_config.debugger + local host = config.host or env_config.host or "localhost" + local port = config.port or env_config.port or 9966 + local wait = config.wait or env_config.wait + local multi_worker = env_config.multi_worker or env_config.multi_worker + + env_prefix = config.env_prefix or "KONG" + source_path = utils.split(config.source_path or env_config.source_path or "", ":") + if not debugger then return end if not pl_path.isabs(debugger) then - ngx.log(ngx.ERR, "KONG_EMMY_DEBUGGER (" .. debugger .. ") must be an absolute path") + ngx.log(ngx.ERR, env_prefix .. "_EMMY_DEBUGGER (" .. debugger .. ") must be an absolute path") return end if not pl_path.exists(debugger) then - ngx.log(ngx.ERR, "KONG_EMMY_DEBUGGER (" .. debugger .. ") file not found") + ngx.log(ngx.ERR, env_prefix .. "_EMMY_DEBUGGER (" .. debugger .. ") file not found") return end local ext = pl_path.extension(debugger) if ext ~= ".so" and ext ~= ".dylib" then - ngx.log(ngx.ERR, "KONG_EMMY_DEBUGGER (" .. debugger .. ") must be a .so (Linux) or .dylib (macOS) file") + ngx.log(ngx.ERR, env_prefix .. "_EMMY_DEBUGGER (" .. debugger .. ") must be a .so (Linux) or .dylib (macOS) file") return end - if ngx.worker.id() ~= 0 then - ngx.log(ngx.ERR, "KONG_EMMY_DEBUGGER is only supported in the first worker process, suggest setting KONG_NGINX_WORKER_PROCESSES to 1") + if ngx.worker.id() > 0 and not multi_worker then + ngx.log(ngx.ERR, env_prefix .. "_EMMY_DEBUGGER is only supported in the first worker process, suggest setting KONG_NGINX_WORKER_PROCESSES to 1") return end ngx.log(ngx.NOTICE, "loading EmmyLua debugger " .. debugger) ngx.log(ngx.WARN, "The EmmyLua integration for Kong is a feature solely for your convenience during development. Kong assumes no liability as a result of using the integration and does not endorse it’s usage. Issues related to usage of EmmyLua integration should be directed to the respective project instead.") - _G.emmy = { - fixPath = find_source - } - - local name = pl_path.basename(debugger):sub(1, -#ext - 1) - - local save_cpath = package.cpath - package.cpath = pl_path.dirname(debugger) .. '/?' .. ext - local dbg = require(name) - package.cpath = save_cpath - - dbg.tcpListen(emmy_debugger_host, emmy_debugger_port) + local dbg = load_debugger(debugger) + dbg.tcpListen(host, port + (ngx.worker.id() or 0)) - ngx.log(ngx.NOTICE, "EmmyLua debugger loaded, listening on port ", emmy_debugger_port) + ngx.log(ngx.NOTICE, "EmmyLua debugger loaded, listening on port ", port) - if emmy_debugger_wait then + if wait then -- Wait for IDE connection ngx.log(ngx.NOTICE, "waiting for IDE to connect") dbg.waitIDE() @@ -79,5 +105,6 @@ local function init() end return { - init = init + init = init, + load_debugger = load_debugger } From aae1815213790bb0bd53e2cf0aaceba50314c3a3 Mon Sep 17 00:00:00 2001 From: Chrono Date: Mon, 27 May 2024 19:08:50 +0800 Subject: [PATCH 16/16] refactor(tools/uuid): update UUID reference (#12952) --- kong/api/endpoints.lua | 11 +++--- kong/api/routes/certificates.lua | 6 ++-- kong/api/routes/upstreams.lua | 6 ++-- kong/cluster_events/strategies/postgres.lua | 4 +-- kong/db/dao/init.lua | 4 +-- kong/db/errors.lua | 4 +-- kong/db/migrations/core/013_220_to_230.lua | 4 +-- kong/db/schema/others/declarative_config.lua | 4 +-- kong/init.lua | 3 +- kong/pdk/client.lua | 9 ++--- kong/pdk/node.lua | 9 ++--- kong/pdk/private/node.lua | 8 ++--- kong/plugins/acl/api.lua | 8 ++--- kong/plugins/correlation-id/handler.lua | 2 +- kong/runloop/balancer/init.lua | 3 +- kong/runloop/handler.lua | 10 +++--- kong/runloop/plugins_iterator.lua | 9 ++--- kong/runloop/wasm.lua | 4 +-- kong/tools/utils.lua | 6 ++-- .../01-db/01-schema/07-plugins_spec.lua | 22 ++++++------ .../01-db/01-schema/08-targets_spec.lua | 4 +-- .../11-declarative_config/03-flatten_spec.lua | 4 +-- .../04-on-the-fly-migration_spec.lua | 4 +-- spec/01-unit/01-db/01-schema/11-snis_spec.lua | 4 +-- spec/01-unit/05-utils_spec.lua | 1 + spec/01-unit/08-router_spec.lua | 2 +- spec/01-unit/09-balancer/01-generic_spec.lua | 4 +-- .../09-balancer/02-least_connections_spec.lua | 4 +-- .../03-consistent_hashing_spec.lua | 4 +-- .../09-balancer/04-round_robin_spec.lua | 4 +-- .../05-worker_consistency_spec.lua | 3 +- spec/01-unit/09-balancer/06-latency_spec.lua | 4 +-- spec/01-unit/14-dns_spec.lua | 4 +-- spec/01-unit/27-queue_spec.lua | 6 ++-- .../03-db/02-db_core_entities_spec.lua | 30 ++++++++-------- spec/02-integration/03-db/07-tags_spec.lua | 2 +- .../03-db/10-db_unique_foreign_spec.lua | 10 +++--- spec/02-integration/03-db/14-dao_spec.lua | 4 +-- .../04-admin_api/03-consumers_routes_spec.lua | 10 +++--- .../04-admin_api/04-plugins_routes_spec.lua | 8 ++--- .../06-certificates_routes_spec.lua | 16 ++++----- .../04-admin_api/08-targets_routes_spec.lua | 6 ++-- .../04-admin_api/09-routes_routes_spec.lua | 32 ++++++++--------- .../04-admin_api/10-services_routes_spec.lua | 10 +++--- .../04-admin_api/15-off_spec.lua | 12 +++---- .../04-admin_api/17-foreign-entity_spec.lua | 10 +++--- .../04-admin_api/19-vaults_spec.lua | 6 ++-- .../05-proxy/04-plugins_triggering_spec.lua | 24 ++++++------- .../10-balancer/01-healthchecks_spec.lua | 4 +-- .../05-proxy/14-server_tokens_spec.lua | 4 +-- .../03-plugins_iterator_invalidation_spec.lua | 4 +-- .../09-hybrid_mode/01-sync_spec.lua | 6 ++-- .../09-hybrid_mode/09-config-compat_spec.lua | 36 +++++++++---------- .../09-node-id-persistence_spec.lua | 3 +- .../20-wasm/01-admin-api_spec.lua | 18 +++++----- spec/02-integration/20-wasm/02-db_spec.lua | 14 ++++---- .../03-plugins/03-http-log/02-schema_spec.lua | 4 +-- spec/03-plugins/05-syslog/01-log_spec.lua | 4 +-- .../03-plugins/09-key-auth/02-access_spec.lua | 4 +-- .../10-basic-auth/03-access_spec.lua | 4 +-- spec/03-plugins/16-jwt/03-access_spec.lua | 4 +-- spec/03-plugins/18-acl/01-api_spec.lua | 6 ++-- .../19-hmac-auth/03-access_spec.lua | 4 +-- .../20-ldap-auth/01-access_spec.lua | 4 +-- .../23-rate-limiting/02-policies_spec.lua | 2 +- .../06-shorthand_fields_spec.lua | 4 +-- .../02-policies_spec.lua | 2 +- .../06-shorthand_fields_spec.lua | 4 +-- spec/03-plugins/25-oauth2/01-schema_spec.lua | 14 ++++---- spec/03-plugins/25-oauth2/03-access_spec.lua | 4 +-- .../29-acme/07-shorthand_fields_spec.lua | 4 +-- .../01-access_spec.lua | 6 ++-- spec/fixtures/balancer_utils.lua | 9 ++--- spec/helpers.lua | 6 ++-- 74 files changed, 277 insertions(+), 269 deletions(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index eb995a357b76..3129fe6ddbe7 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -1,5 +1,5 @@ local Errors = require "kong.db.errors" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local arguments = require "kong.api.arguments" local workspaces = require "kong.workspaces" local app_helpers = require "lapis.application" @@ -17,7 +17,8 @@ local type = type local fmt = string.format local concat = table.concat local re_match = ngx.re.match -local split = utils.split +local split = require("kong.tools.string").split +local get_default_exit_body = require("kong.tools.http").get_default_exit_body -- error codes http status codes @@ -132,7 +133,7 @@ local function handle_error(err_t) return kong.response.exit(status, err_t) end - return kong.response.exit(status, utils.get_default_exit_body(status, err_t)) + return kong.response.exit(status, get_default_exit_body(status, err_t)) end @@ -241,7 +242,7 @@ local function query_entity(context, self, db, schema, method) end end - if key.id and not utils.is_valid_uuid(key.id) then + if key.id and not uuid.is_valid_uuid(key.id) then local endpoint_key = schema.endpoint_key if endpoint_key then local field = schema.fields[endpoint_key] @@ -526,7 +527,7 @@ local function put_entity_endpoint(schema, foreign_schema, foreign_field_name, m self.params[foreign_schema.name] = pk else associate = true - self.params[foreign_schema.name] = utils.uuid() + self.params[foreign_schema.name] = uuid.uuid() end else diff --git a/kong/api/routes/certificates.lua b/kong/api/routes/certificates.lua index d0224f67aac6..7bdf6df80175 100644 --- a/kong/api/routes/certificates.lua +++ b/kong/api/routes/certificates.lua @@ -1,6 +1,6 @@ local endpoints = require "kong.api.endpoints" local arguments = require "kong.api.arguments" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local ngx = ngx @@ -15,7 +15,7 @@ local function prepare_params(self) local id = unescape_uri(self.params.certificates) local method = self.req.method local name - if not utils.is_valid_uuid(id) then + if not uuid.is_valid_uuid(id) then name = arguments.infer_value(id, kong.db.snis.schema.fields.name) local sni, _, err_t = kong.db.snis:select_by_name(name) @@ -31,7 +31,7 @@ local function prepare_params(self) return kong.response.exit(404, { message = "SNI not found" }) end - id = utils.uuid() + id = uuid.uuid() end end diff --git a/kong/api/routes/upstreams.lua b/kong/api/routes/upstreams.lua index 83393a24cde1..614bef1721dc 100644 --- a/kong/api/routes/upstreams.lua +++ b/kong/api/routes/upstreams.lua @@ -1,5 +1,5 @@ local endpoints = require "kong.api.endpoints" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local kong = kong @@ -21,7 +21,7 @@ local function set_target_health(self, db, is_healthy) end local target - if utils.is_valid_uuid(unescape_uri(self.params.targets)) then + if uuid.is_valid_uuid(unescape_uri(self.params.targets)) then target, _, err_t = endpoints.select_entity(self, db, db.targets.schema) else @@ -90,7 +90,7 @@ local function target_endpoint(self, db, callback) end local target - if utils.is_valid_uuid(unescape_uri(self.params.targets)) then + if uuid.is_valid_uuid(unescape_uri(self.params.targets)) then target, _, err_t = endpoints.select_entity(self, db, db.targets.schema) else diff --git a/kong/cluster_events/strategies/postgres.lua b/kong/cluster_events/strategies/postgres.lua index 3399f49bb404..1658a314298b 100644 --- a/kong/cluster_events/strategies/postgres.lua +++ b/kong/cluster_events/strategies/postgres.lua @@ -1,4 +1,4 @@ -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local new_tab = require "table.new" @@ -97,7 +97,7 @@ function _M:insert(node_id, channel, at, data, delay) nbf = "NULL" end - local pg_id = self.connector:escape_literal(utils.uuid()) + local pg_id = self.connector:escape_literal(uuid.uuid()) local pg_node_id = self.connector:escape_literal(node_id) local pg_channel = self.connector:escape_literal(channel) local pg_data = self.connector:escape_literal(data) diff --git a/kong/db/dao/init.lua b/kong/db/dao/init.lua index e886b9f64dca..f84801c85a1e 100644 --- a/kong/db/dao/init.lua +++ b/kong/db/dao/init.lua @@ -1,12 +1,12 @@ local cjson = require "cjson" local iteration = require "kong.db.iteration" -local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local defaults = require "kong.db.strategies.connector".defaults local hooks = require "kong.hooks" local workspaces = require "kong.workspaces" local new_tab = require "table.new" local DAO_MAX_TTL = require("kong.constants").DATABASE.DAO_MAX_TTL +local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid local setmetatable = setmetatable local tostring = tostring @@ -174,7 +174,7 @@ local function validate_options_value(self, options) if options.workspace then if type(options.workspace) == "string" then - if not utils.is_valid_uuid(options.workspace) then + if not is_valid_uuid(options.workspace) then local ws = kong.db.workspaces:select_by_name(options.workspace) if ws then options.workspace = ws.id diff --git a/kong/db/errors.lua b/kong/db/errors.lua index 67276bf41b2b..a1f96cccd1bf 100644 --- a/kong/db/errors.lua +++ b/kong/db/errors.lua @@ -2,7 +2,7 @@ local pl_pretty = require("pl.pretty").write local pl_keys = require("pl.tablex").keys local nkeys = require("table.nkeys") local table_isarray = require("table.isarray") -local utils = require("kong.tools.utils") +local uuid = require("kong.tools.uuid") local type = type @@ -757,7 +757,7 @@ do ---@return string|nil local function validate_id(id) return (type(id) == "string" - and utils.is_valid_uuid(id) + and uuid.is_valid_uuid(id) and id) or nil end diff --git a/kong/db/migrations/core/013_220_to_230.lua b/kong/db/migrations/core/013_220_to_230.lua index 14f837d9c7be..4931865034ab 100644 --- a/kong/db/migrations/core/013_220_to_230.lua +++ b/kong/db/migrations/core/013_220_to_230.lua @@ -1,7 +1,7 @@ -local utils = require("kong.tools.utils") +local uuid = require("kong.tools.uuid") -local CLUSTER_ID = utils.uuid() +local CLUSTER_ID = uuid.uuid() return { diff --git a/kong/db/schema/others/declarative_config.lua b/kong/db/schema/others/declarative_config.lua index 48c8704c44d5..c6b9ede1c3ab 100644 --- a/kong/db/schema/others/declarative_config.lua +++ b/kong/db/schema/others/declarative_config.lua @@ -1,5 +1,4 @@ local uuid = require("resty.jit-uuid") -local utils = require("kong.tools.utils") local kong_table = require("kong.tools.table") local Errors = require("kong.db.errors") local Entity = require("kong.db.schema.entity") @@ -8,6 +7,7 @@ local constants = require("kong.constants") local plugin_loader = require("kong.db.schema.plugin_loader") local vault_loader = require("kong.db.schema.vault_loader") local schema_topological_sort = require("kong.db.schema.topological_sort") +local utils_uuid = require("kong.tools.uuid").uuid local null = ngx.null @@ -649,7 +649,7 @@ local function populate_ids_for_validation(input, known_entities, parent_entity, if key then item[pk_name] = generate_uuid(schema.name, key) else - item[pk_name] = utils.uuid() + item[pk_name] = utils_uuid() end end diff --git a/kong/init.lua b/kong/init.lua index 225d6683174c..1378c1e91fb3 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -96,6 +96,7 @@ local wasm = require "kong.runloop.wasm" local reports = require "kong.reports" local pl_file = require "pl.file" local req_dyn_hook = require "kong.dynamic_hook" +local uuid = require("kong.tools.uuid").uuid local kong = kong @@ -767,7 +768,7 @@ function Kong.init() end if config.request_debug and config.role ~= "control_plane" and is_http_module then - local token = config.request_debug_token or utils.uuid() + local token = config.request_debug_token or uuid() local request_debug_token_file = pl_path.join(config.prefix, constants.REQUEST_DEBUG_TOKEN_FILE) diff --git a/kong/pdk/client.lua b/kong/pdk/client.lua index 9f74620c5a24..01592f42236b 100644 --- a/kong/pdk/client.lua +++ b/kong/pdk/client.lua @@ -8,8 +8,9 @@ -- @module kong.client -local utils = require "kong.tools.utils" local phase_checker = require "kong.pdk.private.phases" +local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid +local check_https = require("kong.tools.http").check_https local ngx = ngx @@ -187,11 +188,11 @@ local function new(self) error("consumer_id must be a string", 2) end - if not utils.is_valid_uuid(consumer_id) and not search_by_username then + if not is_valid_uuid(consumer_id) and not search_by_username then error("cannot load a consumer with an id that is not a uuid", 2) end - if utils.is_valid_uuid(consumer_id) then + if is_valid_uuid(consumer_id) then local result, err = kong.db.consumers:select({ id = consumer_id }) if result then @@ -289,7 +290,7 @@ local function new(self) if ngx.config.subsystem == "http" then local is_trusted = self.ip.is_trusted(self.client.get_ip()) - local is_https, err = utils.check_https(is_trusted, allow_terminated) + local is_https, err = check_https(is_trusted, allow_terminated) if err then return nil, err end diff --git a/kong/pdk/node.lua b/kong/pdk/node.lua index abb338fa8fd3..9302c17cde1a 100644 --- a/kong/pdk/node.lua +++ b/kong/pdk/node.lua @@ -2,9 +2,10 @@ -- -- @module kong.node -local utils = require "kong.tools.utils" local ffi = require "ffi" local private_node = require "kong.pdk.private.node" +local uuid = require("kong.tools.uuid").uuid +local bytes_to_str = require("kong.tools.string").bytes_to_str local floor = math.floor @@ -46,7 +47,7 @@ local function convert_bytes(bytes, unit, scale) return floor(bytes) end - return utils.bytes_to_str(bytes, unit, scale) + return bytes_to_str(bytes, unit, scale) end @@ -73,7 +74,7 @@ local function new(self) local shm = ngx.shared.kong - local ok, err = shm:safe_add(NODE_ID_KEY, utils.uuid()) + local ok, err = shm:safe_add(NODE_ID_KEY, uuid()) if not ok and err ~= "exists" then error("failed to set 'node_id' in shm: " .. err) end @@ -160,7 +161,7 @@ local function new(self) unit = unit or "b" scale = scale or 2 - local pok, perr = pcall(utils.bytes_to_str, 0, unit, scale) + local pok, perr = pcall(bytes_to_str, 0, unit, scale) if not pok then error(perr, 2) end diff --git a/kong/pdk/private/node.lua b/kong/pdk/private/node.lua index ed299c999c3d..26441ed47807 100644 --- a/kong/pdk/private/node.lua +++ b/kong/pdk/private/node.lua @@ -1,5 +1,5 @@ local log = require "kong.cmd.utils.log" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local pl_file = require "pl.file" local pl_path = require "pl.path" local pl_dir = require "pl.dir" @@ -31,7 +31,7 @@ local function initialize_node_id(prefix) return nil, fmt("failed to access file %s: %s", filename, err) end - if not utils.is_valid_uuid(id) then + if not uuid.is_valid_uuid(id) then log.debug("file %s contains invalid uuid: %s", filename, id) -- set false to override it when it contains an invalid uuid. file_exists = false @@ -39,7 +39,7 @@ local function initialize_node_id(prefix) end if not file_exists then - local id = utils.uuid() + local id = uuid.uuid() log.debug("persisting node_id (%s) to %s", id, filename) local ok, write_err = pl_file.write(filename, id) @@ -89,7 +89,7 @@ local function load_node_id(prefix) return nil, fmt("failed to access file %s: %s", filename, read_err) end - if not utils.is_valid_uuid(id) then + if not uuid.is_valid_uuid(id) then return nil, fmt("file %s contains invalid uuid: %q", filename, id) end diff --git a/kong/plugins/acl/api.lua b/kong/plugins/acl/api.lua index 95586593bd31..c6c6dd48d9aa 100644 --- a/kong/plugins/acl/api.lua +++ b/kong/plugins/acl/api.lua @@ -1,5 +1,5 @@ local endpoints = require "kong.api.endpoints" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local ngx = ngx @@ -13,10 +13,10 @@ return { schema = kong.db.acls.schema, before = function(self, db, helpers) local group = unescape_uri(self.params.acls) - if not utils.is_valid_uuid(group) then + if not uuid.is_valid_uuid(group) then local consumer_id = unescape_uri(self.params.consumers) - if not utils.is_valid_uuid(consumer_id) then + if not uuid.is_valid_uuid(consumer_id) then local consumer, _, err_t = endpoints.select_entity(self, db, db.consumers.schema) if err_t then return endpoints.handle_error(err_t) @@ -42,7 +42,7 @@ return { return kong.response.error(404) end - self.params.acls = utils.uuid() + self.params.acls = uuid.uuid() end self.params.group = group diff --git a/kong/plugins/correlation-id/handler.lua b/kong/plugins/correlation-id/handler.lua index b7d917dde305..5f1f82b9fdef 100644 --- a/kong/plugins/correlation-id/handler.lua +++ b/kong/plugins/correlation-id/handler.lua @@ -1,5 +1,5 @@ -- Copyright (C) Kong Inc. -local uuid = require "kong.tools.utils".uuid +local uuid = require "kong.tools.uuid".uuid local kong_meta = require "kong.meta" diff --git a/kong/runloop/balancer/init.lua b/kong/runloop/balancer/init.lua index 7515cfc1c875..0e8268323fdf 100644 --- a/kong/runloop/balancer/init.lua +++ b/kong/runloop/balancer/init.lua @@ -2,6 +2,7 @@ local pl_tablex = require "pl.tablex" local utils = require "kong.tools.utils" local hooks = require "kong.hooks" local recreate_request = require("ngx.balancer").recreate_request +local uuid = require("kong.tools.uuid").uuid local healthcheckers = require "kong.runloop.balancer.healthcheckers" local balancers = require "kong.runloop.balancer.balancers" @@ -145,7 +146,7 @@ local function get_value_to_hash(upstream, ctx) ctx = ngx.ctx end - identifier = utils.uuid() + identifier = uuid() ctx.balancer_data.hash_cookie = { key = upstream.hash_on_cookie, diff --git a/kong/runloop/handler.lua b/kong/runloop/handler.lua index b743e3241717..1f3210d2a889 100644 --- a/kong/runloop/handler.lua +++ b/kong/runloop/handler.lua @@ -1,7 +1,6 @@ -- Kong runloop local meta = require "kong.meta" -local utils = require "kong.tools.utils" local Router = require "kong.router" local balancer = require "kong.runloop.balancer" local events = require "kong.runloop.events" @@ -50,6 +49,7 @@ 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 uuid = require("kong.tools.uuid").uuid local req_dyn_hook_run_hook = req_dyn_hook.run_hook @@ -226,7 +226,7 @@ end -- or an error happened). -- @returns error message as a second return value in case of failure/error local function rebuild(name, callback, version, opts) - local current_version, err = kong.core_cache:get(name .. ":version", TTL_ZERO, utils.uuid) + local current_version, err = kong.core_cache:get(name .. ":version", TTL_ZERO, uuid) if err then return nil, "failed to retrieve " .. name .. " version: " .. err end @@ -333,7 +333,7 @@ end local function get_router_version() - return kong.core_cache:get("router:version", TTL_ZERO, utils.uuid) + return kong.core_cache:get("router:version", TTL_ZERO, uuid) end @@ -533,7 +533,7 @@ end local function update_plugins_iterator() - local version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, utils.uuid) + local version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, uuid) if err then return nil, "failed to retrieve plugins iterator version: " .. err end @@ -621,7 +621,7 @@ end local reconfigure_handler do - local get_monotonic_ms = utils.get_updated_monotonic_ms + local get_monotonic_ms = require("kong.tools.time").get_updated_monotonic_ms local ngx_worker_id = ngx.worker.id local exiting = ngx.worker.exiting diff --git a/kong/runloop/plugins_iterator.lua b/kong/runloop/plugins_iterator.lua index 515d14a947eb..6fe558004035 100644 --- a/kong/runloop/plugins_iterator.lua +++ b/kong/runloop/plugins_iterator.lua @@ -1,6 +1,5 @@ local workspaces = require "kong.workspaces" local constants = require "kong.constants" -local utils = require "kong.tools.utils" local tablepool = require "tablepool" @@ -16,6 +15,8 @@ local ipairs = ipairs local format = string.format local fetch_table = tablepool.fetch local release_table = tablepool.release +local uuid = require("kong.tools.uuid").uuid +local get_updated_monotonic_ms = require("kong.tools.time").get_updated_monotonic_ms local TTL_ZERO = { ttl = 0 } @@ -433,9 +434,9 @@ local function configure(configurable, ctx) local name = plugin.name kong_global.set_namespaced_log(kong, plugin.name, ctx) - local start = utils.get_updated_monotonic_ms() + local start = get_updated_monotonic_ms() local ok, err = pcall(plugin.handler[CONFIGURE_PHASE], plugin.handler, configurable[name]) - local elapsed = utils.get_updated_monotonic_ms() - start + local elapsed = get_updated_monotonic_ms() - start kong_global.reset_log(kong, ctx) if not ok then @@ -514,7 +515,7 @@ function PluginsIterator.new(version) end if is_not_dbless and counter > 0 and counter % page_size == 0 and kong.core_cache then - local new_version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, utils.uuid) + local new_version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, uuid) if err then return nil, "failed to retrieve plugins iterator version: " .. err end diff --git a/kong/runloop/wasm.lua b/kong/runloop/wasm.lua index 8ea57e2042b8..af9bbc2cbae8 100644 --- a/kong/runloop/wasm.lua +++ b/kong/runloop/wasm.lua @@ -31,7 +31,7 @@ local _M = { ---@field config_schema kong.db.schema.json.schema_doc|nil -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local reports = require "kong.reports" local clear_tab = require "table.clear" local cjson = require "cjson.safe" @@ -81,7 +81,7 @@ local FILTER_META_SCHEMA = { -- ---@return string local function get_version() - return kong.core_cache:get(VERSION_KEY, TTL_ZERO, utils.uuid) + return kong.core_cache:get(VERSION_KEY, TTL_ZERO, uuid.uuid) end diff --git a/kong/tools/utils.lua b/kong/tools/utils.lua index c410454b6857..aa75282f202b 100644 --- a/kong/tools/utils.lua +++ b/kong/tools/utils.lua @@ -18,10 +18,12 @@ local _M = {} do local modules = { + -- [[ keep it here for compatibility "kong.tools.table", - "kong.tools.string", "kong.tools.uuid", - "kong.tools.rand", -- keep it here for compatibility + "kong.tools.rand", + -- ]] keep it here for compatibility + "kong.tools.string", "kong.tools.time", "kong.tools.ip", "kong.tools.http", diff --git a/spec/01-unit/01-db/01-schema/07-plugins_spec.lua b/spec/01-unit/01-db/01-schema/07-plugins_spec.lua index 1bfc1efcefab..4de064d3861d 100644 --- a/spec/01-unit/01-db/01-schema/07-plugins_spec.lua +++ b/spec/01-unit/01-db/01-schema/07-plugins_spec.lua @@ -1,7 +1,7 @@ require "spec.helpers" -- initializes 'kong' global for plugins local Entity = require "kong.db.schema.entity" local typedefs = require "kong.db.schema.typedefs" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local routes_definition = require "kong.db.schema.entities.routes" local services_definition = require "kong.db.schema.entities.services" local consumers_definition = require "kong.db.schema.entities.consumers" @@ -78,7 +78,7 @@ describe("plugins", function() -- Success local plugin = { name = "key-auth", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, config = { key_names = { "x-kong-key" } } @@ -91,7 +91,7 @@ describe("plugins", function() -- Failure plugin = { name = "rate-limiting", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, config = { second = "hello" } @@ -112,7 +112,7 @@ describe("plugins", function() -- Insert key-auth, whose config has some default values that should be set local plugin = { name = "key-auth", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, } plugin = Plugins:process_auto_fields(plugin) local ok = Plugins:validate(plugin) @@ -133,7 +133,7 @@ describe("plugins", function() -- Insert response-transformer, whose default config has no default values, and should be empty local plugin = { name = "response-transformer", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, } plugin = Plugins:process_auto_fields(plugin) local ok = Plugins:validate(plugin) @@ -182,7 +182,7 @@ describe("plugins", function() local ok, err = Plugins:validate(Plugins:process_auto_fields({ name = "with-no-route", - route = { id = utils.uuid() }, + route = { id = uuid.uuid() }, config = { string = "foo", } @@ -219,7 +219,7 @@ describe("plugins", function() local ok, err = Plugins:validate(Plugins:process_auto_fields({ name = "with-no-service", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, config = { string = "foo", } @@ -256,7 +256,7 @@ describe("plugins", function() local ok, err = Plugins:validate(Plugins:process_auto_fields({ name = "with-no-consumer", - consumer = { id = utils.uuid() }, + consumer = { id = uuid.uuid() }, config = { string = "foo", } @@ -279,21 +279,21 @@ describe("plugins", function() it("accepts a plugin if configured for route", function() assert(Plugins:validate(Plugins:process_auto_fields({ name = "key-auth", - route = { id = utils.uuid() }, + route = { id = uuid.uuid() }, }))) end) it("accepts a plugin if configured for service", function() assert(Plugins:validate(Plugins:process_auto_fields({ name = "key-auth", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, }))) end) it("accepts a plugin if configured for consumer", function() assert(Plugins:validate(Plugins:process_auto_fields({ name = "rate-limiting", - consumer = { id = utils.uuid() }, + consumer = { id = uuid.uuid() }, config = { second = 1, } diff --git a/spec/01-unit/01-db/01-schema/08-targets_spec.lua b/spec/01-unit/01-db/01-schema/08-targets_spec.lua index fb08ade2a428..d791f119d13d 100644 --- a/spec/01-unit/01-db/01-schema/08-targets_spec.lua +++ b/spec/01-unit/01-db/01-schema/08-targets_spec.lua @@ -2,7 +2,7 @@ local Schema = require "kong.db.schema" local targets = require "kong.db.schema.entities.targets" local certificates = require "kong.db.schema.entities.certificates" local upstreams = require "kong.db.schema.entities.upstreams" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local function setup_global_env() _G.kong = _G.kong or {} @@ -32,7 +32,7 @@ describe("targets", function() setup_global_env() describe("targets.target", function() it("validates", function() - local upstream = { id = utils.uuid() } + local upstream = { id = uuid.uuid() } local targets = { "valid.name", "valid.name:8080", "12.34.56.78", "1.2.3.4:123" } for _, target in ipairs(targets) do local ok, err = validate({ target = target, upstream = upstream }) diff --git a/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua b/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua index 9bdba912e43a..a869822e847e 100644 --- a/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua +++ b/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua @@ -3,7 +3,7 @@ local helpers = require "spec.helpers" local lyaml = require "lyaml" local cjson = require "cjson" local tablex = require "pl.tablex" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local null = ngx.null @@ -48,7 +48,7 @@ local function idempotent(tbl, err) local function recurse_fields(t) helpers.deep_sort(t) for k,v in sortedpairs(t) do - if k == "id" and utils.is_valid_uuid(v) then + if k == "id" and uuid.is_valid_uuid(v) then t[k] = "UUID" end if k == "client_id" or k == "client_secret" or k == "access_token" then diff --git a/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua b/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua index 7ceb873ebe5f..52e47441f8c1 100644 --- a/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua +++ b/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua @@ -6,7 +6,7 @@ local null = ngx.null local helpers = require "spec.helpers" local tablex = require "pl.tablex" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local function sort_by_key(t) return function(a, b) @@ -48,7 +48,7 @@ local function idempotent(tbl, err) local function recurse_fields(t) helpers.deep_sort(t) for k,v in sortedpairs(t) do - if k == "id" and utils.is_valid_uuid(v) then + if k == "id" and uuid.is_valid_uuid(v) then t[k] = "UUID" end if k == "client_id" or k == "client_secret" or k == "access_token" then diff --git a/spec/01-unit/01-db/01-schema/11-snis_spec.lua b/spec/01-unit/01-db/01-schema/11-snis_spec.lua index a5fdfa05ccaa..e7dac570e885 100644 --- a/spec/01-unit/01-db/01-schema/11-snis_spec.lua +++ b/spec/01-unit/01-db/01-schema/11-snis_spec.lua @@ -1,7 +1,7 @@ local Schema = require "kong.db.schema" local snis = require "kong.db.schema.entities.snis" local certificates = require "kong.db.schema.entities.certificates" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" Schema.new(certificates) local Snis = assert(Schema.new(snis)) @@ -27,7 +27,7 @@ end describe("snis", function() - local certificate = { id = utils.uuid() } + local certificate = { id = uuid.uuid() } setup_global_env() diff --git a/spec/01-unit/05-utils_spec.lua b/spec/01-unit/05-utils_spec.lua index ea467264b0af..2a65ea7bc850 100644 --- a/spec/01-unit/05-utils_spec.lua +++ b/spec/01-unit/05-utils_spec.lua @@ -56,6 +56,7 @@ describe("Utils", function() end) describe("is_valid_uuid()", function() + local utils = require "kong.tools.uuid" it("validates UUIDs from jit-uuid", function() assert.True (utils.is_valid_uuid("cbb297c0-a956-486d-ad1d-f9b42df9465a")) assert.False(utils.is_valid_uuid("cbb297c0-a956486d-ad1d-f9b42df9465a")) diff --git a/spec/01-unit/08-router_spec.lua b/spec/01-unit/08-router_spec.lua index 025120392ecf..1b164904f4e2 100644 --- a/spec/01-unit/08-router_spec.lua +++ b/spec/01-unit/08-router_spec.lua @@ -1,6 +1,6 @@ local Router local path_handling_tests = require "spec.fixtures.router_path_handling_tests" -local uuid = require("kong.tools.utils").uuid +local uuid = require("kong.tools.uuid").uuid local get_expression = require("kong.router.transform").get_expression local deep_copy = require("kong.tools.table").deep_copy diff --git a/spec/01-unit/09-balancer/01-generic_spec.lua b/spec/01-unit/09-balancer/01-generic_spec.lua index 6d2c6c1f38ca..ec4c58f1c60c 100644 --- a/spec/01-unit/09-balancer/01-generic_spec.lua +++ b/spec/01-unit/09-balancer/01-generic_spec.lua @@ -7,9 +7,9 @@ local dnsA = function(...) return helpers.dnsA(client, ...) end local dnsExpire = helpers.dnsExpire local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local hc_defaults = { active = { diff --git a/spec/01-unit/09-balancer/02-least_connections_spec.lua b/spec/01-unit/09-balancer/02-least_connections_spec.lua index 3617070d4309..3db545dec093 100644 --- a/spec/01-unit/09-balancer/02-least_connections_spec.lua +++ b/spec/01-unit/09-balancer/02-least_connections_spec.lua @@ -1,9 +1,9 @@ local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local client, balancers, targets diff --git a/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua b/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua index 3e7566755624..17f46f46fa5b 100644 --- a/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua +++ b/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua @@ -11,9 +11,9 @@ local targets, balancers require "spec.helpers" -- initialize db local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local helpers = require "spec.helpers.dns" local gettime = helpers.gettime diff --git a/spec/01-unit/09-balancer/04-round_robin_spec.lua b/spec/01-unit/09-balancer/04-round_robin_spec.lua index 17fe3b837783..35f63f2c4522 100644 --- a/spec/01-unit/09-balancer/04-round_robin_spec.lua +++ b/spec/01-unit/09-balancer/04-round_robin_spec.lua @@ -9,9 +9,9 @@ local targets, balancers local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local helpers = require "spec.helpers.dns" local gettime = helpers.gettime diff --git a/spec/01-unit/09-balancer/05-worker_consistency_spec.lua b/spec/01-unit/09-balancer/05-worker_consistency_spec.lua index 18784b4690c8..3dd7d3714358 100644 --- a/spec/01-unit/09-balancer/05-worker_consistency_spec.lua +++ b/spec/01-unit/09-balancer/05-worker_consistency_spec.lua @@ -1,9 +1,8 @@ -local utils = require "kong.tools.utils" local mocker = require "spec.fixtures.mocker" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy -local ws_id = utils.uuid() +local ws_id = require("kong.tools.uuid").uuid() local function setup_it_block(consistency) diff --git a/spec/01-unit/09-balancer/06-latency_spec.lua b/spec/01-unit/09-balancer/06-latency_spec.lua index 1a0945e9c4a8..89def3b45299 100644 --- a/spec/01-unit/09-balancer/06-latency_spec.lua +++ b/spec/01-unit/09-balancer/06-latency_spec.lua @@ -1,9 +1,9 @@ local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local client, balancers, targets diff --git a/spec/01-unit/14-dns_spec.lua b/spec/01-unit/14-dns_spec.lua index 3be181652ee4..fda591d4df64 100644 --- a/spec/01-unit/14-dns_spec.lua +++ b/spec/01-unit/14-dns_spec.lua @@ -1,8 +1,8 @@ local mocker = require "spec.fixtures.mocker" local balancer = require "kong.runloop.balancer" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local function setup_it_block() local client = require "kong.resty.dns.client" diff --git a/spec/01-unit/27-queue_spec.lua b/spec/01-unit/27-queue_spec.lua index 878d0f85892f..8960d5076198 100644 --- a/spec/01-unit/27-queue_spec.lua +++ b/spec/01-unit/27-queue_spec.lua @@ -1,10 +1,10 @@ local Queue = require "kong.tools.queue" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy -local utils = require "kong.tools.utils" local helpers = require "spec.helpers" local mocker = require "spec.fixtures.mocker" local timerng = require "resty.timerng" local queue_schema = require "kong.tools.queue_schema" +local uuid = require("kong.tools.uuid").uuid local queue_num = 1 @@ -71,7 +71,7 @@ describe("plugin queue", function() err = function(message) return log('ERR', message) end, }, plugin = { - get_id = function () return utils.uuid() end, + get_id = function () return uuid() end, }, }, ngx = { @@ -128,7 +128,7 @@ describe("plugin queue", function() it("displays log_tag in log entries", function () local handler_invoked - local log_tag = utils.uuid() + local log_tag = uuid() Queue.enqueue( queue_conf({ name = "log-tag", log_tag = log_tag }), function () diff --git a/spec/02-integration/03-db/02-db_core_entities_spec.lua b/spec/02-integration/03-db/02-db_core_entities_spec.lua index 0dedb916f6b0..51e1c147a730 100644 --- a/spec/02-integration/03-db/02-db_core_entities_spec.lua +++ b/spec/02-integration/03-db/02-db_core_entities_spec.lua @@ -1,6 +1,6 @@ local Errors = require "kong.db.errors" local defaults = require "kong.db.strategies.connector".defaults -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local helpers = require "spec.helpers" local cjson = require "cjson" local ssl_fixtures = require "spec.fixtures.ssl" @@ -604,7 +604,7 @@ for _, strategy in helpers.each_strategy() do end) it("cannot insert if foreign primary_key is invalid", function() - local fake_id = utils.uuid() + local fake_id = uuid.uuid() local credentials, _, err_t = db.basicauth_credentials:insert({ username = "peter", password = "pan", @@ -618,7 +618,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("cannot insert if foreign Service does not exist", function() - local u = utils.uuid() + local u = uuid.uuid() local service = { id = u } @@ -687,7 +687,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(route) assert.is_number(route.created_at) assert.is_number(route.updated_at) - assert.is_true(utils.is_valid_uuid(route.id)) + assert.is_true(uuid.is_valid_uuid(route.id)) assert.same({ id = route.id, @@ -731,7 +731,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(route) assert.is_number(route.created_at) assert.is_number(route.updated_at) - assert.is_true(utils.is_valid_uuid(route.id)) + assert.is_true(uuid.is_valid_uuid(route.id)) assert.same({ id = route.id, @@ -773,7 +773,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(route) assert.is_number(route.created_at) assert.is_number(route.updated_at) - assert.is_true(utils.is_valid_uuid(route.id)) + assert.is_true(uuid.is_valid_uuid(route.id)) assert.same({ id = route.id, @@ -985,7 +985,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("return nothing on non-existing Route", function() - local route, err, err_t = db.routes:select({ id = utils.uuid() }) + local route, err, err_t = db.routes:select({ id = uuid.uuid() }) assert.is_nil(route) assert.is_nil(err_t) assert.is_nil(err) @@ -1060,7 +1060,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local pk = { id = utils.uuid() } + local pk = { id = uuid.uuid() } local new_route, err, err_t = db.routes:update(pk, { protocols = { "https" }, hosts = { "example.com" }, @@ -1274,7 +1274,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing if the Route does not exist", function() - local u = utils.uuid() + local u = uuid.uuid() local ok, err, err_t = db.routes:delete({ id = u }) @@ -1354,7 +1354,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(service) assert.is_number(service.created_at) assert.is_number(service.updated_at) - assert.is_true(utils.is_valid_uuid(service.id)) + assert.is_true(uuid.is_valid_uuid(service.id)) assert.same({ id = service.id, @@ -1401,7 +1401,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(service) assert.is_number(service.created_at) assert.is_number(service.updated_at) - assert.is_true(utils.is_valid_uuid(service.id)) + assert.is_true(uuid.is_valid_uuid(service.id)) assert.same({ id = service.id, @@ -1601,7 +1601,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing on non-existing Service", function() local service, err, err_t = db.services:select({ - id = utils.uuid() + id = uuid.uuid() }) assert.is_nil(err_t) assert.is_nil(err) @@ -1682,7 +1682,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local pk = { id = utils.uuid() } + local pk = { id = uuid.uuid() } local service, err, err_t = db.services:update(pk, { protocol = "http" }) assert.is_nil(service) local message = fmt( @@ -1863,7 +1863,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing if the Service does not exist", function() - local u = utils.uuid() + local u = uuid.uuid() local ok, err, err_t = db.services:delete({ id = u }) @@ -2010,7 +2010,7 @@ for _, strategy in helpers.each_strategy() do it(":update() cannot attach a Route to a non-existing Service", function() local service = { - id = utils.uuid() + id = uuid.uuid() } local route = bp.routes:insert({ diff --git a/spec/02-integration/03-db/07-tags_spec.lua b/spec/02-integration/03-db/07-tags_spec.lua index 2327a15bce7b..86f93d52ed8a 100644 --- a/spec/02-integration/03-db/07-tags_spec.lua +++ b/spec/02-integration/03-db/07-tags_spec.lua @@ -190,7 +190,7 @@ for _, strategy in helpers.each_strategy() do -- note this is different from test "update row in tags table with" -- as this test actually creates new records local scenarios = { - { "upsert", { id = require("kong.tools.utils").uuid() }, { "service-upsert-1" } }, + { "upsert", { id = require("kong.tools.uuid").uuid() }, { "service-upsert-1" } }, { "upsert_by_name", "service-upsert-2", { "service-upsert-2" } }, } for _, scenario in pairs(scenarios) do diff --git a/spec/02-integration/03-db/10-db_unique_foreign_spec.lua b/spec/02-integration/03-db/10-db_unique_foreign_spec.lua index 8a154b0b1e1c..7ab5ba0d054c 100644 --- a/spec/02-integration/03-db/10-db_unique_foreign_spec.lua +++ b/spec/02-integration/03-db/10-db_unique_foreign_spec.lua @@ -1,6 +1,6 @@ local Errors = require "kong.db.errors" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local fmt = string.format @@ -78,7 +78,7 @@ for _, strategy in helpers.each_strategy() do it("returns nothing on non-existing Unique Foreign", function() for i = 1, 5 do local unique_reference, err, err_t = db.unique_references:select_by_unique_foreign({ - id = utils.uuid() + id = uuid.uuid() }) assert.is_nil(err) @@ -116,7 +116,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local unique_reference, err, err_t = db.unique_references:update_by_unique_foreign({ id = uuid, }, { @@ -193,7 +193,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local unique_reference, err, err_t = db.unique_references:upsert_by_unique_foreign({ id = uuid, }, { @@ -305,7 +305,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing if the Unique Foreign does not exist", function() local ok, err, err_t = db.unique_references:delete_by_unique_foreign({ - id = utils.uuid() + id = uuid.uuid() }) assert.is_true(ok) assert.is_nil(err_t) diff --git a/spec/02-integration/03-db/14-dao_spec.lua b/spec/02-integration/03-db/14-dao_spec.lua index d71d59dc1bac..313ebd9bd650 100644 --- a/spec/02-integration/03-db/14-dao_spec.lua +++ b/spec/02-integration/03-db/14-dao_spec.lua @@ -1,7 +1,7 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local declarative = require "kong.db.declarative" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy +local uuid = require("kong.tools.uuid").uuid -- Note: include "off" strategy here as well for _, strategy in helpers.all_strategies() do @@ -162,7 +162,7 @@ for _, strategy in helpers.all_strategies() do -- new plugin upsert (insert part of upsert) local new_plugin_config = { - id = utils.uuid(), + id = uuid(), enabled = true, name = "rate-limiting", instance_name = 'rate-limiting-instance-2', diff --git a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua index d5251bd7c676..06fbb8968899 100644 --- a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua +++ b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua @@ -2,7 +2,7 @@ local helpers = require "spec.helpers" local cjson = require "cjson" local escape = require("socket.url").escape local Errors = require "kong.db.errors" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local function it_content_types(title, fn) @@ -267,7 +267,7 @@ describe("Admin API (#" .. strategy .. "): ", function() assert.same(c, json.data[1]) end) it("allows filtering by uuid-like custom_id", function() - local custom_id = utils.uuid() + local custom_id = uuid.uuid() local c = bp.consumers:insert({ custom_id = custom_id }, { nulls = true }) local res = client:get("/consumers?custom_id=" .. custom_id) @@ -472,7 +472,7 @@ describe("Admin API (#" .. strategy .. "): ", function() it_content_types("creates if not exists", function(content_type) return function() local custom_id = gensym() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/consumers/" .. id, { body = { custom_id = custom_id }, headers = { ["Content-Type"] = content_type } @@ -556,7 +556,7 @@ describe("Admin API (#" .. strategy .. "): ", function() it_content_types("handles invalid input", function(content_type) return function() -- Missing params - local res = client:put("/consumers/" .. utils.uuid(), { + local res = client:put("/consumers/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = content_type } }) @@ -954,7 +954,7 @@ describe("Admin API (#" .. strategy .. "): ", function() for content_type, input in pairs(inputs) do it("creates if not found with " .. content_type, function() local consumer = bp.consumers:insert() - local plugin_id = utils.uuid() + local plugin_id = uuid.uuid() local res = assert(client:send { method = "PUT", diff --git a/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua b/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua index f1f52be07870..f59c2fa61e92 100644 --- a/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua +++ b/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local admin_api = require "spec.fixtures.admin_api" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" for _, strategy in helpers.each_strategy() do @@ -187,7 +187,7 @@ for _, strategy in helpers.each_strategy() do }) local res = assert(client:send { method = "PUT", - path = "/plugins/" .. utils.uuid(), + path = "/plugins/" .. uuid.uuid(), body = { name = "key-auth", service = { @@ -201,7 +201,7 @@ for _, strategy in helpers.each_strategy() do it("can create a plugin by instance_name", function() local service = admin_api.services:insert() - local instance_name = "name-" .. utils.uuid() + local instance_name = "name-" .. uuid.uuid() local res = assert(client:send { method = "PUT", path = "/plugins/" .. instance_name, @@ -221,7 +221,7 @@ for _, strategy in helpers.each_strategy() do it("can upsert a plugin by instance_name", function() -- create a plugin by instance_name local service = admin_api.services:insert() - local instance_name = "name-" .. utils.uuid() + local instance_name = "name-" .. uuid.uuid() local plugin_id local res = assert(client:send { method = "PUT", diff --git a/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua b/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua index 848885c81670..c0fde48646cd 100644 --- a/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua +++ b/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua @@ -1,7 +1,7 @@ local ssl_fixtures = require "spec.fixtures.ssl" local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local Errors = require "kong.db.errors" @@ -341,7 +341,7 @@ describe("Admin API: #" .. strategy, function() end) it("returns 404 for a random non-existing uuid", function() - local res = client:get("/certificates/" .. utils.uuid()) + local res = client:get("/certificates/" .. uuid.uuid()) assert.res_status(404, res) end) @@ -354,7 +354,7 @@ describe("Admin API: #" .. strategy, function() describe("PUT", function() it("creates if not found", function() local n1 = get_name() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/certificates/" .. id, { body = { cert = ssl_fixtures.cert, @@ -478,7 +478,7 @@ describe("Admin API: #" .. strategy, function() it("handles invalid input", function() -- Missing params - local res = client:put("/certificates/" .. utils.uuid(), { + local res = client:put("/certificates/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = "application/json" } }) @@ -496,7 +496,7 @@ describe("Admin API: #" .. strategy, function() it("handles invalid input with alternate certificate", function() -- Missing params - local res = client:put("/certificates/" .. utils.uuid(), { + local res = client:put("/certificates/" .. uuid.uuid(), { body = { cert = ssl_fixtures.cert, key = ssl_fixtures.key, @@ -788,7 +788,7 @@ describe("Admin API: #" .. strategy, function() it("returns 404 for a random non-existing id", function() local n1 = get_name() - local res = client:patch("/certificates/" .. utils.uuid(), { + local res = client:patch("/certificates/" .. uuid.uuid(), { body = { cert = ssl_fixtures.cert, key = ssl_fixtures.key, @@ -1206,7 +1206,7 @@ describe("Admin API: #" .. strategy, function() it("creates if not found", function() local certificate = add_certificate() local n1 = get_name() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/snis/" .. id, { body = { certificate = { id = certificate.id }, @@ -1251,7 +1251,7 @@ describe("Admin API: #" .. strategy, function() it("handles invalid input", function() -- Missing params - local res = client:put("/snis/" .. utils.uuid(), { + local res = client:put("/snis/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = "application/json" } }) diff --git a/spec/02-integration/04-admin_api/08-targets_routes_spec.lua b/spec/02-integration/04-admin_api/08-targets_routes_spec.lua index 3f58cf6024e0..10d39ed3a03d 100644 --- a/spec/02-integration/04-admin_api/08-targets_routes_spec.lua +++ b/spec/02-integration/04-admin_api/08-targets_routes_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local tablex = require "pl.tablex" local function it_content_types(title, fn) @@ -797,8 +797,8 @@ describe("Admin API #" .. strategy, function() end) it("checks every combination of valid and invalid upstream and target", function() - for i, u in ipairs({ utils.uuid(), "invalid", upstream.name, upstream.id }) do - for j, t in ipairs({ utils.uuid(), "invalid:1234", wrong_target.id, target.target, target.id }) do + for i, u in ipairs({ uuid.uuid(), "invalid", upstream.name, upstream.id }) do + for j, t in ipairs({ uuid.uuid(), "invalid:1234", wrong_target.id, target.target, target.id }) do for _, e in ipairs({ "healthy", "unhealthy" }) do local expected = (i >= 3 and j >= 4) and 204 or 404 local path = "/upstreams/" .. u .. "/targets/" .. t .. "/" .. e diff --git a/spec/02-integration/04-admin_api/09-routes_routes_spec.lua b/spec/02-integration/04-admin_api/09-routes_routes_spec.lua index e358bf1d7062..3746e8c53bf0 100644 --- a/spec/02-integration/04-admin_api/09-routes_routes_spec.lua +++ b/spec/02-integration/04-admin_api/09-routes_routes_spec.lua @@ -1,5 +1,5 @@ local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local helpers = require "spec.helpers" local Errors = require "kong.db.errors" @@ -668,7 +668,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/routes/" .. utils.uuid()) + local res = client:get("/routes/" .. uuid.uuid()) assert.res_status(404, res) end) @@ -709,7 +709,7 @@ for _, strategy in helpers.each_strategy() do end local service = bp.services:insert() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/routes/" .. id, { headers = { ["Content-Type"] = content_type @@ -738,7 +738,7 @@ for _, strategy in helpers.each_strategy() do return end - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/routes/" .. id, { headers = { ["Content-Type"] = content_type @@ -896,7 +896,7 @@ for _, strategy in helpers.each_strategy() do end -- Missing params - local res = client:put("/routes/" .. utils.uuid(), { + local res = client:put("/routes/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = content_type } }) @@ -916,7 +916,7 @@ for _, strategy in helpers.each_strategy() do }, cjson.decode(body)) -- Invalid parameter - res = client:put("/routes/" .. utils.uuid(), { + res = client:put("/routes/" .. uuid.uuid(), { body = { methods = { "GET" }, protocols = { "foo", "http" }, @@ -1242,7 +1242,7 @@ for _, strategy in helpers.each_strategy() do return end - local res = client:patch("/routes/" .. utils.uuid(), { + local res = client:patch("/routes/" .. uuid.uuid(), { headers = { ["Content-Type"] = content_type }, @@ -1309,7 +1309,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it("returns HTTP 204 even if not found", function() - local res = client:delete("/routes/" .. utils.uuid()) + local res = client:delete("/routes/" .. uuid.uuid()) assert.res_status(204, res) end) end) @@ -1342,7 +1342,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/routes/" .. utils.uuid() .. "/service") + local res = client:get("/routes/" .. uuid.uuid() .. "/service") assert.res_status(404, res) end) @@ -1461,7 +1461,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it_content_types("returns 404 if not found", function(content_type) return function() - local res = client:patch("/routes/" .. utils.uuid() .. "/service", { + local res = client:patch("/routes/" .. uuid.uuid() .. "/service", { headers = { ["Content-Type"] = content_type }, @@ -1511,7 +1511,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns HTTP 404 with non-existing route", function() - local res = client:delete("/routes/" .. utils.uuid() .. "/service") + local res = client:delete("/routes/" .. uuid.uuid() .. "/service") assert.res_status(404, res) end) @@ -1645,7 +1645,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it_content_types("returns 404 if not found", function(content_type) return function() - local res = client:put("/routes/" .. utils.uuid() .. "/service", { + local res = client:put("/routes/" .. uuid.uuid() .. "/service", { headers = { ["Content-Type"] = content_type }, @@ -1902,7 +1902,7 @@ for _, strategy in helpers.each_strategy() do hosts = { "example.test" }, }) local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), route = route, }) local res = client:get("/routes/" .. route.id .. "/plugins/" .. plugin.instance_name) @@ -1915,7 +1915,7 @@ for _, strategy in helpers.each_strategy() do describe("DELETE", function() it("deletes a plugin by id", function() - local route = bp.routes:insert({ paths = { "/route-" .. utils.uuid() }}) + local route = bp.routes:insert({ paths = { "/route-" .. uuid.uuid() }}) local plugin = bp.key_auth_plugins:insert({ route = route, }) @@ -1927,9 +1927,9 @@ for _, strategy in helpers.each_strategy() do assert.is_nil(in_db) end) it("deletes a plugin by instance_name", function() - local route = bp.routes:insert({ paths = { "/route-" .. utils.uuid() }}) + local route = bp.routes:insert({ paths = { "/route-" .. uuid.uuid() }}) local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), route = route, }) local res = assert(client:delete("/routes/" .. route.id .. "/plugins/" .. plugin.instance_name)) diff --git a/spec/02-integration/04-admin_api/10-services_routes_spec.lua b/spec/02-integration/04-admin_api/10-services_routes_spec.lua index 32dbcd052ff3..8588e71b0c51 100644 --- a/spec/02-integration/04-admin_api/10-services_routes_spec.lua +++ b/spec/02-integration/04-admin_api/10-services_routes_spec.lua @@ -1,5 +1,5 @@ local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local helpers = require "spec.helpers" local Errors = require "kong.db.errors" @@ -272,7 +272,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/services/" .. utils.uuid()) + local res = client:get("/services/" .. uuid.uuid()) assert.res_status(404, res) end) @@ -454,7 +454,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it("returns HTTP 204 even if not found", function() - local res = client:delete("/services/" .. utils.uuid()) + local res = client:delete("/services/" .. uuid.uuid()) assert.res_status(204, res) end) @@ -814,7 +814,7 @@ for _, strategy in helpers.each_strategy() do it("retrieves a plugin by instance_name", function() local service = bp.services:insert() local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), service = service, }) local res = client:get("/services/" .. service.id .. "/plugins/" .. plugin.instance_name) @@ -841,7 +841,7 @@ for _, strategy in helpers.each_strategy() do it("deletes a plugin by instance_name", function() local service = bp.services:insert() local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), service = service, }) local res = assert(client:delete("/services/" .. service.id .. "/plugins/" .. plugin.instance_name)) diff --git a/spec/02-integration/04-admin_api/15-off_spec.lua b/spec/02-integration/04-admin_api/15-off_spec.lua index b4acd359d301..069a51b4b829 100644 --- a/spec/02-integration/04-admin_api/15-off_spec.lua +++ b/spec/02-integration/04-admin_api/15-off_spec.lua @@ -1,6 +1,5 @@ local cjson = require "cjson" local lyaml = require "lyaml" -local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local pl_utils = require "pl.utils" local helpers = require "spec.helpers" @@ -11,6 +10,7 @@ local inspect = require "inspect" local nkeys = require "table.nkeys" local typedefs = require "kong.db.schema.typedefs" local schema = require "kong.db.schema" +local uuid = require("kong.tools.uuid").uuid local WORKER_SYNC_TIMEOUT = 10 local LMDB_MAP_SIZE = "10m" @@ -84,7 +84,7 @@ describe("Admin API #off", function() body = { protocols = { "http" }, hosts = { "my.route.test" }, - service = { id = utils.uuid() }, + service = { id = uuid() }, }, headers = { ["Content-Type"] = content_type } }) @@ -111,7 +111,7 @@ describe("Admin API #off", function() methods = { "GET", "POST", "PATCH" }, hosts = { "foo.api.test", "bar.api.test" }, paths = { "/foo", "/bar" }, - service = { id = utils.uuid() }, + service = { id = uuid() }, }, headers = { ["Content-Type"] = content_type } }) @@ -160,7 +160,7 @@ describe("Admin API #off", function() path = "/routes", body = { paths = { "/" }, - service = { id = utils.uuid() } + service = { id = uuid() } }, headers = { ["Content-Type"] = "application/json" @@ -188,10 +188,10 @@ describe("Admin API #off", function() for i = 1, #methods do local res = assert(client:send { method = methods[i], - path = "/routes/" .. utils.uuid(), + path = "/routes/" .. uuid(), body = { paths = { "/" }, - service = { id = utils.uuid() } + service = { id = uuid() } }, headers = { ["Content-Type"] = "application/json" diff --git a/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua b/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua index afb94cfe24ac..4bb758634dd9 100644 --- a/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua +++ b/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local Errors = require "kong.db.errors" @@ -99,7 +99,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/foreign-references/" .. utils.uuid() .. "/same") + local res = client:get("/foreign-references/" .. uuid.uuid() .. "/same") assert.res_status(404, res) end) @@ -190,7 +190,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it_content_types("returns 404 if not found", function(content_type) return function() - local res = client:patch("/foreign-references/" .. utils.uuid() .. "/same", { + local res = client:patch("/foreign-references/" .. uuid.uuid() .. "/same", { headers = { ["Content-Type"] = content_type }, @@ -245,12 +245,12 @@ for _, strategy in helpers.each_strategy() do end) it("returns HTTP 404 with non-existing foreign entity ", function() - local res = client:delete("/foreign-entities/" .. utils.uuid() .. "/foreign-references/" .. utils.uuid()) + local res = client:delete("/foreign-entities/" .. uuid.uuid() .. "/foreign-references/" .. uuid.uuid()) assert.res_status(404, res) end) it("returns HTTP 404 with non-existing foreign reference", function() - local res = client:delete("/foreign-references/" .. utils.uuid() .. "/same") + local res = client:delete("/foreign-references/" .. uuid.uuid() .. "/same") assert.res_status(404, res) end) diff --git a/spec/02-integration/04-admin_api/19-vaults_spec.lua b/spec/02-integration/04-admin_api/19-vaults_spec.lua index 08063e30fe07..1f0a48bcd8a7 100644 --- a/spec/02-integration/04-admin_api/19-vaults_spec.lua +++ b/spec/02-integration/04-admin_api/19-vaults_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" @@ -103,7 +103,7 @@ for _, strategy in helpers.each_strategy() do describe("PUT", function() it("can create a vault by id", function() - local res = client:put("/vaults/" .. utils.uuid(), { + local res = client:put("/vaults/" .. uuid.uuid(), { headers = HEADERS, body = { name = "env", @@ -151,7 +151,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it("handles invalid input by id", function() - local res = client:put("/vaults/" .. utils.uuid(), { + local res = client:put("/vaults/" .. uuid.uuid(), { headers = HEADERS, body = { name = "env", diff --git a/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua b/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua index 5f729b221947..09551259bad8 100644 --- a/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua +++ b/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" local pl_path = require "pl.path" local pl_file = require "pl.file" @@ -415,7 +415,7 @@ for _, strategy in helpers.each_strategy() do end) it("execute a log plugin", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -470,7 +470,7 @@ for _, strategy in helpers.each_strategy() do -- regression test for bug spotted in 0.12.0rc2 it("responses.send stops plugin but runloop continues", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -766,7 +766,7 @@ for _, strategy in helpers.each_strategy() do it("executes a log plugin on Bad Gateway (HTTP 502)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -787,7 +787,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 502)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", @@ -818,7 +818,7 @@ for _, strategy in helpers.each_strategy() do it("executes a log plugin on Service Unavailable (HTTP 503)", function() -- Does not trigger error_page directive (no proxy_intercept_errors) - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -839,7 +839,7 @@ for _, strategy in helpers.each_strategy() do it("executes a log plugin on Gateway Timeout (HTTP 504)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -860,7 +860,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 504)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", @@ -891,7 +891,7 @@ for _, strategy in helpers.each_strategy() do it("executes a global log plugin on Nginx-produced client errors (HTTP 400)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -919,7 +919,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 400)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", @@ -954,7 +954,7 @@ for _, strategy in helpers.each_strategy() do it("executes a global log plugin on Nginx-produced client errors (HTTP 414)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -982,7 +982,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 414)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", diff --git a/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua b/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua index 9de7aacc4f18..0d3872c093c8 100644 --- a/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua +++ b/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua @@ -1,7 +1,7 @@ local bu = require "spec.fixtures.balancer_utils" local cjson = require "cjson" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local https_server = helpers.https_server @@ -1099,7 +1099,7 @@ for _, strategy in helpers.each_strategy() do local api_host, service_id = bu.add_api(bp, upstream_name, { connect_timeout = 50, }) -- add a plugin - local plugin_id = utils.uuid() + local plugin_id = uuid.uuid() bp.plugins:insert({ id = plugin_id, service = { id = service_id }, diff --git a/spec/02-integration/05-proxy/14-server_tokens_spec.lua b/spec/02-integration/05-proxy/14-server_tokens_spec.lua index 6cee745a1354..95447d9b371e 100644 --- a/spec/02-integration/05-proxy/14-server_tokens_spec.lua +++ b/spec/02-integration/05-proxy/14-server_tokens_spec.lua @@ -2,7 +2,7 @@ local meta = require "kong.meta" local helpers = require "spec.helpers" local constants = require "kong.constants" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require("kong.tools.uuid").uuid local default_server_header = meta._SERVER_TOKENS @@ -455,7 +455,7 @@ describe("headers [#" .. strategy .. "]", function() if strategy ~= "off" then it("should not be returned when plugin errors on rewrite phase", function() local admin_client = helpers.admin_client() - local uuid = utils.uuid() + local uuid = uuid() local res = assert(admin_client:send { method = "PUT", path = "/plugins/" .. uuid, diff --git a/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua b/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua index e0ab5ccba749..c61794489324 100644 --- a/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua +++ b/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua @@ -1,6 +1,6 @@ local cjson = require "cjson" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require("kong.tools.uuid").uuid local POLL_INTERVAL = 0.3 @@ -273,7 +273,7 @@ for _, strategy in helpers.each_strategy() do -- A regression test for https://github.com/Kong/kong/issues/4191 local admin_res_plugin = assert(admin_client_1:send { method = "PUT", - path = "/plugins/" .. utils.uuid(), + path = "/plugins/" .. uuid(), body = { name = "dummy", service = { id = service_fixture.id }, diff --git a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua index 0573be38d667..71bb46ead473 100644 --- a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua +++ b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua @@ -1,5 +1,4 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson.safe" local _VERSION_TABLE = require "kong.meta" ._VERSION_TABLE local MAJOR = _VERSION_TABLE.major @@ -7,6 +6,7 @@ local MINOR = _VERSION_TABLE.minor local PATCH = _VERSION_TABLE.patch local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy +local uuid = require("kong.tools.uuid").uuid local KEY_AUTH_PLUGIN @@ -480,7 +480,7 @@ describe("CP/DP #version check #" .. strategy, function() for desc, harness in pairs(allowed_cases) do it(desc .. ", sync is allowed", function() - local uuid = utils.uuid() + local uuid = uuid() local res = assert(helpers.clustering_client({ host = "127.0.0.1", @@ -567,7 +567,7 @@ describe("CP/DP #version check #" .. strategy, function() for desc, harness in pairs(blocked_cases) do it(desc ..", sync is blocked", function() - local uuid = utils.uuid() + local uuid = uuid() local res, err = helpers.clustering_client({ host = "127.0.0.1", 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 1c8f7bd26ee5..53d21bf08a0d 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 @@ -1,8 +1,8 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy +local uuid = require("kong.tools.uuid").uuid local admin = require "spec.fixtures.admin_api" @@ -20,7 +20,7 @@ local function cluster_client(opts) cert = "spec/fixtures/kong_clustering.crt", cert_key = "spec/fixtures/kong_clustering.key", node_hostname = opts.hostname or "test", - node_id = opts.id or utils.uuid(), + node_id = opts.id or uuid(), node_version = opts.version, node_plugins_list = PLUGIN_LIST, }) @@ -142,7 +142,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected.config.error_code = nil expected.config.error_message = nil expected.config.sync_rate = nil - do_assert(utils.uuid(), "3.0.0", expected) + do_assert(uuid(), "3.0.0", expected) --[[ @@ -153,7 +153,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected = cycle_aware_deep_copy(rate_limit) expected.config.redis = nil expected.config.sync_rate = nil - do_assert(utils.uuid(), "3.2.0", expected) + do_assert(uuid(), "3.2.0", expected) --[[ @@ -164,7 +164,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected = cycle_aware_deep_copy(rate_limit) expected.config.redis = nil expected.config.sync_rate = nil - do_assert(utils.uuid(), "3.3.0", expected) + do_assert(uuid(), "3.3.0", expected) -- cleanup admin.plugins:remove({ id = rate_limit.id }) @@ -191,7 +191,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() local expected = cycle_aware_deep_copy(rate_limit) expected.config.redis = nil - do_assert(utils.uuid(), "3.4.0", expected) + do_assert(uuid(), "3.4.0", expected) -- cleanup admin.plugins:remove({ id = rate_limit.id }) @@ -212,7 +212,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() assert.not_nil(cors.config.private_network) local expected_cors = cycle_aware_deep_copy(cors) expected_cors.config.private_network = nil - do_assert(utils.uuid(), "3.4.0", expected_cors) + do_assert(uuid(), "3.4.0", expected_cors) -- cleanup admin.plugins:remove({ id = cors.id }) @@ -228,7 +228,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() -- ]] } } - do_assert(utils.uuid(), "3.5.0", cors) + do_assert(uuid(), "3.5.0", cors) -- cleanup admin.plugins:remove({ id = cors.id }) @@ -253,7 +253,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_otel_prior_35.config.header_type = "preserve" expected_otel_prior_35.config.sampling_rate = nil expected_otel_prior_35.config.propagation = nil - do_assert(utils.uuid(), "3.4.0", expected_otel_prior_35) + do_assert(uuid(), "3.4.0", expected_otel_prior_35) -- cleanup admin.plugins:remove({ id = opentelemetry.id }) @@ -274,7 +274,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_otel_prior_34.config.header_type = "preserve" expected_otel_prior_34.config.sampling_rate = nil expected_otel_prior_34.config.propagation = nil - do_assert(utils.uuid(), "3.3.0", expected_otel_prior_34) + do_assert(uuid(), "3.3.0", expected_otel_prior_34) -- cleanup admin.plugins:remove({ id = opentelemetry.id }) @@ -300,7 +300,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_zipkin_prior_35.config.header_type = "preserve" expected_zipkin_prior_35.config.default_header_type = "b3" expected_zipkin_prior_35.config.propagation = nil - do_assert(utils.uuid(), "3.4.0", expected_zipkin_prior_35) + do_assert(uuid(), "3.4.0", expected_zipkin_prior_35) -- cleanup admin.plugins:remove({ id = zipkin.id }) @@ -321,7 +321,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_zipkin_prior_34.config.header_type = "preserve" expected_zipkin_prior_34.config.default_header_type = "b3" expected_zipkin_prior_34.config.propagation = nil - do_assert(utils.uuid(), "3.3.0", expected_zipkin_prior_34) + do_assert(uuid(), "3.3.0", expected_zipkin_prior_34) -- cleanup admin.plugins:remove({ id = zipkin.id }) @@ -372,7 +372,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() namespace = "test_namespace", scan_count = 13 } - do_assert(utils.uuid(), "3.5.0", expected_acme_prior_36) + do_assert(uuid(), "3.5.0", expected_acme_prior_36) -- cleanup admin.plugins:remove({ id = acme.id }) @@ -417,7 +417,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_rl_prior_36.config.redis_server_name = "example.test" - do_assert(utils.uuid(), "3.5.0", expected_rl_prior_36) + do_assert(uuid(), "3.5.0", expected_rl_prior_36) -- cleanup admin.plugins:remove({ id = rl.id }) @@ -466,7 +466,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_response_rl_prior_36.config.redis_server_name = "example.test" - do_assert(utils.uuid(), "3.5.0", expected_response_rl_prior_36) + do_assert(uuid(), "3.5.0", expected_response_rl_prior_36) -- cleanup admin.plugins:remove({ id = response_rl.id }) @@ -505,7 +505,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_ai_proxy_prior_37.config.model.options.upstream_path = nil expected_ai_proxy_prior_37.config.route_type = "llm/v1/chat" - do_assert(utils.uuid(), "3.6.0", expected_ai_proxy_prior_37) + do_assert(uuid(), "3.6.0", expected_ai_proxy_prior_37) -- cleanup admin.plugins:remove({ id = ai_proxy.id }) @@ -544,7 +544,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() local expected_ai_request_transformer_prior_37 = cycle_aware_deep_copy(ai_request_transformer) expected_ai_request_transformer_prior_37.config.llm.model.options.upstream_path = nil - do_assert(utils.uuid(), "3.6.0", expected_ai_request_transformer_prior_37) + do_assert(uuid(), "3.6.0", expected_ai_request_transformer_prior_37) -- cleanup admin.plugins:remove({ id = ai_request_transformer.id }) @@ -581,7 +581,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() local expected_ai_response_transformer_prior_37 = cycle_aware_deep_copy(ai_response_transformer) expected_ai_response_transformer_prior_37.config.llm.model.options.upstream_path = nil - do_assert(utils.uuid(), "3.6.0", expected_ai_response_transformer_prior_37) + do_assert(uuid(), "3.6.0", expected_ai_response_transformer_prior_37) -- cleanup admin.plugins:remove({ id = ai_response_transformer.id }) diff --git a/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua b/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua index 2d507dda2fc9..cd67cd502c27 100644 --- a/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua +++ b/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua @@ -1,7 +1,6 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" -local is_valid_uuid = utils.is_valid_uuid +local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid local PREFIX = "servroot.dp" local NODE_ID = PREFIX .. "/kong.id" diff --git a/spec/02-integration/20-wasm/01-admin-api_spec.lua b/spec/02-integration/20-wasm/01-admin-api_spec.lua index ee9c3ce8316a..6ca6d75798c1 100644 --- a/spec/02-integration/20-wasm/01-admin-api_spec.lua +++ b/spec/02-integration/20-wasm/01-admin-api_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local fmt = string.format @@ -99,7 +99,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() local body = assert.response(res).has.jsonbody() assert.is_string(body.id) - assert.truthy(utils.is_valid_uuid(body.id)) + assert.truthy(uuid.is_valid_uuid(body.id)) assert.equals(1, #body.filters) assert.equals("tests", body.filters[1].name) @@ -172,7 +172,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() it("returns 404 if not found", function() assert.response( - admin:get("/filter-chains/" .. utils.uuid()) + admin:get("/filter-chains/" .. uuid.uuid()) ).has.status(404) end) end) @@ -234,7 +234,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() end) - unsupported("POST", "/filter-chains/" .. utils.uuid()) + unsupported("POST", "/filter-chains/" .. uuid.uuid()) end) end -- each { "id", "name" } @@ -270,7 +270,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() local body = assert.response(res).has.jsonbody() assert.is_string(body.id) - assert.truthy(utils.is_valid_uuid(body.id)) + assert.truthy(uuid.is_valid_uuid(body.id)) assert.equals(1, #body.filters) assert.equals("tests", body.filters[1].name) @@ -340,7 +340,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() it("returns 404 if not found", function() assert.response( - admin:get(path .. utils.uuid()) + admin:get(path .. uuid.uuid()) ).has.status(404) end) end) @@ -666,7 +666,7 @@ describe("wasm admin API - wasm = off [#" .. strategy .. "]", function() it("PATCH returns 400", function() assert.response( - admin:patch(path .. "/" .. utils.uuid()), json({ + admin:patch(path .. "/" .. uuid.uuid()), json({ filters = { { name = "tests" } }, service = { id = service.id }, }) @@ -675,7 +675,7 @@ describe("wasm admin API - wasm = off [#" .. strategy .. "]", function() it("PUT returns 400", function() assert.response( - admin:put(path .. "/" .. utils.uuid()), json({ + admin:put(path .. "/" .. uuid.uuid()), json({ filters = { { name = "tests" } }, service = { id = service.id }, }) @@ -684,7 +684,7 @@ describe("wasm admin API - wasm = off [#" .. strategy .. "]", function() it("DELETE returns 400", function() assert.response( - admin:delete(path .. "/" .. utils.uuid()) + admin:delete(path .. "/" .. uuid.uuid()) ).has.status(400) end) diff --git a/spec/02-integration/20-wasm/02-db_spec.lua b/spec/02-integration/20-wasm/02-db_spec.lua index be7e2ec7e2bd..cd3d1ee34652 100644 --- a/spec/02-integration/20-wasm/02-db_spec.lua +++ b/spec/02-integration/20-wasm/02-db_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local schema_lib = require "kong.db.schema.json" local FILTER_PATH = assert(helpers.test_conf.wasm_filters_path) @@ -63,11 +63,11 @@ describe("wasm DB entities [#" .. strategy .. "]", function() })) assert.is_string(chain.id) - assert.truthy(utils.is_valid_uuid(chain.id)) + assert.truthy(uuid.is_valid_uuid(chain.id)) end) it("can be user-generated", function() - local id = utils.uuid() + local id = uuid.uuid() local chain = assert(dao:insert({ id = id, service = make_service(), @@ -76,7 +76,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() assert.is_string(chain.id) assert.equals(id, chain.id) - assert.truthy(utils.is_valid_uuid(chain.id)) + assert.truthy(uuid.is_valid_uuid(chain.id)) end) it("must be a valid uuid", function() @@ -178,7 +178,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() it("requires the route to exist", function() local chain, err, err_t = dao:insert({ filters = { { name = "test" } }, - route = { id = utils.uuid() }, + route = { id = uuid.uuid() }, }) assert.is_nil(chain) @@ -210,7 +210,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() it("requires the service to exist", function() local chain, err, err_t = dao:insert({ filters = { { name = "test" } }, - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, }) assert.is_nil(chain) @@ -247,7 +247,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() helpers.wait_until(function() local updated = assert(dao:update( { id = chain.id }, - { tags = { utils.uuid() } } + { tags = { uuid.uuid() } } )) return updated.updated_at > chain.updated_at diff --git a/spec/03-plugins/03-http-log/02-schema_spec.lua b/spec/03-plugins/03-http-log/02-schema_spec.lua index f96b4eadb0ac..2bd01c54c178 100644 --- a/spec/03-plugins/03-http-log/02-schema_spec.lua +++ b/spec/03-plugins/03-http-log/02-schema_spec.lua @@ -2,7 +2,7 @@ local PLUGIN_NAME = "http-log" local Queue = require "kong.tools.queue" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local mocker = require "spec.fixtures.mocker" -- helper function to validate data against a schema @@ -37,7 +37,7 @@ describe(PLUGIN_NAME .. ": (schema)", function() err = function(message) return log('ERR', message) end, }, plugin = { - get_id = function () return utils.uuid() end, + get_id = function () return uuid.uuid() end, }, }, ngx = { diff --git a/spec/03-plugins/05-syslog/01-log_spec.lua b/spec/03-plugins/05-syslog/01-log_spec.lua index c84c55213c68..9f913dd36c6c 100644 --- a/spec/03-plugins/05-syslog/01-log_spec.lua +++ b/spec/03-plugins/05-syslog/01-log_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" local pl_stringx = require "pl.stringx" @@ -159,7 +159,7 @@ for _, strategy in helpers.each_strategy() do end) local function do_test(host, expecting_same, grpc) - local uuid = utils.uuid() + local uuid = uuid.uuid() local ok, resp if not grpc then diff --git a/spec/03-plugins/09-key-auth/02-access_spec.lua b/spec/03-plugins/09-key-auth/02-access_spec.lua index 49f3f3561a1e..6c63dbde3edb 100644 --- a/spec/03-plugins/09-key-auth/02-access_spec.lua +++ b/spec/03-plugins/09-key-auth/02-access_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local http_mock = require "spec.helpers.http_mock" local MOCK_PORT = helpers.get_available_port() @@ -117,7 +117,7 @@ for _, strategy in helpers.each_strategy() do name = "key-auth", route = { id = route4.id }, config = { - anonymous = utils.uuid(), -- unknown consumer + anonymous = uuid.uuid(), -- unknown consumer }, } diff --git a/spec/03-plugins/10-basic-auth/03-access_spec.lua b/spec/03-plugins/10-basic-auth/03-access_spec.lua index 765a3a4aa77b..34560721de35 100644 --- a/spec/03-plugins/10-basic-auth/03-access_spec.lua +++ b/spec/03-plugins/10-basic-auth/03-access_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" for _, strategy in helpers.each_strategy() do @@ -104,7 +104,7 @@ for _, strategy in helpers.each_strategy() do name = "basic-auth", route = { id = route4.id }, config = { - anonymous = utils.uuid(), -- a non-existing consumer id + anonymous = uuid.uuid(), -- a non-existing consumer id }, } diff --git a/spec/03-plugins/16-jwt/03-access_spec.lua b/spec/03-plugins/16-jwt/03-access_spec.lua index d091fb8e478d..972749f604e0 100644 --- a/spec/03-plugins/16-jwt/03-access_spec.lua +++ b/spec/03-plugins/16-jwt/03-access_spec.lua @@ -2,7 +2,7 @@ local cjson = require "cjson" local helpers = require "spec.helpers" local fixtures = require "spec.03-plugins.16-jwt.fixtures" local jwt_encoder = require "kong.plugins.jwt.jwt_parser" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local PAYLOAD = { @@ -121,7 +121,7 @@ for _, strategy in helpers.each_strategy() do plugins:insert({ name = "jwt", route = { id = routes[7].id }, - config = { anonymous = utils.uuid() }, + config = { anonymous = uuid.uuid() }, }) plugins:insert({ diff --git a/spec/03-plugins/18-acl/01-api_spec.lua b/spec/03-plugins/18-acl/01-api_spec.lua index dd84c9eb292f..202ba067ab38 100644 --- a/spec/03-plugins/18-acl/01-api_spec.lua +++ b/spec/03-plugins/18-acl/01-api_spec.lua @@ -1,4 +1,4 @@ -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" local helpers = require "spec.helpers" @@ -466,7 +466,7 @@ for _, strategy in helpers.each_strategy() do end) it("does not create acl when missing consumer", function() - local res = admin_client:put("/acls/" .. utils.uuid(), { + local res = admin_client:put("/acls/" .. uuid.uuid(), { body = { group = "test-group" }, headers = { ["Content-Type"] = "application/json" @@ -478,7 +478,7 @@ for _, strategy in helpers.each_strategy() do end) it("creates acl", function() - local res = admin_client:put("/acls/" .. utils.uuid(), { + local res = admin_client:put("/acls/" .. uuid.uuid(), { body = { group = "test-group", consumer = { diff --git a/spec/03-plugins/19-hmac-auth/03-access_spec.lua b/spec/03-plugins/19-hmac-auth/03-access_spec.lua index 643ed1adfcf6..4e3a1920d0fe 100644 --- a/spec/03-plugins/19-hmac-auth/03-access_spec.lua +++ b/spec/03-plugins/19-hmac-auth/03-access_spec.lua @@ -1,7 +1,7 @@ local cjson = require "cjson" local openssl_mac = require "resty.openssl.mac" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local resty_sha256 = require "resty.sha256" local fmt = string.format @@ -95,7 +95,7 @@ for _, strategy in helpers.each_strategy() do name = "hmac-auth", route = { id = route3.id }, config = { - anonymous = utils.uuid(), -- non existing consumer + anonymous = uuid.uuid(), -- non existing consumer clock_skew = 3000 } } diff --git a/spec/03-plugins/20-ldap-auth/01-access_spec.lua b/spec/03-plugins/20-ldap-auth/01-access_spec.lua index f0aa66e60ad9..f106076e58b6 100644 --- a/spec/03-plugins/20-ldap-auth/01-access_spec.lua +++ b/spec/03-plugins/20-ldap-auth/01-access_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" @@ -136,7 +136,7 @@ for _, ldap_strategy in pairs(ldap_strategies) do base_dn = "ou=scientists,dc=ldap,dc=mashape,dc=com", attribute = "uid", cache_ttl = 2, - anonymous = utils.uuid(), -- non existing consumer + anonymous = uuid.uuid(), -- non existing consumer } } diff --git a/spec/03-plugins/23-rate-limiting/02-policies_spec.lua b/spec/03-plugins/23-rate-limiting/02-policies_spec.lua index 640de183f1db..f28dc47f445b 100644 --- a/spec/03-plugins/23-rate-limiting/02-policies_spec.lua +++ b/spec/03-plugins/23-rate-limiting/02-policies_spec.lua @@ -1,4 +1,4 @@ -local uuid = require("kong.tools.utils").uuid +local uuid = require("kong.tools.uuid").uuid local helpers = require "spec.helpers" local timestamp = require "kong.tools.timestamp" diff --git a/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua b/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua index d5c122fb62a8..19d8d20d6e3d 100644 --- a/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua +++ b/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua @@ -1,11 +1,11 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" +local uuid = require("kong.tools.uuid").uuid describe("Plugin: rate-limiting (shorthand fields)", function() local bp, route, admin_client - local plugin_id = utils.uuid() + local plugin_id = uuid() lazy_setup(function() bp = helpers.get_db_utils(nil, { diff --git a/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua b/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua index 38b3a240f0c3..dbc848b6631c 100644 --- a/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua +++ b/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua @@ -1,4 +1,4 @@ -local uuid = require("kong.tools.utils").uuid +local uuid = require("kong.tools.uuid").uuid local helpers = require "spec.helpers" local timestamp = require "kong.tools.timestamp" diff --git a/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua b/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua index 69275b322887..3d2de4c436a2 100644 --- a/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua +++ b/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua @@ -1,11 +1,11 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" +local uuid = require("kong.tools.uuid").uuid describe("Plugin: response-ratelimiting (shorthand fields)", function() local bp, route, admin_client - local plugin_id = utils.uuid() + local plugin_id = uuid() lazy_setup(function() bp = helpers.get_db_utils(nil, { diff --git a/spec/03-plugins/25-oauth2/01-schema_spec.lua b/spec/03-plugins/25-oauth2/01-schema_spec.lua index f0de8317a158..13a6c31c936d 100644 --- a/spec/03-plugins/25-oauth2/01-schema_spec.lua +++ b/spec/03-plugins/25-oauth2/01-schema_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local schema_def = require "kong.plugins.oauth2.schema" local DAO_MAX_TTL = require("kong.constants").DATABASE.DAO_MAX_TTL local v = require("spec.helpers").validate_plugin_config_schema @@ -118,7 +118,7 @@ for _, strategy in helpers.each_strategy() do local ok, err_t = oauth2_tokens_schema:validate_insert({ credential = { id = "foo" }, - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, expires_in = 1, }) assert.falsy(ok) @@ -129,8 +129,8 @@ for _, strategy in helpers.each_strategy() do local ok, err_t = oauth2_tokens_schema:validate_insert({ - credential = { id = utils.uuid() }, - service = { id = utils.uuid() }, + credential = { id = uuid.uuid() }, + service = { id = uuid.uuid() }, expires_in = 1, token_type = "bearer", }) @@ -152,7 +152,7 @@ for _, strategy in helpers.each_strategy() do local ok, err_t = oauth2_authorization_codes_schema:validate_insert({ credential = { id = "foo" }, - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, }) assert.falsy(ok) assert.same({ @@ -160,8 +160,8 @@ for _, strategy in helpers.each_strategy() do }, err_t) local ok, err_t = oauth2_authorization_codes_schema:validate_insert({ - credential = { id = utils.uuid() }, - service = { id = utils.uuid() }, + credential = { id = uuid.uuid() }, + service = { id = uuid.uuid() }, }) assert.truthy(ok) diff --git a/spec/03-plugins/25-oauth2/03-access_spec.lua b/spec/03-plugins/25-oauth2/03-access_spec.lua index 48e1cf018a28..e941769b6027 100644 --- a/spec/03-plugins/25-oauth2/03-access_spec.lua +++ b/spec/03-plugins/25-oauth2/03-access_spec.lua @@ -1,6 +1,6 @@ local cjson = require "cjson" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local admin_api = require "spec.fixtures.admin_api" local sha256 = require "resty.sha256" local jwt_encoder = require "kong.plugins.jwt.jwt_parser" @@ -510,7 +510,7 @@ describe("Plugin: oauth2 [#" .. strategy .. "]", function() config = { scopes = { "email", "profile", "user.email" }, global_credentials = true, - anonymous = utils.uuid(), -- a non existing consumer + anonymous = uuid.uuid(), -- a non existing consumer }, }) diff --git a/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua b/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua index f40b47f9af6f..ba199a7440bb 100644 --- a/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua +++ b/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua @@ -1,11 +1,11 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" +local uuid = require("kong.tools.uuid").uuid describe("Plugin: acme (shorthand fields)", function() local bp, route, admin_client - local plugin_id = utils.uuid() + local plugin_id = uuid() lazy_setup(function() bp = helpers.get_db_utils(nil, { diff --git a/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua b/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua index 83768ef7ab89..436256de6cd3 100644 --- a/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua +++ b/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" describe("Reconfiguration completion detection plugin", function() @@ -11,7 +11,7 @@ describe("Reconfiguration completion detection plugin", function() local function plugin_tests() - local configuration_version = utils.uuid() + local configuration_version = uuid.uuid() local res = admin_client:post("/plugins", { body = { @@ -72,7 +72,7 @@ describe("Reconfiguration completion detection plugin", function() }) assert.res_status(201, res) - configuration_version = utils.uuid() + configuration_version = uuid.uuid() res = admin_client:patch("/plugins/" .. reconfiguration_completion_plugin_id, { body = { config = { diff --git a/spec/fixtures/balancer_utils.lua b/spec/fixtures/balancer_utils.lua index 644d80befb9e..fdac769de7e5 100644 --- a/spec/fixtures/balancer_utils.lua +++ b/spec/fixtures/balancer_utils.lua @@ -4,6 +4,7 @@ local helpers = require "spec.helpers" local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local https_server = require "spec.fixtures.https_server" +local uuid = require("kong.tools.uuid").uuid local CONSISTENCY_FREQ = 1 @@ -228,7 +229,7 @@ do end add_certificate = function(bp, data) - local certificate_id = utils.uuid() + local certificate_id = uuid() local req = kong_table.cycle_aware_deep_copy(data) or {} req.id = certificate_id bp.certificates:insert(req) @@ -236,7 +237,7 @@ do end add_upstream = function(bp, data) - local upstream_id = utils.uuid() + local upstream_id = uuid() local req = kong_table.cycle_aware_deep_copy(data) or {} local upstream_name = req.name or gen_sym("upstream") req.name = upstream_name @@ -336,8 +337,8 @@ do add_api = function(bp, upstream_name, opts) opts = opts or {} - local route_id = utils.uuid() - local service_id = utils.uuid() + local route_id = uuid() + local service_id = uuid() local route_host = gen_sym("host") local sproto = opts.service_protocol or opts.route_protocol or "http" local rproto = opts.route_protocol or "http" diff --git a/spec/helpers.lua b/spec/helpers.lua index ed6170ec64fb..57b9fea00da3 100644 --- a/spec/helpers.lua +++ b/spec/helpers.lua @@ -61,7 +61,6 @@ local pl_Set = require "pl.Set" local Schema = require "kong.db.schema" local Entity = require "kong.db.schema.entity" local cjson = require "cjson.safe" -local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local http = require "resty.http" local pkey = require "resty.openssl.pkey" @@ -78,6 +77,7 @@ local stress_generator = require "spec.fixtures.stress_generator" local resty_signal = require "resty.signal" local lfs = require "lfs" local luassert = require "luassert.assert" +local uuid = require("kong.tools.uuid").uuid ffi.cdef [[ int setenv(const char *name, const char *value, int overwrite); @@ -594,7 +594,7 @@ local plugins_schema = assert(Entity.new(plugins_schema_def)) local function validate_plugin_config_schema(config, schema_def) assert(plugins_schema:new_subschema(schema_def.name, schema_def)) local entity = { - id = utils.uuid(), + id = uuid(), name = schema_def.name, config = config } @@ -4061,7 +4061,7 @@ local function clustering_client(opts) local c = assert(ws_client:new()) local uri = "wss://" .. opts.host .. ":" .. opts.port .. - "/v1/outlet?node_id=" .. (opts.node_id or utils.uuid()) .. + "/v1/outlet?node_id=" .. (opts.node_id or uuid()) .. "&node_hostname=" .. (opts.node_hostname or kong.node.get_hostname()) .. "&node_version=" .. (opts.node_version or KONG_VERSION)