CLEANUP: opentracing: use the haproxy function to generate uuid

To avoid duplicate source code, the original haproxy function is used to
generate the OpenTracing runtime context UUID.

Also, the structure flt_ot_runtime_context is simplified because the
detailed definition of UUID is removed from it (struct flt_ot_uuid),
ie the UUID is left only in the form of a string.
This commit is contained in:
Miroslav Zagorac 2021-09-09 10:31:12 +02:00 committed by Willy Tarreau
parent 71cb1ab6b9
commit a75f3404c8
2 changed files with 9 additions and 29 deletions

View File

@ -40,10 +40,10 @@
FLT_OT_DBG(3, "%s%p:{ %p %d %p %p %d }", \ FLT_OT_DBG(3, "%s%p:{ %p %d %p %p %d }", \
(f), (a), (a)->tags, (a)->num_tags, (a)->baggage, (a)->log_fields, (a)->num_log_fields) (f), (a), (a)->tags, (a)->num_tags, (a)->baggage, (a)->log_fields, (a)->num_log_fields)
#define FLT_OT_DBG_RUNTIME_CONTEXT(f,a) \ #define FLT_OT_DBG_RUNTIME_CONTEXT(f,a) \
FLT_OT_DBG(3, "%s%p:{ %p %p { %016" PRIx64 " %016" PRIx64 " '%s' } %hhu %hhu 0x%02hhx 0x%08x %s %s }", \ FLT_OT_DBG(3, "%s%p:{ %p %p '%s' %hhu %hhu 0x%02hhx 0x%08x %s %s }", \
(f), (a), (a)->stream, (a)->filter, (a)->uuid.u64[0], (a)->uuid.u64[1], (a)->uuid.s, (a)->flag_harderr, \ (f), (a), (a)->stream, (a)->filter, (a)->uuid, (a)->flag_harderr, \
(a)->flag_disabled, (a)->logging, (a)->analyzers, flt_ot_list_debug(&((a)->spans)), \ (a)->flag_disabled, (a)->logging, (a)->analyzers, flt_ot_list_debug(&((a)->spans)), \
flt_ot_list_debug(&((a)->contexts))) flt_ot_list_debug(&((a)->contexts)))
#define FLT_OT_CONST_STR_HDR(a) \ #define FLT_OT_CONST_STR_HDR(a) \
@ -82,26 +82,11 @@ struct flt_ot_scope_context {
struct list list; /* Used to chain this structure. */ struct list list; /* Used to chain this structure. */
}; };
struct flt_ot_uuid {
union {
uint64_t u64[2];
uint8_t u8[16];
struct {
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_and_version;
uint16_t clock_seq;
uint64_t node : 48;
} __attribute__((packed));
};
char s[40];
};
/* The runtime filter context attached to a stream. */ /* The runtime filter context attached to a stream. */
struct flt_ot_runtime_context { struct flt_ot_runtime_context {
struct stream *stream; /* The stream to which the filter is attached. */ struct stream *stream; /* The stream to which the filter is attached. */
struct filter *filter; /* The OpenTracing filter. */ struct filter *filter; /* The OpenTracing filter. */
struct flt_ot_uuid uuid; /* Randomly generated UUID. */ char uuid[40]; /* Randomly generated UUID. */
bool flag_harderr; /* [0 1] */ bool flag_harderr; /* [0 1] */
bool flag_disabled; /* [0 1] */ bool flag_disabled; /* [0 1] */
uint8_t logging; /* [0 1 3] */ uint8_t logging; /* [0 1 3] */

View File

@ -95,6 +95,7 @@ void flt_ot_pools_info(void)
struct flt_ot_runtime_context *flt_ot_runtime_context_init(struct stream *s, struct filter *f, char **err) struct flt_ot_runtime_context *flt_ot_runtime_context_init(struct stream *s, struct filter *f, char **err)
{ {
const struct flt_ot_conf *conf = FLT_OT_CONF(f); const struct flt_ot_conf *conf = FLT_OT_CONF(f);
struct buffer uuid;
struct flt_ot_runtime_context *retptr = NULL; struct flt_ot_runtime_context *retptr = NULL;
FLT_OT_FUNC("%p, %p, %p:%p", s, f, FLT_OT_DPTR_ARGS(err)); FLT_OT_FUNC("%p, %p, %p:%p", s, f, FLT_OT_DPTR_ARGS(err));
@ -105,20 +106,14 @@ struct flt_ot_runtime_context *flt_ot_runtime_context_init(struct stream *s, str
retptr->stream = s; retptr->stream = s;
retptr->filter = f; retptr->filter = f;
retptr->uuid.u64[0] = ha_random64();
retptr->uuid.u64[1] = ha_random64();
retptr->flag_harderr = conf->tracer->flag_harderr; retptr->flag_harderr = conf->tracer->flag_harderr;
retptr->flag_disabled = conf->tracer->flag_disabled; retptr->flag_disabled = conf->tracer->flag_disabled;
retptr->logging = conf->tracer->logging; retptr->logging = conf->tracer->logging;
LIST_INIT(&(retptr->spans)); LIST_INIT(&(retptr->spans));
LIST_INIT(&(retptr->contexts)); LIST_INIT(&(retptr->contexts));
(void)snprintf(retptr->uuid.s, sizeof(retptr->uuid.s), "%08x-%04hx-%04hx-%04hx-%012" PRIx64, uuid = b_make(retptr->uuid, sizeof(retptr->uuid), 0, 0);
retptr->uuid.time_low, ha_generate_uuid(&uuid);
retptr->uuid.time_mid,
(uint16_t)((retptr->uuid.time_hi_and_version & UINT16_C(0xfff)) | UINT16_C(0x4000)),
(uint16_t)(retptr->uuid.clock_seq | UINT16_C(0x8000)),
(uint64_t)retptr->uuid.node);
#ifdef USE_OT_VARS #ifdef USE_OT_VARS
/* /*
@ -126,7 +121,7 @@ struct flt_ot_runtime_context *flt_ot_runtime_context_init(struct stream *s, str
* after which its value is set to runtime context UUID. * after which its value is set to runtime context UUID.
*/ */
if (flt_ot_var_register(FLT_OT_VAR_UUID, err) != -1) 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); (void)flt_ot_var_set(s, FLT_OT_VAR_UUID, retptr->uuid, SMP_OPT_DIR_REQ, err);
#endif #endif
FLT_OT_DBG_RUNTIME_CONTEXT("session context: ", retptr); FLT_OT_DBG_RUNTIME_CONTEXT("session context: ", retptr);