blob: 5e7b298d58965edd5ccef7e2b88e39429b116421 [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 "-"
41#define FLT_OT_PARSE_CTX_USE_HEADERS "use-headers"
42#define FLT_OT_PARSE_CTX_USE_VARS "use-vars"
43#define FLT_OT_PARSE_OPTION_HARDERR "hard-errors"
44#define FLT_OT_PARSE_OPTION_DISABLED "disabled"
45#define FLT_OT_PARSE_OPTION_NOLOGNORM "dontlog-normal"
46
47/*
48 * A description of the macro arguments can be found in the structure
49 * flt_ot_parse_data definition
50 */
51#define FLT_OT_PARSE_TRACER_DEFINES \
52 FLT_OT_PARSE_TRACER_DEF( ID, 0, 1, 2, 2, "ot-tracer", " <name>") \
53 FLT_OT_PARSE_TRACER_DEF( ACL, 0, 1, 3, 0, "acl", " <name> <criterion> [flags] [operator] <value> ...") \
54 FLT_OT_PARSE_TRACER_DEF( LOG, 0, 1, 2, 0, "log", " { global | <addr> [len <len>] [format <fmt>] <facility> [<level> [<minlevel>]] }") \
55 FLT_OT_PARSE_TRACER_DEF( CONFIG, 0, 0, 2, 2, "config", " <file>") \
56 FLT_OT_PARSE_TRACER_DEF( PLUGIN, 0, 0, 2, 2, "plugin", " <file>") \
57 FLT_OT_PARSE_TRACER_DEF( GROUPS, 0, 0, 2, 0, "groups", " <name> ...") \
58 FLT_OT_PARSE_TRACER_DEF( SCOPES, 0, 0, 2, 0, "scopes", " <name> ...") \
59 FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, 0, 2, 2, "rate-limit", " <value>") \
60 FLT_OT_PARSE_TRACER_DEF( OPTION, 0, 0, 2, 2, "option", " { disabled | dontlog-normal | hard-errors }") \
61 FLT_OT_PARSE_TRACER_DEF(DEBUG_LEVEL, 0, 0, 2, 2, "debug-level", " <value>")
62
63#define FLT_OT_PARSE_GROUP_DEFINES \
64 FLT_OT_PARSE_GROUP_DEF( ID, 0, 1, 2, 2, "ot-group", " <name>") \
65 FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, 0, 2, 0, "scopes", " <name> ...")
66
67#define FLT_OT_PARSE_SCOPE_DEFINES \
68 FLT_OT_PARSE_SCOPE_DEF( ID, 0, 1, 2, 2, "ot-scope", " <name>") \
69 FLT_OT_PARSE_SCOPE_DEF( SPAN, 0, 0, 2, 5, "span", " <name> [<reference>] [root]") \
70 FLT_OT_PARSE_SCOPE_DEF( TAG, 1, 0, 3, 0, "tag", " <name> <sample> ...") \
71 FLT_OT_PARSE_SCOPE_DEF( LOG, 1, 0, 3, 0, "log", " <name> <sample> ...") \
72 FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, 4, 3, 0, "baggage", " <name> <sample> ...") \
73 FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, 3, 2, 4, "inject", " <name-prefix> [use-vars] [use-headers]") \
74 FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, 3, 2, 3, "extract", " <name-prefix> [use-vars | use-headers]") \
75 FLT_OT_PARSE_SCOPE_DEF( FINISH, 0, 0, 2, 0, "finish", " <name> ...") \
76 FLT_OT_PARSE_SCOPE_DEF( ACL, 0, 1, 3, 0, "acl", " <name> <criterion> [flags] [operator] <value> ...") \
77 FLT_OT_PARSE_SCOPE_DEF( EVENT, 0, 0, 2, 0, "event", " <name> [{ if | unless } <condition>]")
78
79enum FLT_OT_PARSE_TRACER_enum {
80#define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_TRACER_##a,
81 FLT_OT_PARSE_TRACER_DEFINES
82#undef FLT_OT_PARSE_TRACER_DEF
83};
84
85enum FLT_OT_PARSE_GROUP_enum {
86#define FLT_OT_PARSE_GROUP_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_GROUP_##a,
87 FLT_OT_PARSE_GROUP_DEFINES
88#undef FLT_OT_PARSE_GROUP_DEF
89};
90
91enum FLT_OT_PARSE_SCOPE_enum {
92#define FLT_OT_PARSE_SCOPE_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_SCOPE_##a,
93 FLT_OT_PARSE_SCOPE_DEFINES
94#undef FLT_OT_PARSE_SCOPE_DEF
95};
96
97enum FLT_OT_CTX_USE_enum {
98 FLT_OT_CTX_USE_VARS = 1 << 0,
99 FLT_OT_CTX_USE_HEADERS = 1 << 1,
100};
101
102struct flt_ot_parse_data {
103 int keyword; /* Keyword index. */
104 bool flag_check_id; /* Whether the group ID must be defined for the keyword. */
105 int check_name; /* Checking allowed characters in the name. */
106 int args_min; /* The minimum number of arguments required. */
107 int args_max; /* The maximum number of arguments allowed. */
108 const char *name; /* Keyword name. */
109 const char *usage; /* Usage text to be printed in case of an error. */
110};
111
112#define FLT_OT_PARSE_WARNING(f, ...) \
113 ha_warning("parsing [%s:%d] : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'" f "'\n", ##__VA_ARGS__);
114#define FLT_OT_PARSE_ALERT(f, ...) \
115 do { \
116 ha_alert("parsing [%s:%d] : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'" f "'\n", ##__VA_ARGS__); \
117 \
118 retval |= ERR_ABORT | ERR_ALERT; \
119 } while (0)
120#define FLT_OT_POST_PARSE_ALERT(f, ...) \
121 FLT_OT_PARSE_ALERT(f, flt_ot_current_config->cfg_file, ##__VA_ARGS__)
122
123#define FLT_OT_PARSE_ERR(e,f, ...) \
124 do { \
125 if (*(e) == NULL) \
126 (void)memprintf((e), f, ##__VA_ARGS__); \
127 \
128 retval |= ERR_ABORT | ERR_ALERT; \
129 } while (0)
130#define FLT_OT_PARSE_IFERR_ALERT() \
131 do { \
132 if (err == NULL) \
133 break; \
134 \
135 FLT_OT_PARSE_ALERT("%s", file, linenum, err); \
136 FLT_OT_ERR_FREE(err); \
137 } while (0)
138
139#endif /* _OPENTRACING_PARSER_H_ */
140
141/*
142 * Local variables:
143 * c-indent-level: 8
144 * c-basic-offset: 8
145 * End:
146 *
147 * vi: noexpandtab shiftwidth=8 tabstop=8
148 */