Upstream: Count peer->fails if peers->single is 1

u5h u5.horie at gmail.com
Wed Mar 8 00:11:01 UTC 2023


Hello.
The upstream peer status is always up when the upstream peer is single.
FYI: https://github.com/vozlt/nginx-module-vts/issues/262
The conventional upstream round robin hasn't count peer->fails anywhere
when it is peers->single is 1.
Thus we’d like to only count it, but not to judge that the peer is down.


# HG changeset patch
# User Yugo Horie <u5.horie at gmail.com>
# Date 1678105277 -32400
#      Mon Mar 06 21:21:17 2023 +0900
# Node ID bd2cfa9541df90fa45883797cba56a26fc5f39c0
# Parent  2acb00b9b5fff8a97523b659af4377fc605abe6e
Upstream: Count peer->fails if peers->single is 1

The log based monitoring modules (e.g. nginx-module-vts)
can identify the upstream peer is up or down with
peer->fails even if it is the single upstream peer.

diff -r 2acb00b9b5ff -r bd2cfa9541df
src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c  Thu Feb 23 20:50:03 2023
+0300
+++ b/src/http/ngx_http_upstream_round_robin.c  Mon Mar 06 21:21:17 2023
+0900
@@ -551,7 +551,7 @@
             continue;
         }

-        if (peer->max_fails
+        if (!rrp->peers->single && peer->max_fails
             && peer->fails >= peer->max_fails
             && now - peer->checked <= peer->fail_timeout)
         {
@@ -618,6 +618,11 @@
     if (rrp->peers->single) {

         peer->conns--;
+        if (state & NGX_PEER_FAILED) {
+            peer->fails++;
+        } else {
+            peer->fails = 0;
+        }

         ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
         ngx_http_upstream_rr_peers_unlock(rrp->peers);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20230308/2983c062/attachment.htm>


More information about the nginx-devel mailing list