From: Aurelien DARRAGON Date: Wed, 4 Oct 2023 08:32:45 +0000 (+0200) Subject: MINOR: server: introduce "log-bufsize" kw X-Git-Tag: v2.9-dev8~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94d0f77debdcb4d2e17da254a2b27135a774e3f4;p=thirdparty%2Fhaproxy.git MINOR: server: introduce "log-bufsize" kw "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). --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 6f85c10134..0b74ae2915 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -16176,6 +16176,14 @@ downinter "inter" setting will have a very limited effect as it will not be able to reduce the time spent in the queue. +log-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 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" diff --git a/include/haproxy/server-t.h b/include/haproxy/server-t.h index fc08909e23..9b03600034 100644 --- a/include/haproxy/server-t.h +++ b/include/haproxy/server-t.h @@ -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 */ diff --git a/src/server.c b/src/server.c index 807dcc81bd..3c40ca7fe6 100644 --- a/src/server.c +++ b/src/server.c @@ -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 diff --git a/src/sink.c b/src/sink.c index bb086e458d..42c15b4906 100644 --- a/src/sink.c +++ b/src/sink.c @@ -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;