MySQL 9.1.0
Source Code Documentation
|
#include "log_service_imp.h"
#include <mysqld_error.h>
#include "../sql/sql_error.h"
#include <mysql/components/component_implementation.h>
#include <mysql/components/service_implementation.h>
#include <mysql/components/services/component_status_var_service.h>
#include <mysql/components/services/component_sys_var_service.h>
#include <mysql/components/services/mysql_system_variable.h>
#include "../sql/set_var.h"
#include <mysql/components/services/log_builtins.h>
#include <mysql/components/services/log_builtins_filter.h>
#include <string_with_len.h>
Classes | |
struct | log_filter_xlate_key |
Element in an array of known tokens in the filter configuration language. More... | |
Macros | |
#define | LOG_FILTER_DUMP_BUFF_SIZE 8192 |
There is a new filter engine in the server proper (components/mysql_server/log_builtins_filter.cc). More... | |
#define | LOG_FILTER_LANGUAGE_NAME "dragnet" |
#define | LOG_FILTER_SYSVAR_NAME "log_error_filter_rules" |
#define | LOG_FILTER_STATUS_NAME "Status" |
#define | LOG_FILTER_DEFAULT_RULES |
Typedefs | |
typedef enum enum_log_filter_xlate_flags | log_filter_xlate_flags |
Flags to use in log_filter_xlate_by_name() / log_filter_xlate_by_opcode() when looking up a token by its opcode, or vice versa. More... | |
typedef enum enum_log_filter_token_flags | log_filter_token_flags |
What kind of token should log_filter_get_token() look for? More... | |
typedef enum enum_log_filter_syntax | log_filter_syntax |
A few keywords that we look for while parsing, but that do not necessarily generate an opcode in the rule-set. More... | |
typedef enum enum_log_filter_result | log_filter_result |
result codes used in dumping/decompiling rules More... | |
typedef enum enum_set_arg_result | set_arg_result |
result codes of log_filter_set_arg() More... | |
Functions | |
REQUIRES_SERVICE_PLACEHOLDER (component_sys_variable_register) | |
REQUIRES_SERVICE_PLACEHOLDER (component_sys_variable_unregister) | |
REQUIRES_SERVICE_PLACEHOLDER (mysql_system_variable_reader) | |
REQUIRES_SERVICE_PLACEHOLDER (status_variable_registration) | |
STR_CHECK_ARG (rules) values_filter_rules | |
limits and default for sysvar More... | |
REQUIRES_SERVICE_PLACEHOLDER (log_builtins) | |
REQUIRES_SERVICE_PLACEHOLDER (log_builtins_string) | |
REQUIRES_SERVICE_PLACEHOLDER (log_builtins_filter) | |
REQUIRES_SERVICE_PLACEHOLDER (log_builtins_tmp) | |
static int | log_filter_xlate_by_name (const char *token, size_t len, uint flags) |
Find a given token in log_filter_xlate_keys[], the table of known tokens. More... | |
static int | log_filter_xlate_by_opcode (uint opcode, uint flags) |
Find a given opcode in log_filter_xlate_keys[], the table of known tokens. More... | |
static void | log_filter_append (char *out_buf, size_t out_siz, const char *str) |
Helper for dumping filter rules. More... | |
static void | log_filter_append_item_value (char *out_buf, size_t out_siz, log_item *li) |
Helper for dumping filter rules. More... | |
static log_filter_result | log_filter_rule_dump (log_filter_rule *rule, log_filter_result state, char *out_buf, size_t out_size) |
Decompile an individual rule. More... | |
log_filter_result | log_filter_ruleset_dump (log_filter_ruleset *ruleset, char *ruleset_buf, size_t siz) |
Dump an entire filter rule-set. More... | |
static void | log_filter_skip_white (const char **inp_readpos) |
Skip whitespace. More... | |
static int | log_filter_get_token (const char **inp_readpos, const char **token, size_t *len, uint types) |
Gets a token from a filter configuration. More... | |
static int | log_filter_make_field (const char **name, const size_t *len, log_item *li) |
Set up a log-item from filtering rules. More... | |
static bool | log_filter_generic_type (log_item_type type) |
Helper: Does a field require a certain data class, or can it morph into whatever value we wish to assign to it? The former is the case if the field either has a generic (rather than well-known) type, or if it has no type at all (this is the case if a rule has an unnamed aux item). More... | |
static set_arg_result | log_filter_set_arg (const char **token, const size_t *len, log_item *li, const char **state) |
Set argument (i.e., the value) on a list-item. More... | |
static int | log_filter_dragnet_set (log_filter_ruleset *ruleset, const char *rules, const char **state) |
Set filtering rules from human-readable configuration string. More... | |
static int | check_var_filter_rules (MYSQL_THD thd, SYS_VAR *self, void *save, struct st_mysql_value *value) |
Check the proposed value for the component variable which contains the filter rules in human-readable format. More... | |
static void | update_var_filter_rules (MYSQL_THD thd, SYS_VAR *self, void *var_ptr, const void *save) |
Update value of component variable. More... | |
mysql_service_status_t | log_filter_exit () |
De-initialization method for Component used when unloading the Component. More... | |
mysql_service_status_t | log_filter_init () |
Initialization entry method for Component used when loading the Component. More... | |
PROVIDES_SERVICE (log_filter_dragnet, log_service) | |
END_COMPONENT_PROVIDES () | |
REQUIRES_SERVICE (component_sys_variable_register) | |
REQUIRES_SERVICE (component_sys_variable_unregister) | |
REQUIRES_SERVICE (mysql_system_variable_reader) | |
REQUIRES_SERVICE (status_variable_registration) | |
REQUIRES_SERVICE (log_builtins) | |
REQUIRES_SERVICE (log_builtins_string) | |
REQUIRES_SERVICE (log_builtins_filter) | |
REQUIRES_SERVICE (log_builtins_tmp) | |
END_COMPONENT_REQUIRES () | |
METADATA ("mysql.author", "Oracle Corporation") | |
METADATA ("mysql.license", "GPL") | |
METADATA ("log_service_type", "filter") | |
END_COMPONENT_METADATA () | |
Variables | |
static char * | log_error_filter_rules = nullptr |
sysvar containing rules More... | |
static char | log_error_filter_decompile [LOG_FILTER_DUMP_BUFF_SIZE] = "" |
static SHOW_VAR | show_var_filter_rules_decompile [] |
static bool | inited = false |
static int | opened = 0 |
const mysql_service_log_builtins_t * | log_bi = nullptr |
accessor built-ins More... | |
const mysql_service_log_builtins_string_t * | log_bs = nullptr |
string built-ins More... | |
const mysql_service_log_builtins_filter_t * | log_bf = nullptr |
filter built-ins More... | |
const mysql_service_log_builtins_tmp_t * | log_bt = nullptr |
notify built-in More... | |
log_filter_tag | rule_tag_dragnet |
log_filter_ruleset * | log_filter_dragnet_rules = nullptr |
static const log_filter_xlate_key | log_filter_xlate_keys [] |
Array of known tokens in the filter configuration language. More... | |
const mysql_service_log_service_t | imp_log_filter_dragnet_log_service |
mysql_component_t | mysql_component_log_filter_dragnet |
#define LOG_FILTER_DEFAULT_RULES |
#define LOG_FILTER_DUMP_BUFF_SIZE 8192 |
There is a new filter engine in the server proper (components/mysql_server/log_builtins_filter.cc).
It can apply highly versatile filtering rules to log events. By default however, it loads a rule-set that emulates mysqld 5.7 behavior, so as far as the users are concerned, the configuration variables (–log_error_verbosity ...) and the behavior haven't changed (much).
The loadable service implemented in this file is noteworthy in that it does not implement a complete filtering service; instead, it implements a configuration language for the internal filter that gives users access to all its features (rather than just to the small 5.7 compatibility subset).
Therefore, this file contains the parsing of the new configuration language (the "configuration engine"), whereas log_builtins_filter.cc contains the filtering engine.
CONFIGURATION PARSING STAGE
As a courtesy, during parsing (e.g. "IF prio>=3 THEN drop."), the filter configuration engine checks whether it knows the field ("prio"), and if so, whether the storage class it expects for the field (integer) matches that of the argument (3). In our example, it does; if it didn't, the configuration engine would throw an error.
The same applies if a well-known field appears in the action (e.g. the action 'set log_label:="HELO".' in the rule 'IF err_code==1408 THEN set label:="HELO".') label is a well-known field here, its well-known storage class is string, and since "HELO" is a string, all's well. (Otherwise, again, we'd throw an error.)
#define LOG_FILTER_LANGUAGE_NAME "dragnet" |
#define LOG_FILTER_STATUS_NAME "Status" |
#define LOG_FILTER_SYSVAR_NAME "log_error_filter_rules" |
typedef enum enum_log_filter_result log_filter_result |
result codes used in dumping/decompiling rules
typedef enum enum_log_filter_syntax log_filter_syntax |
A few keywords that we look for while parsing, but that do not necessarily generate an opcode in the rule-set.
typedef enum enum_log_filter_token_flags log_filter_token_flags |
What kind of token should log_filter_get_token() look for?
typedef enum enum_log_filter_xlate_flags log_filter_xlate_flags |
Flags to use in log_filter_xlate_by_name() / log_filter_xlate_by_opcode() when looking up a token by its opcode, or vice versa.
typedef enum enum_set_arg_result set_arg_result |
result codes of log_filter_set_arg()
result codes used in dumping/decompiling rules
What kind of token should log_filter_get_token() look for?
Flags to use in log_filter_xlate_by_name() / log_filter_xlate_by_opcode() when looking up a token by its opcode, or vice versa.
enum enum_set_arg_result |
result codes of log_filter_set_arg()
|
static |
Check the proposed value for the component variable which contains the filter rules in human-readable format.
thd | session |
self | the system variable we're checking |
save | where to save the resulting intermediate (char *) value |
value | the value we're validating |
false | value OK, go ahead and update system variable (from "save") |
true | value rejected, do not update variable |
< result code from dump
END_COMPONENT_METADATA | ( | ) |
END_COMPONENT_PROVIDES | ( | ) |
END_COMPONENT_REQUIRES | ( | ) |
|
static |
Helper for dumping filter rules.
Append a string literal to a buffer. Used by log_filter_rule_dump().
out_buf | NTBS buffer to append to. must contain at least '\0' |
out_siz | size of that buffer |
str | NTBS to append to that buffer |
|
static |
Helper for dumping filter rules.
Append an item's data/value to a buffer. Used by log_filter_rule_dump().
out_buf | NTBS buffer to append to. must contain at least '\0' |
out_siz | size of that buffer |
li | log-item whose value to append to that buffer |
|
static |
Set filtering rules from human-readable configuration string.
ruleset | ruleset to update | |
rules | a NTBS containing zero, one, or many rules | |
[out] | state | a pointer to additional info about the state. (this is free-text intended for error messages.) |
0 | no problems |
-1 | could not acquire ruleset |
-2 | out of memory |
-3 | invalid arguments |
>0 | parse problem at this index in rule string |
< current rule
< previous rule, if any
< read position in submitted rules
< retry from here on misparse
< current token in input
< token's length
< counter
< return code for caller
< previous flow control command
< current flow control command
< rule that had the opening IF
< number of conditions in branch
< the rule-set we're creating
< implicit item for "unset"
< have half-finished rule?
mysql_service_status_t log_filter_exit | ( | ) |
De-initialization method for Component used when unloading the Component.
false | success |
true | failure |
|
inlinestatic |
Helper: Does a field require a certain data class, or can it morph into whatever value we wish to assign to it? The former is the case if the field either has a generic (rather than well-known) type, or if it has no type at all (this is the case if a rule has an unnamed aux item).
type | the type to examine |
true | if field is of generic type or no type |
false | otherwise |
|
static |
Gets a token from a filter configuration.
[in,out] | inp_readpos | parse position pointer, in: current token, out: next token (on success), current token (on failure) |
[out] | token | pointer to start of (if arg-type, possible quoted) token |
[out] | len | length of (if arg-type, possibly quoted) token (0 on fail) |
types | what kind of token (and in what context) do we want? |
0 | OK |
-1 | incorrect quotation |
-2 | unknown values for 'types' |
mysql_service_status_t log_filter_init | ( | ) |
Initialization entry method for Component used when loading the Component.
false | success |
true | failure |
|
static |
Set up a log-item from filtering rules.
name | pointer to field name (ad hoc or well-known) |
len | length of field name |
li | log item to set up |
0 | OK |
-1 | invalid log-item type (reserved name) |
-2 | copy failed (out of memory?) |
|
static |
Decompile an individual rule.
At this point, we only ever decompile rules we've previously compiled ourselves, so short of memory corruption or running out of space, this should not fail. We check for failure all the same so all this will remain safe if we ever allow decompiles of other components' rule-sets.
rule | rule to decompile |
state | resulting state of previous rule's decompile, if any (so we can identify chained rules etc.) |
out_buf | buffer to hold the decompiled rule |
out_size | size of that buffer |
LOG_FILTER_LANGUAGE_OK | decompile succeeded |
LOG_FILTER_LANGUAGE_DK_COND | rule corrupted; condition unknown |
LOG_FILTER_LANGUAGE_DK_VERB | rule corrupted; action-verb unknown |
LOG_FILTER_LANGUAGE_CHAIN | chain rules (AND/OR) |
log_filter_result log_filter_ruleset_dump | ( | log_filter_ruleset * | ruleset, |
char * | ruleset_buf, | ||
size_t | siz | ||
) |
Dump an entire filter rule-set.
ruleset | rule-set to decompile |
ruleset_buf | buffer to write the decompiled ruleset to |
siz | size of that buffer in bytes |
LOG_FILTER_LANGUAGE_OK | decompiling succeeded |
LOG_FILTER_LANGUAGE_GET_FAILED | couldn't get rules |
LOG_FILTER_LANGUAGE_OOM | supplied buffer too small |
< return this result
< index of current rule
< rule to decompile
< current decompiled rule
< write pointer
< bytes left (out buffer)
< bytes used in a buffer
|
static |
Set argument (i.e., the value) on a list-item.
If the item is of any generic type, we'll set the value, and adjust the type to be of an appropriate ad hoc type. If the item is of a well-known type, we'll set the value on it if it's of an appropriate type, but will fail otherwise. For this, an integer constitutes a valid float, but not vice versa. (A string containing nothing but a number is still not a number.)
token | pointer to the beginning of the value-token | |
len | length of the argument/token | |
li | log-item to set the value on | |
[out] | state | a pointer to additional info about the state. (this is free-text intended for error messages.) |
|
inlinestatic |
Skip whitespace.
Helper for parsing. Advances a read-pointer to the next non-space character.
[in,out] | inp_readpos | Pointer to a NTBS. |
|
static |
Find a given token in log_filter_xlate_keys[], the table of known tokens.
A token in the array will only be considered a valid match if it features at least one flag requested by the caller (i.e. if it is of the requested class – comparator, action-verb, etc.). Used by log_filter_dragnet_set() to convert tokens into opcodes.
token | token to look up |
len | length of token in bytes |
flags | combination of log_filter_xlate_flags |
|
static |
Find a given opcode in log_filter_xlate_keys[], the table of known tokens.
An opcode in the array will only be considered a valid match if it features at least one flag requested by the caller (i.e. if it is of the requested class – comparator, action-verb, etc.). Used by log_filter_rule_dump() to convert opcodes into printable tokens.
opcode | opcode to look up |
flags | combination of log_filter_xlate_flags |
METADATA | ( | "log_service_type" | , |
"filter" | |||
) |
METADATA | ( | "mysql.author" | , |
"Oracle Corporation" | |||
) |
METADATA | ( | "mysql.license" | , |
"GPL" | |||
) |
PROVIDES_SERVICE | ( | log_filter_dragnet | , |
log_service | |||
) |
REQUIRES_SERVICE | ( | component_sys_variable_register | ) |
REQUIRES_SERVICE | ( | component_sys_variable_unregister | ) |
REQUIRES_SERVICE | ( | log_builtins | ) |
REQUIRES_SERVICE | ( | log_builtins_filter | ) |
REQUIRES_SERVICE | ( | log_builtins_string | ) |
REQUIRES_SERVICE | ( | log_builtins_tmp | ) |
REQUIRES_SERVICE | ( | mysql_system_variable_reader | ) |
REQUIRES_SERVICE | ( | status_variable_registration | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | component_sys_variable_register | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | component_sys_variable_unregister | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | log_builtins | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | log_builtins_filter | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | log_builtins_string | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | log_builtins_tmp | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | mysql_system_variable_reader | ) |
REQUIRES_SERVICE_PLACEHOLDER | ( | status_variable_registration | ) |
STR_CHECK_ARG | ( | rules | ) |
limits and default for sysvar
|
static |
Update value of component variable.
thd | session |
self | the system variable we're changing |
var_ptr | where to save the resulting (char *) value |
save | pointer to the new value (from check function) |
const mysql_service_log_service_t imp_log_filter_dragnet_log_service |
|
static |
const mysql_service_log_builtins_filter_t* log_bf = nullptr |
filter built-ins
const mysql_service_log_builtins_t* log_bi = nullptr |
accessor built-ins
const mysql_service_log_builtins_string_t* log_bs = nullptr |
string built-ins
const mysql_service_log_builtins_tmp_t* log_bt = nullptr |
notify built-in
|
static |
|
static |
sysvar containing rules
log_filter_ruleset* log_filter_dragnet_rules = nullptr |
|
static |
Array of known tokens in the filter configuration language.
mysql_component_t mysql_component_log_filter_dragnet |
|
static |
log_filter_tag rule_tag_dragnet |
|
static |