From 8e3f67c8ccb82a02f2608f0d24157a8c9ab57ca0 Mon Sep 17 00:00:00 2001 From: Javier Guerra Date: Mon, 11 Apr 2022 21:27:25 -0500 Subject: [PATCH] perf(clustering) do granular hashes like #8519 does for old protocol. --- kong/clustering/wrpc_control_plane.lua | 5 +++-- kong/clustering/wrpc_data_plane.lua | 7 +++++-- kong/include/kong/services/config/v1/config.proto | 12 +++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/kong/clustering/wrpc_control_plane.lua b/kong/clustering/wrpc_control_plane.lua index 0ccbfcca8e6..9ef85eb2774 100644 --- a/kong/clustering/wrpc_control_plane.lua +++ b/kong/clustering/wrpc_control_plane.lua @@ -151,7 +151,7 @@ function _M:export_deflated_reconfigure_payload() end end - local config_hash = self:calculate_config_hash(config_table) + local config_hash, hashes = self:calculate_config_hash(config_table) config_version = config_version + 1 -- store serialized plugins map for troubleshooting purposes @@ -162,7 +162,8 @@ function _M:export_deflated_reconfigure_payload() self.config_call_rpc, self.config_call_args = assert(service:encode_args("ConfigService.SyncConfig", { config = config_table, version = config_version, - hash = config_hash, + config_hash = config_hash, + hashes = hashes, })) return config_table, nil diff --git a/kong/clustering/wrpc_data_plane.lua b/kong/clustering/wrpc_data_plane.lua index b7cb80f7c55..cda078b9982 100644 --- a/kong/clustering/wrpc_data_plane.lua +++ b/kong/clustering/wrpc_data_plane.lua @@ -84,7 +84,8 @@ local function get_config_service() data.config.format_version = nil peer.config_obj.next_config = data.config - peer.config_obj.next_hash = data.hash + peer.config_obj.next_hash = data.config_hash + peer.config_obj.next_hashes = data.hashes peer.config_obj.next_config_version = tonumber(data.version) if peer.config_semaphore:count() <= 0 then -- the following line always executes immediately after the `if` check @@ -196,11 +197,12 @@ function _M:communicate(premature) end local config_table = self.next_config local config_hash = self.next_hash + local hashes = self.next_hashes if config_table and self.next_config_version > last_config_version then ngx_log(ngx_INFO, _log_prefix, "received config #", self.next_config_version, log_suffix) local pok, res - pok, res, err = xpcall(self.update_config, debug.traceback, self, config_table, config_hash, true) + pok, res, err = xpcall(self.update_config, debug.traceback, self, config_table, config_hash, true, hashes) if pok then last_config_version = self.next_config_version if not res then @@ -214,6 +216,7 @@ function _M:communicate(premature) if self.next_config == config_table then self.next_config = nil self.next_hash = nil + self.next_hashes = nil end end diff --git a/kong/include/kong/services/config/v1/config.proto b/kong/include/kong/services/config/v1/config.proto index e2f6d44b999..8ecc79ff5c9 100644 --- a/kong/include/kong/services/config/v1/config.proto +++ b/kong/include/kong/services/config/v1/config.proto @@ -85,6 +85,15 @@ message PluginVersion { string version = 2; } +message GranularHashes { + string config = 1; + string routes = 2; + string services = 3; + string plugins = 4; + string upstreams = 5; + string targets = 6; +} + message SyncConfigRequest { // Config represents a configuration of Kong Gateway. // This is same as the declarative configuration of Kong. @@ -101,7 +110,8 @@ message SyncConfigRequest { uint64 version = 2; // raw binary hash of the config data. - string hash = 3; + string config_hash = 3; + GranularHashes hashes = 4; } message SyncConfigResponse {