From ed6cce1ce2c6f90ad8318ab6f6f84139829799b2 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Thu, 29 Feb 2024 11:24:25 +0800 Subject: [PATCH] apply comments Signed-off-by: tzssangglass --- config | 2 +- lualib/resty/kong/peer_conn.lua | 11 +++++++---- src/ngx_http_lua_kong_peer_connection.c | 3 +++ t/011-get_last_peer_connection_cached.t | 3 +-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config b/config index 0404fed9..043ec536 100644 --- a/config +++ b/config @@ -9,7 +9,7 @@ ngx_module_srcs=" \ $ngx_addon_dir/src/ngx_http_lua_kong_log.c \ $ngx_addon_dir/src/ngx_http_lua_kong_log_handler.c \ $ngx_addon_dir/src/ngx_http_lua_kong_vars.c \ - $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ + $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ $ngx_addon_dir/src/ssl/ngx_lua_kong_ssl.c \ " diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index 64494718..d27d18aa 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -1,19 +1,22 @@ local ffi = require "ffi" -local C = ffi.C local base = require "resty.core.base" -local ffi_str = ffi.string + local orig_get_request = base.get_request +local errmsg = base.get_errmsg_ptr() +local C = ffi.C +local ffi_str = ffi.string local get_phase = ngx.get_phase -local error = error local NGX_ERROR = ngx.ERROR +local error = error + + ffi.cdef[[ int ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, char **err); ]] -local errmsg = base.get_errmsg_ptr() local function get_request() local r = orig_get_request() diff --git a/src/ngx_http_lua_kong_peer_connection.c b/src/ngx_http_lua_kong_peer_connection.c index e992530f..e431073f 100644 --- a/src/ngx_http_lua_kong_peer_connection.c +++ b/src/ngx_http_lua_kong_peer_connection.c @@ -17,6 +17,7 @@ #include "ngx_http_lua_kong_common.h" + int ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, char **err) @@ -26,5 +27,7 @@ ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, return NGX_ERROR; } + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "last_peer_connection_cached %d", r->upstream->peer.cached); return r->upstream->peer.cached; } diff --git a/t/011-get_last_peer_connection_cached.t b/t/011-get_last_peer_connection_cached.t index 9da401df..9ee143d8 100644 --- a/t/011-get_last_peer_connection_cached.t +++ b/t/011-get_last_peer_connection_cached.t @@ -3,7 +3,7 @@ use Test::Nginx::Socket::Lua; use Cwd qw(cwd); -log_level('info'); +log_level('debug'); repeat_each(1); plan tests => repeat_each() * (blocks() * 2); @@ -26,7 +26,6 @@ __DATA__ balancer_by_lua_block { local peer_conn = require("resty.kong.peer_conn") local last_peer_connection_cached = peer_conn.get_last_peer_connection_cached() - ngx.log(ngx.INFO, "last_peer_connection_cached ", tostring(last_peer_connection_cached)) local balancer = require "ngx.balancer" local host = "127.0.0.1"