]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: introduce "log-bufsize" kw
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 4 Oct 2023 08:32:45 +0000 (10:32 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Oct 2023 08:05:07 +0000 (10:05 +0200)
"log-bufsize" may now be used for a log server (in a log backend) to
configure the bufsize of implicit ring associated to the server (which
defaults to BUFSIZE).

doc/configuration.txt
include/haproxy/server-t.h
src/server.c
src/sink.c

index 6f85c1013457cf39213c13fd3f71cb41738a4f3d..0b74ae29158d5f1a1d3b7244dbc57e060ba294b8 100644 (file)
@@ -16176,6 +16176,14 @@ downinter <delay>
   "inter" setting will have a very limited effect as it will not be able to
   reduce the time spent in the queue.
 
+log-bufsize <bufsize>
+  The "log-bufsize" specifies the ring bufsize to use for the implicit ring
+  that will be associated to the log server in a log backend. When not
+  specified, this defaults to BUFSIZE. Use of a greater value will increase
+  memory usage but can help to prevent the loss of log messages with slow
+  servers since the buffer will be able to hold more pending messages.
+  This keyword may only be used in log backend sections (with "mode log")
+
 log-proto <logproto>
   The "log-proto" specifies the protocol used to forward event messages to
   a server configured in a log or ring section. Possible values are "legacy"
index fc08909e235203b75570378e0bf97ee29c1a6ae7..9b03600034e722297dbf5c7829e5f1fdf49c14f1 100644 (file)
@@ -306,6 +306,7 @@ struct server {
        unsigned cumulative_weight;             /* weight of servers prior to this one in the same group, for chash balancing */
        int maxqueue;                           /* maximum number of pending connections allowed */
        int shard;                              /* shard (in peers protocol context only) */
+       int log_bufsize;                        /* implicit ring bufsize (for log server only - in log backend) */
 
        enum srv_ws_mode ws;                    /* configure the protocol selection for websocket */
        /* 3 bytes hole here */
index 807dcc81bdf9ce8a0e5cd79ca3efb44d427a2571..3c40ca7fe6d339d74a88a2f761a843d1b9e61783 100644 (file)
@@ -760,6 +760,27 @@ static int srv_parse_init_addr(char **args, int *cur_arg,
        return 0;
 }
 
+/* Parse the "log-bufsize" server keyword */
+static int srv_parse_log_bufsize(char **args, int *cur_arg,
+                                 struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       if (!*args[*cur_arg + 1]) {
+               memprintf(err, "'%s' expects an integer argument.",
+                         args[*cur_arg]);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+       newsrv->log_bufsize = atoi(args[*cur_arg + 1]);
+
+       if (newsrv->log_bufsize <= 0) {
+               memprintf(err, "%s has to be > 0.",
+                         args[*cur_arg]);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+       return 0;
+}
+
 /* Parse the "log-proto" server keyword */
 static int srv_parse_log_proto(char **args, int *cur_arg,
                                struct proxy *curproxy, struct server *newsrv, char **err)
@@ -1901,6 +1922,7 @@ static struct srv_kw_list srv_kws = { "ALL", { }, {
        { "ws",                  srv_parse_ws,                  1,  1,  1 }, /* websocket protocol */
        { "id",                  srv_parse_id,                  1,  0,  1 }, /* set id# of server */
        { "init-addr",           srv_parse_init_addr,           1,  1,  0 }, /* */
+       { "log-bufsize",         srv_parse_log_bufsize,         1,  1,  0 }, /* Set the ring bufsize for log server (only for log backends) */
        { "log-proto",           srv_parse_log_proto,           1,  1,  0 }, /* Set the protocol for event messages, only relevant in a log or ring section */
        { "maxconn",             srv_parse_maxconn,             1,  1,  1 }, /* Set the max number of concurrent connection */
        { "maxqueue",            srv_parse_maxqueue,            1,  1,  1 }, /* Set the max number of connection to put in queue */
@@ -2421,6 +2443,7 @@ void srv_settings_cpy(struct server *srv, const struct server *src, int srv_tmpl
        srv->netns                    = src->netns;
        srv->check.via_socks4         = src->check.via_socks4;
        srv->socks4_addr              = src->socks4_addr;
+       srv->log_bufsize              = src->log_bufsize;
 }
 
 /* allocate a server and attach it to the global servers_list. Returns
index bb086e458dc4cb6bca6cecf25e7185f0a20d8fa4..42c15b4906248371ec3639f9733ac8a01310bd39 100644 (file)
@@ -1266,6 +1266,7 @@ struct sink *sink_new_from_logger(struct logger *logger)
 struct sink *sink_new_from_srv(struct server *srv, const char *from)
 {
        struct sink *sink = NULL;
+       int bufsize = (srv->log_bufsize) ? srv->log_bufsize : BUFSIZE;
 
        /* prepare description for the sink */
        chunk_reset(&trash);
@@ -1274,7 +1275,7 @@ struct sink *sink_new_from_srv(struct server *srv, const char *from)
        /* directly create a sink of BUF type, and use UNSPEC log format to
         * inherit from caller fmt in sink_write()
         */
-       sink = sink_new_buf(srv->id, trash.area, LOG_FORMAT_UNSPEC, BUFSIZE);
+       sink = sink_new_buf(srv->id, trash.area, LOG_FORMAT_UNSPEC, bufsize);
        if (!sink) {
                ha_alert("unable to create a new sink buffer for server '%s'.\n", srv->id);
                goto error;