blob: 96939916da0fe74917fdaf771e646a554ae60b53 [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_PARSER_H_
21#define _OPENTRACING_PARSER_H_
22
23#define FLT_OT_SCOPE "OT"
24
25/*
26 * filter FLT_OT_OPT_NAME FLT_OT_OPT_FILTER_ID <FLT_OT_OPT_FILTER_ID_DEFAULT> FLT_OT_OPT_CONFIG <file>
27 */
28#define FLT_OT_OPT_NAME "opentracing"
29#define FLT_OT_OPT_FILTER_ID "id"
30#define FLT_OT_OPT_FILTER_ID_DEFAULT "ot-filter"
31#define FLT_OT_OPT_CONFIG "config"
32
33#define FLT_OT_PARSE_SECTION_TRACER_ID "ot-tracer"
34#define FLT_OT_PARSE_SECTION_GROUP_ID "ot-group"
35#define FLT_OT_PARSE_SECTION_SCOPE_ID "ot-scope"
36
37#define FLT_OT_PARSE_SPAN_ROOT "root"
38#define FLT_OT_PARSE_SPAN_REF_CHILD "child-of"
39#define FLT_OT_PARSE_SPAN_REF_FOLLOWS "follows-from"
40#define FLT_OT_PARSE_CTX_AUTONAME "-"
Miroslav Zagoraca8bdf2b2021-04-14 11:47:28 +020041#define FLT_OT_PARSE_CTX_IGNORE_NAME '-'
Miroslav Zagorac70230c62020-12-09 16:54:31 +010042#define FLT_OT_PARSE_CTX_USE_HEADERS "use-headers"
43#define FLT_OT_PARSE_CTX_USE_VARS "use-vars"
44#define FLT_OT_PARSE_OPTION_HARDERR "hard-errors"
45#define FLT_OT_PARSE_OPTION_DISABLED "disabled"
46#define FLT_OT_PARSE_OPTION_NOLOGNORM "dontlog-normal"
47
48/*
49 * A description of the macro arguments can be found in the structure
50 * flt_ot_parse_data definition
51 */
52#define FLT_OT_PARSE_TRACER_DEFINES \
53 FLT_OT_PARSE_TRACER_DEF( ID, 0, 1, 2, 2, "ot-tracer", " <name>") \
54 FLT_OT_PARSE_TRACER_DEF( ACL, 0, 1, 3, 0, "acl", " <name> <criterion> [flags] [operator] <value> ...") \
55 FLT_OT_PARSE_TRACER_DEF( LOG, 0, 1, 2, 0, "log", " { global | <addr> [len <len>] [format <fmt>] <facility> [<level> [<minlevel>]] }") \
56 FLT_OT_PARSE_TRACER_DEF( CONFIG, 0, 0, 2, 2, "config", " <file>") \
57 FLT_OT_PARSE_TRACER_DEF( PLUGIN, 0, 0, 2, 2, "plugin", " <file>") \
58 FLT_OT_PARSE_TRACER_DEF( GROUPS, 0, 0, 2, 0, "groups", " <name> ...") \
59 FLT_OT_PARSE_TRACER_DEF( SCOPES, 0, 0, 2, 0, "scopes", " <name> ...") \
60 FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, 0, 2, 2, "rate-limit", " <value>") \
61 FLT_OT_PARSE_TRACER_DEF( OPTION, 0, 0, 2, 2, "option", " { disabled | dontlog-normal | hard-errors }") \
62 FLT_OT_PARSE_TRACER_DEF(DEBUG_LEVEL, 0, 0, 2, 2, "debug-level", " <value>")
63
64#define FLT_OT_PARSE_GROUP_DEFINES \
65 FLT_OT_PARSE_GROUP_DEF( ID, 0, 1, 2, 2, "ot-group", " <name>") \
66 FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, 0, 2, 0, "scopes", " <name> ...")
67
Miroslav Zagorac4cb2c832021-09-08 20:56:05 +020068#ifdef USE_OT_VARS
69# define FLT_OT_PARSE_SCOPE_INJECT_HELP " <name-prefix> [use-vars] [use-headers]"
70# define FLT_OT_PARSE_SCOPE_EXTRACT_HELP " <name-prefix> [use-vars | use-headers]"
71#else
72# define FLT_OT_PARSE_SCOPE_INJECT_HELP " <name-prefix> [use-headers]"
73# define FLT_OT_PARSE_SCOPE_EXTRACT_HELP " <name-prefix> [use-headers]"
74#endif
75
76/*
77 * In case the possibility of working with OpenTracing context via HAProxyu
78 * variables is not used, args_max member of the structure flt_ot_parse_data
79 * should be reduced for 'inject' keyword. However, this is not critical
80 * because in this case the 'use-vars' argument cannot be entered anyway,
81 * so I will not complicate it here with additional definitions.
82 */
Miroslav Zagorac70230c62020-12-09 16:54:31 +010083#define FLT_OT_PARSE_SCOPE_DEFINES \
84 FLT_OT_PARSE_SCOPE_DEF( ID, 0, 1, 2, 2, "ot-scope", " <name>") \
85 FLT_OT_PARSE_SCOPE_DEF( SPAN, 0, 0, 2, 5, "span", " <name> [<reference>] [root]") \
86 FLT_OT_PARSE_SCOPE_DEF( TAG, 1, 0, 3, 0, "tag", " <name> <sample> ...") \
87 FLT_OT_PARSE_SCOPE_DEF( LOG, 1, 0, 3, 0, "log", " <name> <sample> ...") \
88 FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, 4, 3, 0, "baggage", " <name> <sample> ...") \
Miroslav Zagorac4cb2c832021-09-08 20:56:05 +020089 FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, 3, 2, 4, "inject", FLT_OT_PARSE_SCOPE_INJECT_HELP) \
90 FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, 3, 2, 3, "extract", FLT_OT_PARSE_SCOPE_EXTRACT_HELP) \
Miroslav Zagorac70230c62020-12-09 16:54:31 +010091 FLT_OT_PARSE_SCOPE_DEF( FINISH, 0, 0, 2, 0, "finish", " <name> ...") \
92 FLT_OT_PARSE_SCOPE_DEF( ACL, 0, 1, 3, 0, "acl", " <name> <criterion> [flags] [operator] <value> ...") \
93 FLT_OT_PARSE_SCOPE_DEF( EVENT, 0, 0, 2, 0, "event", " <name> [{ if | unless } <condition>]")
94
95enum FLT_OT_PARSE_TRACER_enum {
96#define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_TRACER_##a,
97 FLT_OT_PARSE_TRACER_DEFINES
98#undef FLT_OT_PARSE_TRACER_DEF
99};
100
101enum FLT_OT_PARSE_GROUP_enum {
102#define FLT_OT_PARSE_GROUP_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_GROUP_##a,
103 FLT_OT_PARSE_GROUP_DEFINES
104#undef FLT_OT_PARSE_GROUP_DEF
105};
106
107enum FLT_OT_PARSE_SCOPE_enum {
108#define FLT_OT_PARSE_SCOPE_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_SCOPE_##a,
109 FLT_OT_PARSE_SCOPE_DEFINES
110#undef FLT_OT_PARSE_SCOPE_DEF
111};
112
113enum FLT_OT_CTX_USE_enum {
114 FLT_OT_CTX_USE_VARS = 1 << 0,
115 FLT_OT_CTX_USE_HEADERS = 1 << 1,
116};
117
118struct flt_ot_parse_data {
119 int keyword; /* Keyword index. */
120 bool flag_check_id; /* Whether the group ID must be defined for the keyword. */
121 int check_name; /* Checking allowed characters in the name. */
122 int args_min; /* The minimum number of arguments required. */
123 int args_max; /* The maximum number of arguments allowed. */
124 const char *name; /* Keyword name. */
125 const char *usage; /* Usage text to be printed in case of an error. */
126};
127
128#define FLT_OT_PARSE_WARNING(f, ...) \
129 ha_warning("parsing [%s:%d] : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'" f "'\n", ##__VA_ARGS__);
130#define FLT_OT_PARSE_ALERT(f, ...) \
131 do { \
132 ha_alert("parsing [%s:%d] : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'" f "'\n", ##__VA_ARGS__); \
133 \
134 retval |= ERR_ABORT | ERR_ALERT; \
135 } while (0)
136#define FLT_OT_POST_PARSE_ALERT(f, ...) \
137 FLT_OT_PARSE_ALERT(f, flt_ot_current_config->cfg_file, ##__VA_ARGS__)
138
139#define FLT_OT_PARSE_ERR(e,f, ...) \
140 do { \
141 if (*(e) == NULL) \
142 (void)memprintf((e), f, ##__VA_ARGS__); \
143 \
144 retval |= ERR_ABORT | ERR_ALERT; \
145 } while (0)
146#define FLT_OT_PARSE_IFERR_ALERT() \
147 do { \
148 if (err == NULL) \
149 break; \
150 \
151 FLT_OT_PARSE_ALERT("%s", file, linenum, err); \
152 FLT_OT_ERR_FREE(err); \
153 } while (0)
154
155#endif /* _OPENTRACING_PARSER_H_ */
156
157/*
158 * Local variables:
159 * c-indent-level: 8
160 * c-basic-offset: 8
161 * End:
162 *
163 * vi: noexpandtab shiftwidth=8 tabstop=8
164 */