From 894bcc6a543e26b1c07c4cf467696477e6af60a3 Mon Sep 17 00:00:00 2001 From: Jun Ouyang Date: Tue, 17 Dec 2024 16:13:23 +0800 Subject: [PATCH 1/5] feat(patch): control the proxy_upstream in lua side --- .requirements | 2 +- .../nginx-1.25.3_10-proxy-upstream-next.patch | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch diff --git a/.requirements b/.requirements index 1d1a2175155..6437cef2569 100644 --- a/.requirements +++ b/.requirements @@ -15,7 +15,7 @@ LIBEXPAT_SHA256=d4cf38d26e21a56654ffe4acd9cd5481164619626802328506a2869afab29ab3 # Note: git repositories can be loaded from local path if path is set as value -LUA_KONG_NGINX_MODULE=3eb89666f84348fa0599d4e0a29ccf89511e8b75 # 0.13.0 +LUA_KONG_NGINX_MODULE=0b9cf13a779e2d8703f6770f7228984779dbf948 # 0.13.0 LUA_RESTY_LMDB=9da0e9f3313960d06e2d8e718b7ac494faa500f1 # 1.6.0 LUA_RESTY_EVENTS=bc85295b7c23eda2dbf2b4acec35c93f77b26787 # 0.3.1 LUA_RESTY_SIMDJSON=7e6466ce91b2bc763b45701a4f055e94b1e8143b # 1.1.0 diff --git a/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch b/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch new file mode 100644 index 00000000000..ecdb612b644 --- /dev/null +++ b/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch @@ -0,0 +1,16 @@ +diff --git a/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c b/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c +index 2be233c..6edff37 100644 +--- a/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c ++++ b/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c +@@ -2563,7 +2563,11 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) + } + + if (u->peer.tries > 1 ++#if (NGX_HTTP_LUA_KONG) ++ && ((ngx_http_lua_kong_get_next_upstream_mask(r, u->conf->next_upstream) & mask) == mask) ++#else + && ((u->conf->next_upstream & mask) == mask) ++#endif + && !(u->request_sent && r->request_body_no_buffering) + && !(timeout && ngx_current_msec - u->peer.start_time >= timeout)) + { From d2668d91227efc19c4005cc81517b6074b9da9e9 Mon Sep 17 00:00:00 2001 From: Jun Ouyang Date: Wed, 18 Dec 2024 17:51:25 +0800 Subject: [PATCH 2/5] feat(patch): control the proxy_upstream in lua side --- .../nginx-1.25.3_10-proxy-upstream-next.patch | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch b/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch index ecdb612b644..a17fb086612 100644 --- a/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch +++ b/build/openresty/patches/nginx-1.25.3_10-proxy-upstream-next.patch @@ -1,5 +1,5 @@ diff --git a/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c b/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c -index 2be233c..6edff37 100644 +index 2be233c..7f7132d 100644 --- a/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c +++ b/bundle/nginx-1.25.3/src/http/ngx_http_upstream.c @@ -2563,7 +2563,11 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) @@ -14,3 +14,16 @@ index 2be233c..6edff37 100644 && !(u->request_sent && r->request_body_no_buffering) && !(timeout && ngx_current_msec - u->peer.start_time >= timeout)) { +@@ -4420,7 +4424,12 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, + } + + if (u->peer.tries == 0 ++#if (NGX_HTTP_LUA_KONG) ++ || ((ngx_http_lua_kong_get_next_upstream_mask(r, u->conf->next_upstream) & ft_type) != ft_type) ++#else + || ((u->conf->next_upstream & ft_type) != ft_type) ++#endif ++ + || (u->request_sent && r->request_body_no_buffering) + || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) + { From a8789a989ad3c15ca2465edb9f774d127b56f44c Mon Sep 17 00:00:00 2001 From: Jun Ouyang Date: Wed, 18 Dec 2024 18:06:50 +0800 Subject: [PATCH 3/5] feat(patch): control the proxy_upstream in lua side --- .requirements | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.requirements b/.requirements index 6437cef2569..6d08e0f002f 100644 --- a/.requirements +++ b/.requirements @@ -15,7 +15,7 @@ LIBEXPAT_SHA256=d4cf38d26e21a56654ffe4acd9cd5481164619626802328506a2869afab29ab3 # Note: git repositories can be loaded from local path if path is set as value -LUA_KONG_NGINX_MODULE=0b9cf13a779e2d8703f6770f7228984779dbf948 # 0.13.0 +LUA_KONG_NGINX_MODULE=f8f96a3ff1cd13e7aaf40ef8b60a4e8e7d973b9b # 0.13.0 LUA_RESTY_LMDB=9da0e9f3313960d06e2d8e718b7ac494faa500f1 # 1.6.0 LUA_RESTY_EVENTS=bc85295b7c23eda2dbf2b4acec35c93f77b26787 # 0.3.1 LUA_RESTY_SIMDJSON=7e6466ce91b2bc763b45701a4f055e94b1e8143b # 1.1.0 From 59e921bea17d00c38ee6b64fa7d8faa4214f1976 Mon Sep 17 00:00:00 2001 From: Jun Ouyang Date: Wed, 18 Dec 2024 18:26:54 +0800 Subject: [PATCH 4/5] feat(patch): update changelog --- .../unreleased/kong/feat-patch-supprt-set_next_upstream.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/unreleased/kong/feat-patch-supprt-set_next_upstream.yml diff --git a/changelog/unreleased/kong/feat-patch-supprt-set_next_upstream.yml b/changelog/unreleased/kong/feat-patch-supprt-set_next_upstream.yml new file mode 100644 index 00000000000..b7df2cc1113 --- /dev/null +++ b/changelog/unreleased/kong/feat-patch-supprt-set_next_upstream.yml @@ -0,0 +1,4 @@ +message: | + Add a patch for kong.resty.set_next_upstream() to control the next upstream retry logic in lua side. [Kong/lua-kong-nginx-module#98](https://github.com/Kong/lua-kong-nginx-module/pull/98) +type: bugfix +scope: Core \ No newline at end of file From e043819bab76146cef98b2b3a3d403960380283c Mon Sep 17 00:00:00 2001 From: Jun Ouyang Date: Mon, 23 Dec 2024 22:23:31 +0800 Subject: [PATCH 5/5] fix: fix code --- .requirements | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.requirements b/.requirements index 6d08e0f002f..2f3b704e370 100644 --- a/.requirements +++ b/.requirements @@ -15,7 +15,7 @@ LIBEXPAT_SHA256=d4cf38d26e21a56654ffe4acd9cd5481164619626802328506a2869afab29ab3 # Note: git repositories can be loaded from local path if path is set as value -LUA_KONG_NGINX_MODULE=f8f96a3ff1cd13e7aaf40ef8b60a4e8e7d973b9b # 0.13.0 +LUA_KONG_NGINX_MODULE=c967e8326179c86680c0f34d82ee087765aed19a # 0.15.0 LUA_RESTY_LMDB=9da0e9f3313960d06e2d8e718b7ac494faa500f1 # 1.6.0 LUA_RESTY_EVENTS=bc85295b7c23eda2dbf2b4acec35c93f77b26787 # 0.3.1 LUA_RESTY_SIMDJSON=7e6466ce91b2bc763b45701a4f055e94b1e8143b # 1.1.0