]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: opentracing: exclude the use of haproxy variables for the OpenTracing context
authorMiroslav Zagorac <mzagorac@haproxy.com>
Wed, 8 Sep 2021 18:56:05 +0000 (20:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 12 Sep 2021 05:07:13 +0000 (07:07 +0200)
Due to a recent change in the handling of haproxy variables, their use for
OpenTracing context transfer has been excluded from the compilation process.

The use of variables can be re-enabled if the newly defined variable
OT_USE_VARS is set to 1 when calling the 'make' utility.  However,
this should not be used for now as the compilation will end in error.

This change prevents the use of haproxy variables to convey the OpenTracing
context.  This means that the 'use-vars' parameter cannot be used in the
OpenTracing filter configuration for 'inject' and 'extract' operations.

An example configuration that uses this feature is in the test/ctx
directory, while the script to run that test is test/run-ctx.sh.

Then, the 'sess.ot.uuid' variable is no longer set when initializing the
OpenTracing session.  This means that this variable can still be used in
the OpenTracing configuration, but its contents will be empty.

Makefile
addons/ot/Makefile
addons/ot/include/filter.h
addons/ot/include/parser.h
addons/ot/src/event.c
addons/ot/src/filter.c
addons/ot/src/parser.c
addons/ot/src/scope.c

index d0a7862b678570436a30263ecfcdadc3b3752136..38412275c6c3433684d902d45765f0f1f72ead3f 100644 (file)
--- a/Makefile
+++ b/Makefile
 #   OT_INC         : force the include path to libopentracing-c-wrapper
 #   OT_LIB         : force the lib path to libopentracing-c-wrapper
 #   OT_RUNPATH     : add RUNPATH for libopentracing-c-wrapper to haproxy executable
+#   OT_USE_VARS    : allows the use of variables for the OpenTracing context
 #   IGNOREGIT      : ignore GIT commit versions if set.
 #   VERSION        : force haproxy version reporting.
 #   SUBVERS        : add a sub-version (eg: platform, model, ...).
index ef48ce49d3e0607bde0be8f857175b685669f7ca..0cc8c6aadb3a11b35952d8749a336a9b83793569 100644 (file)
@@ -3,6 +3,7 @@
 # OT_INC     : force the include path to libopentracing-c-wrapper
 # OT_LIB     : force the lib path to libopentracing-c-wrapper
 # OT_RUNPATH : add libopentracing-c-wrapper RUNPATH to haproxy executable
+# OT_USE_VARS : allows the use of variables for the OpenTracing context
 
 OT_DEFINE    =
 OT_CFLAGS    =
@@ -61,8 +62,13 @@ OPTIONS_OBJS += \
        addons/ot/src/parser.o      \
        addons/ot/src/pool.o        \
        addons/ot/src/scope.o       \
-       addons/ot/src/util.o        \
+       addons/ot/src/util.o
+
+ifneq ($(OT_USE_VARS),)
+OT_DEFINE     = -DUSE_OT_VARS
+OPTIONS_OBJS += \
        addons/ot/src/vars.o
+endif
 
 OPTIONS_CFLAGS  += $(OT_CFLAGS) -Iaddons/ot/include
 OPTIONS_LDFLAGS += $(OT_LDFLAGS)
index 0b36354e5b2ae483e452d69623999241a6616a0f..c97a0cc59431a8009356ca33bd1fcafe5c45f9df 100644 (file)
@@ -22,7 +22,7 @@
 
 #define FLT_OT_FMT_NAME           "'" FLT_OT_OPT_NAME "' : "
 #define FLT_OT_FMT_TYPE           "'filter' : "
-#define FTL_OT_VAR_UUID           "sess", "ot", "uuid"
+#define FLT_OT_VAR_UUID           "sess", "ot", "uuid"
 #define FLT_OT_ALERT(f, ...)      ha_alert(FLT_OT_FMT_TYPE FLT_OT_FMT_NAME f "\n", ##__VA_ARGS__)
 
 #define FLT_OT_CONDITION_IF       "if"
index 75a39cc0c153f4defb7cc98d3bb7afb24a992933..96939916da0fe74917fdaf771e646a554ae60b53 100644 (file)
        FLT_OT_PARSE_GROUP_DEF(    ID, 0, 1, 2, 2, "ot-group", " <name>") \
        FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, 0, 2, 0, "scopes",   " <name> ...")
 
