1 /*** 2 * Copyright 2020 HAProxy Technologies 3 * 4 * This file is part of the HAProxy OpenTracing filter. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 #ifndef _OPENTRACING_CONF_H_ 21 #define _OPENTRACING_CONF_H_ 22 23 #define FLT_OT_CONF(f) ((struct flt_ot_conf *)FLT_CONF(f)) 24 #define FLT_OT_CONF_HDR_FMT "%p:{ { '%.*s' %zu %d } " 25 #define FLT_OT_CONF_HDR_ARGS(a,b) (a), (int)(a)->b##_len, (a)->b, (a)->b##_len, (a)->cfg_line 26 #define FLT_OT_STR_HDR_ARGS(a,b) (a)->b, (a)->b##_len 27 28 #define FLT_OT_DBG_CONF_SAMPLE_EXPR(f,a) \ 29 FLT_OT_DBG(3, "%s%p:{ '%s' %p }", (f), (a), (a)->value, (a)->expr) 30 31 #define FLT_OT_DBG_CONF_SAMPLE(f,a) \ 32 FLT_OT_DBG(3, "%s%p:{ '%s' '%s' %s %d }", \ 33 (f), (a), (a)->key, (a)->value, flt_ot_list_debug(&((a)->exprs)), (a)->num_exprs) 34 35 #define FLT_OT_DBG_CONF_STR(f,a) \ 36 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "}", FLT_OT_CONF_HDR_ARGS(a, str)) 37 38 #define FLT_OT_DBG_CONF_CONTEXT(f,a) \ 39 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "0x%02hhx }", FLT_OT_CONF_HDR_ARGS(a, id), (a)->flags) 40 41 #define FLT_OT_DBG_CONF_SPAN(f,a) \ 42 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "'%s' %zu %d '%s' %zu %hhu 0x%02hhx %s %s %s }", \ 43 FLT_OT_CONF_HDR_ARGS(a, id), FLT_OT_STR_HDR_ARGS(a, ref_id), (a)->ref_type, \ 44 FLT_OT_STR_HDR_ARGS(a, ctx_id), (a)->flag_root, (a)->ctx_flags, flt_ot_list_debug(&((a)->tags)), \ 45 flt_ot_list_debug(&((a)->logs)), flt_ot_list_debug(&((a)->baggages))) 46 47 #define FLT_OT_DBG_CONF_SCOPE(f,a) \ 48 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "%hhu %d %s %p %s %s %s }", \ 49 FLT_OT_CONF_HDR_ARGS(a, id), (a)->flag_used, (a)->event, flt_ot_list_debug(&((a)->acls)), \ 50 (a)->cond, flt_ot_list_debug(&((a)->contexts)), flt_ot_list_debug(&((a)->spans)), \ 51 flt_ot_list_debug(&((a)->finish))) 52 53 #define FLT_OT_DBG_CONF_GROUP(f,a) \ 54 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "%hhu %s }", \ 55 FLT_OT_CONF_HDR_ARGS(a, id), (a)->flag_used, flt_ot_list_debug(&((a)->ph_scopes))) 56 57 #define FLT_OT_DBG_CONF_PH(f,a) \ 58 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "%p }", FLT_OT_CONF_HDR_ARGS(a, id), (a)->ptr) 59 60 #define FLT_OT_DBG_CONF_TRACER(f,a) \ 61 FLT_OT_DBG(3, f FLT_OT_CONF_HDR_FMT "'%s' %p '%s' %p %u %hhu %hhu 0x%02hhx %p:%s 0x%08x %s %s %s }", \ 62 FLT_OT_CONF_HDR_ARGS(a, id), (a)->config, (a)->cfgbuf, (a)->plugin, (a)->tracer, (a)->rate_limit, (a)->flag_harderr, \ 63 (a)->flag_disabled, (a)->logging, &((a)->proxy_log), flt_ot_list_debug(&((a)->proxy_log.logsrvs)), (a)->analyzers, \ 64 flt_ot_list_debug(&((a)->acls)), flt_ot_list_debug(&((a)->ph_groups)), flt_ot_list_debug(&((a)->ph_scopes))) 65 66 #define FLT_OT_DBG_CONF(f,a) \ 67 FLT_OT_DBG(3, "%s%p:{ %p '%s' '%s' %p %s %s }", \ 68 (f), (a), (a)->proxy, (a)->id, (a)->cfg_file, (a)->tracer, \ 69 flt_ot_list_debug(&((a)->groups)), flt_ot_list_debug(&((a)->scopes))) 70 71 #define FLT_OT_STR_HDR(a) \ 72 struct { \ 73 char *a; \ 74 size_t a##_len; \ 75 } 76 77 #define FLT_OT_CONF_HDR(a) \ 78 struct { \ 79 FLT_OT_STR_HDR(a); \ 80 int cfg_line; \ 81 struct list list; \ 82 } 83 84 85 struct flt_ot_conf_hdr { 86 FLT_OT_CONF_HDR(id); 87 }; 88 89 /* flt_ot_conf_sample->exprs */ 90 struct flt_ot_conf_sample_expr { 91 FLT_OT_CONF_HDR(value); /* The sample value. */ 92 struct sample_expr *expr; /* The sample expression. */ 93 }; 94 95 /* 96 * flt_ot_conf_span->tags 97 * flt_ot_conf_span->logs 98 * flt_ot_conf_span->baggages 99 */ 100 struct flt_ot_conf_sample { 101 FLT_OT_CONF_HDR(key); /* The sample name. */ 102 char *value; /* The sample content. */ 103 struct list exprs; /* Used to chain sample expressions. */ 104 int num_exprs; /* Number of defined expressions. */ 105 }; 106 107 /* flt_ot_conf_scope->finish */ 108 struct flt_ot_conf_str { 109 FLT_OT_CONF_HDR(str); /* String content/length. */ 110 }; 111 112 /* flt_ot_conf_scope->contexts */ 113 struct flt_ot_conf_context { 114 FLT_OT_CONF_HDR(id); /* The name of the context. */ 115 uint8_t flags; /* The type of storage from which the span context is extracted. */ 116 }; 117 118 /* flt_ot_conf_scope->spans */ 119 struct flt_ot_conf_span { 120 FLT_OT_CONF_HDR(id); /* The name of the span. */ 121 FLT_OT_STR_HDR(ref_id); /* The reference name, if used. */ 122 int ref_type; /* The reference type. */ 123 FLT_OT_STR_HDR(ctx_id); /* The span context name, if used. */ 124 uint8_t ctx_flags; /* The type of storage used for the span context. */ 125 bool flag_root; /* Whether this is a root span. */ 126 struct list tags; /* The set of key:value tags. */ 127 struct list logs; /* The set of key:value logs. */ 128 struct list baggages; /* The set of key:value baggage items. */ 129 }; 130 131 struct flt_ot_conf_scope { 132 FLT_OT_CONF_HDR(id); /* The scope name. */ 133 bool flag_used; /* The indication that the scope is being used. */ 134 int event; /* FLT_OT_EVENT_* */ 135 struct list acls; /* ACLs declared on this scope. */ 136 struct acl_cond *cond; /* ACL condition to meet. */ 137 struct list contexts; /* Declared contexts. */ 138 struct list spans; /* Declared spans. */ 139 struct list finish; /* The list of spans to be finished. */ 140 }; 141 142 struct flt_ot_conf_group { 143 FLT_OT_CONF_HDR(id); /* The group name. */ 144 bool flag_used; /* The indication that the group is being used. */ 145 struct list ph_scopes; /* List of all used scopes. */ 146 }; 147 148 struct flt_ot_conf_ph { 149 FLT_OT_CONF_HDR(id); /* The scope/group name. */ 150 void *ptr; /* Pointer to real placeholder structure. */ 151 }; 152 #define flt_ot_conf_ph_group flt_ot_conf_ph 153 #define flt_ot_conf_ph_scope flt_ot_conf_ph 154 155 struct flt_ot_conf_tracer { 156 FLT_OT_CONF_HDR(id); /* The tracer name. */ 157 char *config; /* The OpenTracing configuration file name. */ 158 char *cfgbuf; /* The OpenTracing configuration. */ 159 char *plugin; /* The OpenTracing plugin library file name. */ 160 struct otc_tracer *tracer; /* The OpenTracing tracer handle. */ 161 uint32_t rate_limit; /* [0 2^32-1] <-> [0.0 100.0] */ 162 bool flag_harderr; /* [0 1] */ 163 bool flag_disabled; /* [0 1] */ 164 uint8_t logging; /* [0 1 3] */ 165 struct proxy proxy_log; /* The log server list. */ 166 uint analyzers; /* Defined channel analyzers. */ 167 struct list acls; /* ACLs declared on this tracer. */ 168 struct list ph_groups; /* List of all used groups. */ 169 struct list ph_scopes; /* List of all used scopes. */ 170 }; 171 172 struct flt_ot_counters { 173 #ifdef DEBUG_OT 174 struct { 175 bool flag_used; /* Whether this event is used. */ 176 uint64_t htx[2]; /* htx_is_empty() function result counter. */ 177 } event[FLT_OT_EVENT_MAX]; 178 #endif 179 180 uint64_t disabled[2]; /* How many times stream processing is disabled. */ 181 }; 182 183 /* The OpenTracing filter configuration. */ 184 struct flt_ot_conf { 185 struct proxy *proxy; /* Proxy owning the filter. */ 186 char *id; /* The OpenTracing filter id. */ 187 char *cfg_file; /* The OpenTracing filter configuration file name. */ 188 struct flt_ot_conf_tracer *tracer; /* There can only be one tracer. */ 189 struct list groups; /* List of all available groups. */ 190 struct list scopes; /* List of all available scopes. */ 191 struct flt_ot_counters cnt; /* Various counters related to filter operation. */ 192 }; 193 194 195 #define flt_ot_conf_ph_group_free flt_ot_conf_ph_free 196 #define flt_ot_conf_ph_scope_free flt_ot_conf_ph_free 197 198 struct flt_ot_conf_ph *flt_ot_conf_ph_init(const char *id, int linenum, struct list *head, char **err); 199 void flt_ot_conf_ph_free(struct flt_ot_conf_ph **ptr); 200 struct flt_ot_conf_sample_expr *flt_ot_conf_sample_expr_init(const char *id, int linenum, struct list *head, char **err); 201 void flt_ot_conf_sample_expr_free(struct flt_ot_conf_sample_expr **ptr); 202 struct flt_ot_conf_sample *flt_ot_conf_sample_init(char **args, int linenum, struct list *head, char **err); 203 void flt_ot_conf_sample_free(struct flt_ot_conf_sample **ptr); 204 struct flt_ot_conf_str *flt_ot_conf_str_init(const char *id, int linenum, struct list *head, char **err); 205 void flt_ot_conf_str_free(struct flt_ot_conf_str **ptr); 206 struct flt_ot_conf_context *flt_ot_conf_context_init(const char *id, int linenum, struct list *head, char **err); 207 void flt_ot_conf_context_free(struct flt_ot_conf_context **ptr); 208 struct flt_ot_conf_span *flt_ot_conf_span_init(const char *id, int linenum, struct list *head, char **err); 209 void flt_ot_conf_span_free(struct flt_ot_conf_span **ptr); 210 struct flt_ot_conf_scope *flt_ot_conf_scope_init(const char *id, int linenum, struct list *head, char **err); 211 void flt_ot_conf_scope_free(struct flt_ot_conf_scope **ptr); 212 struct flt_ot_conf_group *flt_ot_conf_group_init(const char *id, int linenum, struct list *head, char **err); 213 void flt_ot_conf_group_free(struct flt_ot_conf_group **ptr); 214 struct flt_ot_conf_tracer *flt_ot_conf_tracer_init(const char *id, int linenum, char **err); 215 void flt_ot_conf_tracer_free(struct flt_ot_conf_tracer **ptr); 216 struct flt_ot_conf *flt_ot_conf_init(struct proxy *px); 217 void flt_ot_conf_free(struct flt_ot_conf **ptr); 218 219 #endif /* _OPENTRACING_CONF_H_ */ 220 221 /* 222 * Local variables: 223 * c-indent-level: 8 224 * c-basic-offset: 8 225 * End: 226 * 227 * vi: noexpandtab shiftwidth=8 tabstop=8 228 */ 229