]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: implement a reload failure counter
authorWilliam Lallemand <wlallemand@haproxy.org>
Wed, 10 Nov 2021 09:49:06 +0000 (10:49 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 10 Nov 2021 14:53:01 +0000 (15:53 +0100)
Implement a reload failure counter which counts the number of failure
since the last success. This counter is available in 'show proc' over
the master CLI.

include/haproxy/mworker-t.h
src/haproxy.c
src/mworker.c

index dabdf810a6390ec903099979a55ea64170865350..3137ec0be9c97a29dc5dab7154b7751b92199665 100644 (file)
@@ -40,6 +40,7 @@ struct mworker_proc {
        char *version;
        int ipc_fd[2]; /* 0 is master side, 1 is worker side */
        int reloads;
+       int failedreloads; /* number of failed reloads since the last successful one */
        int timestamp;
        struct server *srv; /* the server entry in the master proxy */
        struct list list;
index a6b8dc3adf52e9e9f400e16623d01b0d476ec40d..187ba750ae9ba1c621b7564f10e42938fd4751bb 100644 (file)
@@ -864,8 +864,21 @@ static void mworker_loop()
  */
 void reexec_on_failure()
 {
+       struct mworker_proc *child;
+
        if (!atexit_flag)
                return;
+
+       /* get the info of the children in the env */
+       if (mworker_env_to_proc_list() < 0) {
+               exit(EXIT_FAILURE);
+       }
+
+       /* increment the number of failed reloads */
+       list_for_each_entry(child, &proc_list, list) {
+               child->failedreloads++;
+       }
+
        usermsgs_clr(NULL);
        ha_warning("Loading failure!\n");
        mworker_reexec_waitmode();
@@ -1945,6 +1958,7 @@ static void init(int argc, char **argv)
                                exit(EXIT_FAILURE);
                        }
                        tmproc->options |= PROC_O_TYPE_MASTER; /* master */
+                       tmproc->failedreloads = 0;
                        tmproc->reloads = 0;
                        tmproc->pid = pid;
                        tmproc->timestamp = start_date.tv_sec;
@@ -1964,6 +1978,7 @@ static void init(int argc, char **argv)
 
                tmproc->options |= PROC_O_TYPE_WORKER; /* worker */
                tmproc->pid = -1;
+               tmproc->failedreloads = 0;
                tmproc->reloads = 0;
                tmproc->timestamp = -1;
                tmproc->ipc_fd[0] = -1;
@@ -3268,6 +3283,7 @@ int main(int argc, char **argv)
 
                                        /* if not in wait mode, reload in wait mode to free the memory */
                                        ha_notice("Loading success.\n");
+                                       proc_self->failedreloads = 0; /* reset the number of failure */
                                        mworker_reexec_waitmode();
                                }
                                /* should never get there */
index fe1770618b185f77bd2ca5e5c67a6f06a92ddd62..a14a840938c3594935ef8c57e15601d84ed202a5 100644 (file)
@@ -122,7 +122,7 @@ void mworker_proc_list_to_env()
                        type = 'w';
 
                if (child->pid > -1)
-                       memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;reloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->reloads, child->timestamp, child->id ? child->id : "", child->version);
+                       memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;reloads=%d;failedreloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->reloads, child->failedreloads, child->timestamp, child->id ? child->id : "", child->version);
        }
        if (msg)
                setenv("HAPROXY_PROCESSES", msg, 1);
@@ -176,6 +176,8 @@ int mworker_env_to_proc_list()
                        } else if (strncmp(subtoken, "reloads=", 8) == 0) {
                                /* we only increment the number of asked reload */
                                child->reloads = atoi(subtoken+8);
+                       } else if (strncmp(subtoken, "failedreloads=", 14) == 0) {
+                               child->failedreloads = atoi(subtoken+14);
                        } else if (strncmp(subtoken, "timestamp=", 10) == 0) {
                                child->timestamp = atoi(subtoken+10);
                        } else if (strncmp(subtoken, "id=", 3) == 0) {
@@ -455,15 +457,18 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
        int old = 0;
        int up = now.tv_sec - proc_self->timestamp;
        char *uptime = NULL;
+       char *reloadtxt = NULL;
 
        if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
                return 1;
 
        chunk_reset(&trash);
 
+       memprintf(&reloadtxt, "%d [failed: %d]", proc_self->reloads, proc_self->failedreloads);
        chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<reloads>", "<uptime>", "<version>");
        memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-       chunk_appendf(&trash, "%-15u %-15s %-15d %-15s %-15s\n", (unsigned int)getpid(), "master", proc_self->reloads, uptime, haproxy_version);
+       chunk_appendf(&trash, "%-15u %-15s %-15s %-15s %-15s\n", (unsigned int)getpid(), "master", reloadtxt, uptime, haproxy_version);
+       ha_free(&reloadtxt);
        ha_free(&uptime);
 
        /* displays current processes */