MEDIUM: trace: create a new "trace" statement in the "global" section

The exact same commands as those from the CLI may be pre-loaded at boot
time by passing them one per line after the "trace" keyword in the global
section; i.e. just copy-pasting all commands directly there will do the
job. Note that if a ring is mentioned, it needs to be declared before the
global section. Another option is to append another global section after
"ring".

For now the keyword is marked as experimental to discourage its broad
adoption by default. "expose-experimental-directives" needs to be placed
in the global section to expose it.
This commit is contained in:
Willy Tarreau 2022-11-16 17:29:12 +01:00
parent c11f1cdf4d
commit 9fd0542148
2 changed files with 49 additions and 0 deletions

View File

@ -2328,6 +2328,25 @@ thread-groups <number>
since up to 64 threads per group may be configured. The maximum number of
groups is configured at compile time and defaults to 16. See also "nbthread".
trace <args...>
This command configures one "trace" subsystem statement. Each of them can be
found in the management manual, and follow the exact same syntax. Only one
statement per line is permitted (i.e. if some long trace configurations using
semi-colons are to be imported, they must be placed one per line). Any output
that the "trace" command would produce will be emitted during the parsing
step of the section. Most of the time these will be errors and warnings, but
certain incomplete commands might list permissible choices. This command is
not meant for regular use, it will generally only be suggested by developers
along complex debugging sessions. For this reason it is internally marked as
experimental, meaning that "expose-experimental-directives" must appear on a
line before any "trace" statement. Note that these directives are parsed on
the fly, so referencing a ring buffer that is only declared further will not
work. For such use cases it is suggested to place another "global" section
with only the "trace" statements after the declaration of that ring. It is
important to keep in mind that depending on the trace level and details,
enabling traces can severely degrade the global performance. Please refer to
the management manual for the statements syntax.
uid <number>
Changes the process's user ID to <number>. It is recommended that the user ID
is dedicated to HAProxy or to a small set of similar daemons. HAProxy must

View File

@ -21,6 +21,7 @@
#include <import/ist.h>
#include <haproxy/api.h>
#include <haproxy/buf.h>
#include <haproxy/cfgparse.h>
#include <haproxy/cli.h>
#include <haproxy/errors.h>
#include <haproxy/istbuf.h>
@ -675,6 +676,28 @@ static int trace_parse_statement(char **args, const char **msg)
}
/* parse a "trace" statement in the "global" section, returns 1 if a message is returned, otherwise zero */
static int cfg_parse_trace(char **args, int section_type, struct proxy *curpx,
const struct proxy *defpx, const char *file, int line,
char **err)
{
const char *msg;
int severity;
severity = trace_parse_statement(args, &msg);
if (msg) {
if (severity >= LOG_NOTICE)
ha_notice("parsing [%s:%d] : '%s': %s\n", file, line, args[0], msg);
else if (severity >= LOG_WARNING)
ha_warning("parsing [%s:%d] : '%s': %s\n", file, line, args[0], msg);
else {
ha_alert("parsing [%s:%d] : '%s': %s\n", file, line, args[0], msg);
return -1;
}
}
return 0;
}
/* parse the command, returns 1 if a message is returned, otherwise zero */
static int cli_parse_trace(char **args, char *payload, struct appctx *appctx, void *private)
{
@ -754,6 +777,13 @@ static struct cli_kw_list cli_kws = {{ },{
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
static struct cfg_kw_list cfg_kws = {ILH, {
{ CFG_GLOBAL, "trace", cfg_parse_trace, KWF_EXPERIMENTAL },
{ /* END */ },
}};
INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
/*
* Local variables:
* c-indent-level: 8