From 75fa2ae442af961ef456300109919266f7cb7181 Mon Sep 17 00:00:00 2001 From: Chrono Date: Tue, 2 Apr 2024 11:13:57 +0800 Subject: [PATCH] refactor(tools/system): move `kong.tools.system` module out of `kong.tools.utils` (#12813) Putting too many functions into a single module (`kong.tools.utils`) doesn't make sense, we should extract it out of the giant module eventually. KAG-3137 --- kong/reports.lua | 7 ++++--- kong/tools/utils.lua | 1 - spec/01-unit/05-utils_spec.lua | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kong/reports.lua b/kong/reports.lua index 69ecd9b1b69..a898eeaa7be 100644 --- a/kong/reports.lua +++ b/kong/reports.lua @@ -1,5 +1,6 @@ local cjson = require "cjson.safe" -local utils = require "kong.tools.utils" +local system = require "kong.tools.system" +local rand = require "kong.tools.rand" local constants = require "kong.constants" local counter = require "resty.counter" local knode = (kong and kong.node) and kong.node or @@ -62,7 +63,7 @@ local REQUEST_ROUTE_CACHE_HITS_KEY_NEG = REQUEST_COUNT_KEY .. ":" .. ROUTE_CACHE local _buffer = {} local _ping_infos = {} local _enabled = false -local _unique_str = utils.random_string() +local _unique_str = rand.random_string() local _buffer_immutable_idx local _ssl_session local _ssl_verify = false @@ -75,7 +76,7 @@ do local meta = require "kong.meta" - local system_infos = utils.get_system_infos() + local system_infos = system.get_system_infos() system_infos.hostname = system_infos.hostname or knode.get_hostname() diff --git a/kong/tools/utils.lua b/kong/tools/utils.lua index 6e3db7a9d20..e6ece1aae8c 100644 --- a/kong/tools/utils.lua +++ b/kong/tools/utils.lua @@ -22,7 +22,6 @@ do "kong.tools.string", "kong.tools.uuid", "kong.tools.rand", - "kong.tools.system", "kong.tools.time", "kong.tools.ip", "kong.tools.http", diff --git a/spec/01-unit/05-utils_spec.lua b/spec/01-unit/05-utils_spec.lua index 03082bc6fee..5fa423adf80 100644 --- a/spec/01-unit/05-utils_spec.lua +++ b/spec/01-unit/05-utils_spec.lua @@ -4,6 +4,7 @@ local pl_path = require "pl.path" describe("Utils", function() describe("get_system_infos()", function() + local utils = require "kong.tools.system" it("retrieves various host infos", function() local infos = utils.get_system_infos() assert.is_number(infos.cores) @@ -19,6 +20,7 @@ describe("Utils", function() end) describe("get_system_trusted_certs_filepath()", function() + local utils = require "kong.tools.system" local old_exists = pl_path.exists after_each(function() pl_path.exists = old_exists