blob: 97df12e0564610cc63b3cb3e47ad0581cde7f138 [file] [log] [blame]
Miroslav Zagorac70230c62020-12-09 16:54:31 +01001/***
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' '%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)->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
85struct flt_ot_conf_hdr {
86 FLT_OT_CONF_HDR(id);
87};
88
89/* flt_ot_conf_sample->exprs */
90struct 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 */
100struct 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 */
108struct flt_ot_conf_str {
109 FLT_OT_CONF_HDR(str); /* String content/length. */
110};
111
112/* flt_ot_conf_scope->contexts */
113struct 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 */
119struct 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
131struct 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
142struct 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
148struct 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
155struct flt_ot_conf_tracer {
156 FLT_OT_CONF_HDR(id); /* The tracer name. */
157 char *config; /* The OpenTracing configuration file name. */
158 char *plugin; /* The OpenTracing plugin library file name. */
159 struct otc_tracer *tracer; /* The OpenTracing tracer handle. */
160 uint32_t rate_limit; /* [0 2^32-1] <-> [0.0 100.0] */
161 bool flag_harderr; /* [0 1] */
162 bool flag_disabled; /* [0 1] */
163 uint8_t logging; /* [0 1 3] */
164 struct proxy proxy_log; /* The log server list. */
165 uint analyzers; /* Defined channel analyzers. */
166 struct list acls; /* ACLs declared on this tracer. */
167 struct list ph_groups; /* List of all used groups. */
168 struct list ph_scopes; /* List of all used scopes. */
169};
170
171struct flt_ot_counters {
172#ifdef DEBUG_OT
173 struct {
174 bool flag_used; /* Whether this event is used. */
175 uint64_t htx[2]; /* htx_is_empty() function result counter. */
176 } event[FLT_OT_EVENT_MAX];
177#endif
178
179 uint64_t disabled[2]; /* How many times stream processing is disabled. */
180};
181
182/* The OpenTracing filter configuration. */
183struct flt_ot_conf {
184 struct proxy *proxy; /* Proxy owning the filter. */
185 char *id; /* The OpenTracing filter id. */
186 char *cfg_file; /* The OpenTracing filter configuration file name. */
187 struct flt_ot_conf_tracer *tracer; /* There can only be one tracer. */
188 struct list groups; /* List of all available groups. */
189 struct list scopes; /* List of all available scopes. */
190 struct flt_ot_counters cnt; /* Various counters related to filter operation. */
191};
192
193
194#define flt_ot_conf_ph_group_free flt_ot_conf_ph_free
195#define flt_ot_conf_ph_scope_free flt_ot_conf_ph_free
196
197struct flt_ot_conf_ph *flt_ot_conf_ph_init(const char *id, int linenum, struct list *head, char **err);
198void flt_ot_conf_ph_free(struct flt_ot_conf_ph **ptr);
199struct flt_ot_conf_sample_expr *flt_ot_conf_sample_expr_init(const char *id, int linenum, struct list *head, char **err);
200void flt_ot_conf_sample_expr_free(struct flt_ot_conf_sample_expr **ptr);
201struct flt_ot_conf_sample *flt_ot_conf_sample_init(char **args, int linenum, struct list *head, char **err);
202void flt_ot_conf_sample_free(struct flt_ot_conf_sample **ptr);
203struct flt_ot_conf_str *flt_ot_conf_str_init(const char *id, int linenum, struct list *head, char **err);
204void flt_ot_conf_str_free(struct flt_ot_conf_str **ptr);
205struct flt_ot_conf_context *flt_ot_conf_context_init(const char *id, int linenum, struct list *head, char **err);
206void flt_ot_conf_context_free(struct flt_ot_conf_context **ptr);
207struct flt_ot_conf_span *flt_ot_conf_span_init(const char *id, int linenum, struct list *head, char **err);
208void flt_ot_conf_span_free(struct flt_ot_conf_span **ptr);
209struct flt_ot_conf_scope *flt_ot_conf_scope_init(const char *id, int linenum, struct list *head, char **err);
210void flt_ot_conf_scope_free(struct flt_ot_conf_scope **ptr);
211struct flt_ot_conf_group *flt_ot_conf_group_init(const char *id, int linenum, struct list *head, char **err);
212void flt_ot_conf_group_free(struct flt_ot_conf_group **ptr);
213struct flt_ot_conf_tracer *flt_ot_conf_tracer_init(const char *id, int linenum, char **err);
214void flt_ot_conf_tracer_free(struct flt_ot_conf_tracer **ptr);
215struct flt_ot_conf *flt_ot_conf_init(struct proxy *px);
216void flt_ot_conf_free(struct flt_ot_conf **ptr);
217
218#endif /* _OPENTRACING_CONF_H_ */
219
220/*
221 * Local variables:
222 * c-indent-level: 8
223 * c-basic-offset: 8
224 * End:
225 *
226 * vi: noexpandtab shiftwidth=8 tabstop=8
227 */