MINOR: spoe: Add loggers dedicated to the SPOE agent

Now it is possible to configure a logger in a spoe-agent section using a "log"
line, as for a proxy. "no log", "log global" and "log <address> ..." syntaxes
are supported.
This commit is contained in:
Christopher Faulet 2018-03-26 17:19:01 +02:00 committed by Willy Tarreau
parent 28ac099907
commit 7250b8fb5c
3 changed files with 45 additions and 4 deletions

View File

@ -165,6 +165,7 @@ spoe-agent <name>
following keywords are supported : following keywords are supported :
- groups - groups
- log
- maxconnrate - maxconnrate
- maxerrrate - maxerrrate
- max-frame-size - max-frame-size
@ -196,6 +197,16 @@ groups <grp-name> ...
See also: "spoe-group" section. See also: "spoe-group" section.
log global
log <address> [len <length>] [format <format>] <facility> [<level> [<minlevel>]]
no log
Enable per-instance logging of events and traffic.
Prefix :
no should be used when the logger list must be flushed.
See the HAProxy Configuration Manual for details about this option.
maxconnrate <number> maxconnrate <number>
Set the maximum number of connections per second to <number>. The SPOE will Set the maximum number of connections per second to <number>. The SPOE will
stop to open new connections if the maximum is reached and will wait to stop to open new connections if the maximum is reached and will wait to

View File

@ -30,6 +30,7 @@
#include <types/filters.h> #include <types/filters.h>
#include <types/freq_ctr.h> #include <types/freq_ctr.h>
#include <types/log.h>
#include <types/proxy.h> #include <types/proxy.h>
#include <types/sample.h> #include <types/sample.h>
#include <types/stream.h> #include <types/stream.h>

View File

@ -91,6 +91,9 @@ struct list curmphs;
struct list curgphs; struct list curgphs;
struct list curvars; struct list curvars;
/* list of log servers used during the parsing */
struct list curlogsrvs;
/* Pools used to allocate SPOE structs */ /* Pools used to allocate SPOE structs */
static struct pool_head *pool_head_spoe_ctx = NULL; static struct pool_head *pool_head_spoe_ctx = NULL;
static struct pool_head *pool_head_spoe_appctx = NULL; static struct pool_head *pool_head_spoe_appctx = NULL;
@ -2930,11 +2933,9 @@ spoe_init(struct proxy *px, struct flt_conf *fconf)
{ {
struct spoe_config *conf = fconf->conf; struct spoe_config *conf = fconf->conf;
memset(&conf->agent_fe, 0, sizeof(conf->agent_fe)); /* conf->agent_fe was already initialized during the config
init_new_proxy(&conf->agent_fe); * parsing. Finish initialization. */
conf->agent_fe.parent = conf->agent;
conf->agent_fe.last_change = now.tv_sec; conf->agent_fe.last_change = now.tv_sec;
conf->agent_fe.id = conf->agent->id;
conf->agent_fe.cap = PR_CAP_FE; conf->agent_fe.cap = PR_CAP_FE;
conf->agent_fe.mode = PR_MODE_TCP; conf->agent_fe.mode = PR_MODE_TCP;
conf->agent_fe.maxconn = 0; conf->agent_fe.maxconn = 0;
@ -3666,6 +3667,15 @@ cfg_parse_spoe_agent(const char *file, int linenum, char **args, int kwm)
cur_arg++; cur_arg++;
} }
} }
else if (!strcmp(args[0], "log")) {
char *errmsg = NULL;
if (!parse_logsrv(args, &curlogsrvs, (kwm == 1), &errmsg)) {
ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
}
else if (*args[0]) { else if (*args[0]) {
ha_alert("parsing [%s:%d] : unknown keyword '%s' in spoe-agent section.\n", ha_alert("parsing [%s:%d] : unknown keyword '%s' in spoe-agent section.\n",
file, linenum, args[0]); file, linenum, args[0]);
@ -3963,6 +3973,7 @@ parse_spoe_flt(char **args, int *cur_arg, struct proxy *px,
struct spoe_group *grp, *grpback; struct spoe_group *grp, *grpback;
struct spoe_placeholder *ph, *phback; struct spoe_placeholder *ph, *phback;
struct spoe_var_placeholder *vph, *vphback; struct spoe_var_placeholder *vph, *vphback;
struct logsrv *logsrv, *logsrvback;
char *file = NULL, *engine = NULL; char *file = NULL, *engine = NULL;
int ret, pos = *cur_arg + 1; int ret, pos = *cur_arg + 1;
@ -3971,6 +3982,7 @@ parse_spoe_flt(char **args, int *cur_arg, struct proxy *px,
LIST_INIT(&curmphs); LIST_INIT(&curmphs);
LIST_INIT(&curgphs); LIST_INIT(&curgphs);
LIST_INIT(&curvars); LIST_INIT(&curvars);
LIST_INIT(&curlogsrvs);
conf = calloc(1, sizeof(*conf)); conf = calloc(1, sizeof(*conf));
if (conf == NULL) { if (conf == NULL) {
@ -4287,6 +4299,19 @@ parse_spoe_flt(char **args, int *cur_arg, struct proxy *px,
conf->id = strdup(engine ? engine : curagent->id); conf->id = strdup(engine ? engine : curagent->id);
conf->agent = curagent; conf->agent = curagent;
/* Start agent's proxy initialization here. It will be finished during
* the filter init. */
memset(&conf->agent_fe, 0, sizeof(conf->agent_fe));
init_new_proxy(&conf->agent_fe);
conf->agent_fe.id = conf->agent->id;
conf->agent_fe.parent = conf->agent;
list_for_each_entry_safe(logsrv, logsrvback, &curlogsrvs, list) {
LIST_DEL(&logsrv->list);
LIST_ADDQ(&conf->agent_fe.logsrvs, &logsrv->list);
}
list_for_each_entry_safe(ph, phback, &curmphs, list) { list_for_each_entry_safe(ph, phback, &curmphs, list) {
LIST_DEL(&ph->list); LIST_DEL(&ph->list);
spoe_release_placeholder(ph); spoe_release_placeholder(ph);
@ -4347,6 +4372,10 @@ parse_spoe_flt(char **args, int *cur_arg, struct proxy *px,
LIST_DEL(&msg->list); LIST_DEL(&msg->list);
spoe_release_message(msg); spoe_release_message(msg);
} }
list_for_each_entry_safe(logsrv, logsrvback, &curlogsrvs, list) {
LIST_DEL(&logsrv->list);
free(logsrv);
}
free(conf); free(conf);
return -1; return -1;
} }