+#ifdef USE_OT_VARS
+#  define FLT_OT_PARSE_SCOPE_INJECT_HELP    " <name-prefix> [use-vars] [use-headers]"
+#  define FLT_OT_PARSE_SCOPE_EXTRACT_HELP   " <name-prefix> [use-vars | use-headers]"
+#else
+#  define FLT_OT_PARSE_SCOPE_INJECT_HELP    " <name-prefix> [use-headers]"
+#  define FLT_OT_PARSE_SCOPE_EXTRACT_HELP   " <name-prefix> [use-headers]"
+#endif
+
+/*
+ * In case the possibility of working with OpenTracing context via HAProxyu
+ * variables is not used, args_max member of the structure flt_ot_parse_data
+ * should be reduced for 'inject' keyword.  However, this is not critical
+ * because in this case the 'use-vars' argument cannot be entered anyway,
+ * so I will not complicate it here with additional definitions.
+ */
 #define FLT_OT_PARSE_SCOPE_DEFINES                                                                                    \
        FLT_OT_PARSE_SCOPE_DEF(     ID, 0, 1, 2, 2, "ot-scope", " <name>")                                            \
        FLT_OT_PARSE_SCOPE_DEF(   SPAN, 0, 0, 2, 5, "span",     " <name> [<reference>] [root]")                       \
        FLT_OT_PARSE_SCOPE_DEF(    TAG, 1, 0, 3, 0, "tag",      " <name> <sample> ...")                               \
        FLT_OT_PARSE_SCOPE_DEF(    LOG, 1, 0, 3, 0, "log",      " <name> <sample> ...")                               \
        FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, 4, 3, 0, "baggage",  " <name> <sample> ...")                               \
-       FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, 3, 2, 4, "inject",   " <name-prefix> [use-vars] [use-headers]")            \
-       FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, 3, 2, 3, "extract",  " <name-prefix> [use-vars | use-headers]")            \
+       FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, 3, 2, 4, "inject",   FLT_OT_PARSE_SCOPE_INJECT_HELP)                       \
+       FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, 3, 2, 3, "extract",  FLT_OT_PARSE_SCOPE_EXTRACT_HELP)                      \
        FLT_OT_PARSE_SCOPE_DEF( FINISH, 0, 0, 2, 0, "finish",   " <name> ...")                                        \
        FLT_OT_PARSE_SCOPE_DEF(    ACL, 0, 1, 3, 0, "acl",      " <name> <criterion> [flags] [operator] <value> ...") \
        FLT_OT_PARSE_SCOPE_DEF(  EVENT, 0, 0, 2, 0, "event",    " <name> [{ if | unless } <condition>]")
