]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Add loggers dedicated to the SPOE agent
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 26 Mar 2018 15:19:01 +0000 (17:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 5 Apr 2018 13:13:54 +0000 (15:13 +0200)
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.

doc/SPOE.txt
include/types/spoe.h
src/flt_spoe.c

index ce119dc493f8daab284fd5b55ac1f8d66de2f238..36e174eb8934f5a55b6ed130f564fa639cff327c 100644 (file)
@@ -165,6 +165,7 @@ spoe-agent <name>
 
   following keywords are supported :
     - groups
+    - log
     - maxconnrate
     - maxerrrate
     - max-frame-size
@@ -196,6 +197,16 @@ groups <grp-name> ...
   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>
   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
index 9354b5536dd4a098f6dbd484c245dfc38af53625..b7d54f344d407b0d6ae9396dce5c35cb13ddad5e 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <types/filters.h>
 #include <types/freq_ctr.h>
+#include <types/log.h>
 #include <types/proxy.h>
 #include <types/sample.h>
 #include <types/stream.h>
index 760e26c603564e7447d10da7fdb9859893604b6b..0706634b73602573ad8ddde4a974c6d9d8f06712 100644 (file)
@@ -91,6 +91,9 @@ struct list curmphs;
 struct list curgphs;
 struct list curvars;
 
+/* list of log servers used during the parsing */
+struct list curlogsrvs;
+
 /* Pools used to allocate SPOE structs */
 static struct pool_head *pool_head_spoe_ctx = 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;
 
-        memset(&conf->agent_fe, 0, sizeof(conf->agent_fe));
-        init_new_proxy(&conf->agent_fe);
-        conf->agent_fe.parent = conf->agent;
+       /* conf->agent_fe was already initialized during the config
+        * parsing. Finish initialization. */
         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.mode = PR_MODE_TCP;
         conf->agent_fe.maxconn = 0;
@@ -3666,6 +3667,15 @@ cfg_parse_spoe_agent(const char *file, int linenum, char **args, int kwm)
                        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]) {
                ha_alert("parsing [%s:%d] : unknown keyword '%s' in spoe-agent section.\n",
                         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_placeholder     *ph, *phback;
        struct spoe_var_placeholder *vph, *vphback;
+       struct logsrv               *logsrv, *logsrvback;
        char                        *file = NULL, *engine = NULL;
        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(&curgphs);
        LIST_INIT(&curvars);
+       LIST_INIT(&curlogsrvs);
 
        conf = calloc(1, sizeof(*conf));
        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->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_DEL(&ph->list);
                spoe_release_placeholder(ph);
@@ -4347,6 +4372,10 @@ parse_spoe_flt(char **args, int *cur_arg, struct proxy *px,
                LIST_DEL(&msg->list);
                spoe_release_message(msg);
        }
+       list_for_each_entry_safe(logsrv, logsrvback, &curlogsrvs, list) {
+               LIST_DEL(&logsrv->list);
+               free(logsrv);
+       }
        free(conf);
        return -1;
 }