index 90b582876be5fdb7de89c989c3f831403bc7d53a..0cb6b1d72722ce317f15090ec62eefd7a72e084d 100644 (file)
@@ -85,12 +85,14 @@ static int flt_ot_scope_run_span(struct stream *s, struct filter *f, struct chan
 
                        if (conf_span->ctx_flags & (FLT_OT_CTX_USE_VARS | FLT_OT_CTX_USE_HEADERS)) {
                                for (text_map = &(writer.text_map); i < text_map->count; i++) {
+#ifdef USE_OT_VARS
                                        if (!(conf_span->ctx_flags & FLT_OT_CTX_USE_VARS))
                                                /* Do nothing. */;
                                        else if (flt_ot_var_register(FLT_OT_VARS_SCOPE, conf_span->ctx_id, text_map->key[i], err) == -1)
                                                retval = FLT_OT_RET_ERROR;
                                        else if (flt_ot_var_set(s, FLT_OT_VARS_SCOPE, conf_span->ctx_id, text_map->key[i], text_map->value[i], dir, err) == -1)
                                                retval = FLT_OT_RET_ERROR;
+#endif
 
                                        if (!(conf_span->ctx_flags & FLT_OT_CTX_USE_HEADERS))
                                                /* Do nothing. */;
@@ -184,7 +186,7 @@ int flt_ot_scope_run(struct stream *s, struct filter *f, struct channel *chn, st
        }
 
        list_for_each_entry(conf_ctx, &(conf_scope->contexts), list) {
-               struct otc_text_map *text_map;
+               struct otc_text_map *text_map = NULL;
 
                FLT_OT_DBG(3, "run context '%s' -> '%s'", conf_scope->id, conf_ctx->id);
                FLT_OT_DBG_CONF_CONTEXT("run context ", conf_ctx);
@@ -195,8 +197,10 @@ int flt_ot_scope_run(struct stream *s, struct filter *f, struct channel *chn, st
                 */
                if (conf_ctx->flags & FLT_OT_CTX_USE_HEADERS)
                        text_map = flt_ot_http_headers_get(chn, conf_ctx->id, conf_ctx->id_len, err);
+#ifdef USE_OT_VARS
                else
                        text_map = flt_ot_vars_get(s, FLT_OT_VARS_SCOPE, conf_ctx->id, dir, err);
+#endif
 
                if (text_map != NULL) {
                        if (flt_ot_scope_context_init(f->ctx, conf->tracer->tracer, conf_ctx->id, conf_ctx->id_len, text_map, dir, err) == NULL)
@@ -314,7 +318,9 @@ int flt_ot_event_run(struct stream *s, struct filter *f, struct channel *chn, in
                        retval = FLT_OT_RET_ERROR;
        }
 
+#ifdef USE_OT_VARS
        flt_ot_vars_dump(s);
+#endif
        flt_ot_http_headers_dump(chn);
 
        FLT_OT_DBG(3, "event = %d, chn = %p, s->req = %p, s->res = %p", event, chn, &(s->req), &(s->res));
index 04c4a67f13cc80c7d928e8b676e0bb20a9619d55..bd71186a620d80c66092e3232f8699f497b4eb6b 100644 (file)
@@ -560,7 +560,9 @@ static int flt_ot_attach(struct stream *s, struct filter *f)
 
        FLT_OT_LOG(LOG_INFO, "%08x %08x", f->pre_analyzers, f->post_analyzers);
 
+#ifdef USE_OT_VARS
        flt_ot_vars_dump(s);
+#endif
        flt_ot_http_headers_dump(&(s->req));
 
        FLT_OT_RETURN(FLT_OT_RET_OK);
index e26ca18eee30e21f21fee2a3e8b2a99f54da316b..ae09e027e04fa8c85c89390fa463cb0dad8430e4 100644 (file)
@@ -720,8 +720,10 @@ static int flt_ot_parse_cfg_scope_ctx(char **args, int cur_arg, char **err)
 
        if (strcmp(args[cur_arg], FLT_OT_PARSE_CTX_USE_HEADERS) == 0)
                flags = FLT_OT_CTX_USE_HEADERS;
+#ifdef USE_OT_VARS
        else if (strcmp(args[cur_arg], FLT_OT_PARSE_CTX_USE_VARS) == 0)
                flags = FLT_OT_CTX_USE_VARS;
+#endif
        else
                FLT_OT_PARSE_ERR(err, "'%s' : invalid context storage type", args[0]);
 
@@ -939,8 +941,10 @@ static int flt_ot_parse_cfg_scope(const char *file, int linenum, char **args, in
                        conf_ctx->flags = FLT_OT_CTX_USE_HEADERS;
                else if (strcmp(args[2], FLT_OT_PARSE_CTX_USE_HEADERS) == 0)
                        conf_ctx->flags = FLT_OT_CTX_USE_HEADERS;
+#ifdef USE_OT_VARS
                else if (strcmp(args[2], FLT_OT_PARSE_CTX_USE_VARS) == 0)
                        conf_ctx->flags = FLT_OT_CTX_USE_VARS;
+#endif
                else
                        FLT_OT_PARSE_ERR(&err, "'%s' : invalid context storage type", args[2]);
        }
index 8d70a08d6240a010c7cff02013a471addedf359a..112f9d545494e9563aae0ab90d528901b886219c 100644 (file)
@@ -120,8 +120,14 @@ struct flt_ot_runtime_context *flt_ot_runtime_context_init(struct stream *s, str
                       (uint16_t)(retptr->uuid.clock_seq | UINT16_C(0x8000)),
                       (uint64_t)retptr->uuid.node);
 
-       if (flt_ot_var_register(FTL_OT_VAR_UUID, err) != -1)
-               (void)flt_ot_var_set(s, FTL_OT_VAR_UUID, retptr->uuid.s, SMP_OPT_DIR_REQ, err);
+#ifdef USE_OT_VARS
+       /*
+        * The HAProxy variable 'sess.ot.uuid' is registered here,
+        * after which its value is set to runtime context UUID.
+        */
+       if (flt_ot_var_register(FLT_OT_VAR_UUID, err) != -1)
+               (void)flt_ot_var_set(s, FLT_OT_VAR_UUID, retptr->uuid.s, SMP_OPT_DIR_REQ, err);
+#endif
 
        FLT_OT_DBG_RUNTIME_CONTEXT("session context: ", retptr);
 
@@ -610,7 +616,9 @@ void flt_ot_scope_free_unused(struct flt_ot_runtime_context *rt_ctx, struct chan
                                 * the context in question should be deleted.
                                 */
                                (void)flt_ot_http_headers_remove(chn, ctx->id, NULL);
+#ifdef USE_OT_VARS
                                (void)flt_ot_vars_unset(rt_ctx->stream, FLT_OT_VARS_SCOPE, ctx->id, ctx->smp_opt_dir, NULL);
+#endif
 
                                flt_ot_scope_context_free(&ctx);
                        }