Skip to content

Commit 34608c7

Browse files
author
Tatiana Azundris Nuernberg
committed
Merge branch 'mysql-8.0-wl11150' into mysql-trunk-wl11150
2 parents 26ca2cf + f9d1c83 commit 34608c7

File tree

138 files changed

+942
-843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+942
-843
lines changed

components/logging/log_sink_test.cc

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ You should have received a copy of the GNU General Public License
2020
along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2222

23+
#define MY_NAME "log_sink_test"
24+
#define LOG_COMPONENT_TAG MY_NAME
25+
// Test override. No non-test components should use a non-approved value here!
26+
#define LOG_SUBSYSTEM_TAG MY_NAME
27+
2328
#include "log_service_imp.h"
2429

2530
#include <assert.h>
@@ -29,8 +34,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2934
#include <mysql/components/services/log_builtins.h>
3035
#include <mysql/components/services/log_builtins_filter.h>
3136

32-
#define MY_NAME "log_sink_test"
33-
3437
extern REQUIRES_SERVICE_PLACEHOLDER(registry);
3538

3639
REQUIRES_SERVICE_PLACEHOLDER(log_builtins);
@@ -155,6 +158,8 @@ static void test_add_item_log_me(log_filter_ruleset *rs, const char *label,
155158
.string_value(KEY_PRS_ITEM, "test_me_for_presence")
156159
.string_value(KEY_DEL_ITEM, "delete_me_by_rule")
157160
.string_value(KEY_PRIO_CHANGE, VAL_PRIO_CHANGE)
161+
.subsys(LOG_SUBSYSTEM_TAG)
162+
.component(LOG_COMPONENT_TAG)
158163
.source_file(MY_NAME)
159164
.message("filter_rules: (add_item %s) %d", label, rs->count - orig_count);
160165
}
@@ -176,6 +181,8 @@ static int test_if_then_else() {
176181
.int_value("wl9651_val3a", 1)
177182
.int_value("wl9651_val3b", 2)
178183
.int_value("wl9651_val3c", 3)
184+
.subsys(LOG_SUBSYSTEM_TAG)
185+
.component(LOG_COMPONENT_TAG)
179186
.message("WL#9651 expected: r1-IF, r2-SUCCESS, r3-SUCCESS");
180187
LogEvent()
181188
.type(LOG_TYPE_ERROR)
@@ -186,6 +193,8 @@ static int test_if_then_else() {
186193
.int_value("wl9651_val3a", 0)
187194
.int_value("wl9651_val3b", 2)
188195
.int_value("wl9651_val3c", 3)
196+
.subsys(LOG_SUBSYSTEM_TAG)
197+
.component(LOG_COMPONENT_TAG)
189198
.message("WL#9651 expected: r1-ELSEIF1, r2-SUCCESS, r3-FAILURE");
190199
LogEvent()
191200
.type(LOG_TYPE_ERROR)
@@ -196,6 +205,8 @@ static int test_if_then_else() {
196205
.int_value("wl9651_val3a", 1)
197206
.int_value("wl9651_val3b", 0)
198207
.int_value("wl9651_val3c", 3)
208+
.subsys(LOG_SUBSYSTEM_TAG)
209+
.component(LOG_COMPONENT_TAG)
199210
.message("WL#9651 expected: r1-ELSEIF2, r2-FAILURE, r3-FAILURE");
200211
LogEvent()
201212
.type(LOG_TYPE_ERROR)
@@ -206,6 +217,8 @@ static int test_if_then_else() {
206217
.int_value("wl9651_val3a", 1)
207218
.int_value("wl9651_val3b", 2)
208219
.int_value("wl9651_val3c", 0)
220+
.subsys(LOG_SUBSYSTEM_TAG)
221+
.component(LOG_COMPONENT_TAG)
209222
.message("WL#9651 expected: r1-ELSE, r2-FAILURE, r3-FAILURE");
210223
LogEvent()
211224
.type(LOG_TYPE_ERROR)
@@ -215,6 +228,8 @@ static int test_if_then_else() {
215228
.string_value("wl9651_val2", "1")
216229
.int_value("wl9651_val3a", 1)
217230
.int_value("wl9651_val3c", 3)
231+
.subsys(LOG_SUBSYSTEM_TAG)
232+
.component(LOG_COMPONENT_TAG)
218233
.message("WL#9651 expected: r1-IF, r2-FAILURE, r3-FAILURE");
219234
return 0;
220235
}
@@ -468,34 +483,44 @@ static int test_throttle(log_filter_ruleset *rs) {
468483
.prio(INFORMATION_LEVEL)
469484
.errcode(ER_PARSER_TRACE)
470485
.source_line(__LINE__)
486+
.subsys(LOG_SUBSYSTEM_TAG)
487+
.component(LOG_COMPONENT_TAG)
471488
.source_file(MY_NAME)
472489
.message(
473490
"below: 3*unknown error per writer == correct. "
474491
">3*unknown error per writer == filter fail. "
475492
"0*unknown error == " MY_NAME " fail.");
476493

477494
if ((log_bf->filter_ruleset_lock(rs, LOG_BUILTINS_LOCK_EXCLUSIVE)) < 0) {
495+
/* purecov: begin inspected */
478496
LogEvent()
479497
.type(LOG_TYPE_ERROR)
480498
.prio(ERROR_LEVEL)
481499
.errcode(ER_PARSER_TRACE)
500+
.subsys(LOG_SUBSYSTEM_TAG)
501+
.component(LOG_COMPONENT_TAG)
482502
.message(MY_NAME
483503
": could not get a lock on built-in filter's "
484504
"ruleset (for add)");
485505
return -1;
506+
/* purecov: end */
486507
}
487508

488509
orig_count = rs->count;
489510

490511
if ((r = (log_filter_rule *)log_bf->filter_rule_init(rs)) == nullptr) {
512+
/* purecov: begin inspected */
491513
LogEvent()
492514
.type(LOG_TYPE_ERROR)
493515
.prio(ERROR_LEVEL)
494516
.errcode(ER_PARSER_TRACE)
517+
.subsys(LOG_SUBSYSTEM_TAG)
518+
.component(LOG_COMPONENT_TAG)
495519
.message(MY_NAME
496520
": could not init a rule in built-in filter's ruleset");
497521
rr = -2;
498522
goto done;
523+
/* purecov: end */
499524
}
500525

501526
// set up a demo rate-limiter
@@ -523,6 +548,8 @@ static int test_throttle(log_filter_ruleset *rs) {
523548
.type(LOG_TYPE_ERROR)
524549
.prio(INFORMATION_LEVEL)
525550
.errcode(ER_PARSER_TRACE)
551+
.subsys(LOG_SUBSYSTEM_TAG)
552+
.component(LOG_COMPONENT_TAG)
526553
.source_line(__LINE__)
527554
.source_file(MY_NAME)
528555
.message("filter_rules: (throttle: delta in medias res) %d",
@@ -535,20 +562,26 @@ static int test_throttle(log_filter_ruleset *rs) {
535562
LogEvent()
536563
.type(LOG_TYPE_ERROR)
537564
.prio(INFORMATION_LEVEL)
565+
.subsys(LOG_SUBSYSTEM_TAG)
566+
.component(LOG_COMPONENT_TAG)
538567
.source_line(__LINE__)
539568
.source_file(MY_NAME)
540569
.lookup(ER_UNKNOWN_ERROR_NUMBER, 1);
541570
}
542571

543572
if ((log_bf->filter_ruleset_lock(rs, LOG_BUILTINS_LOCK_EXCLUSIVE)) < 0) {
573+
/* purecov: begin inspected */
544574
LogEvent()
545575
.type(LOG_TYPE_ERROR)
546576
.prio(ERROR_LEVEL)
547577
.errcode(ER_PARSER_TRACE)
578+
.subsys(LOG_SUBSYSTEM_TAG)
579+
.component(LOG_COMPONENT_TAG)
548580
.message(MY_NAME
549581
": could not get a lock on built-in filter's "
550582
"ruleset (for delete)");
551583
return -3;
584+
/* purecov: end */
552585
}
553586

554587
rule_delete(rs, LOG_ITEM_SQL_ERRCODE, nullptr, LOG_FILTER_COND_EQ,
@@ -563,6 +596,8 @@ static int test_throttle(log_filter_ruleset *rs) {
563596
.type(LOG_TYPE_ERROR)
564597
.prio(INFORMATION_LEVEL)
565598
.errcode(ER_PARSER_TRACE)
599+
.subsys(LOG_SUBSYSTEM_TAG)
600+
.component(LOG_COMPONENT_TAG)
566601
.source_line(__LINE__)
567602
.source_file(MY_NAME)
568603
.message("filter_rules: (throttle: delta ex post) %d",
@@ -623,6 +658,8 @@ static void banner() {
623658
.type(LOG_TYPE_ERROR)
624659
.prio(INFORMATION_LEVEL)
625660
.errcode(ER_PARSER_TRACE)
661+
.subsys(LOG_SUBSYSTEM_TAG)
662+
.component(LOG_COMPONENT_TAG)
626663
.source_line(__LINE__)
627664
.source_file(MY_NAME)
628665
.float_value("test_float", 3.1415926927)
@@ -659,6 +696,8 @@ static void banner() {
659696
.type(LOG_TYPE_ERROR)
660697
.prio(INFORMATION_LEVEL)
661698
.errcode(ER_PARSER_TRACE)
699+
.subsys(LOG_SUBSYSTEM_TAG)
700+
.component(LOG_COMPONENT_TAG)
662701
.message("item_inconsistent(#%d): %s", 1,
663702
consistent[-log_bi->item_inconsistent(li)]);
664703

@@ -669,6 +708,8 @@ static void banner() {
669708
.type(LOG_TYPE_ERROR)
670709
.prio(INFORMATION_LEVEL)
671710
.errcode(ER_PARSER_TRACE)
711+
.subsys(LOG_SUBSYSTEM_TAG)
712+
.component(LOG_COMPONENT_TAG)
672713
.message("item_inconsistent(#%d): %s", 2,
673714
consistent[-log_bi->item_inconsistent(li)]);
674715

@@ -680,6 +721,8 @@ static void banner() {
680721
.type(LOG_TYPE_ERROR)
681722
.prio(INFORMATION_LEVEL)
682723
.errcode(ER_PARSER_TRACE)
724+
.subsys(LOG_SUBSYSTEM_TAG)
725+
.component(LOG_COMPONENT_TAG)
683726
.message("item_inconsistent(#%d): %s", 2,
684727
consistent[-log_bi->item_inconsistent(li)]);
685728

@@ -691,6 +734,8 @@ static void banner() {
691734
.type(LOG_TYPE_ERROR)
692735
.prio(INFORMATION_LEVEL)
693736
.errcode(ER_PARSER_TRACE)
737+
.subsys(LOG_SUBSYSTEM_TAG)
738+
.component(LOG_COMPONENT_TAG)
694739
.message("item_inconsistent(#%d): %s", 3,
695740
consistent[-log_bi->item_inconsistent(li)]);
696741

@@ -704,6 +749,8 @@ static void banner() {
704749
.type(LOG_TYPE_ERROR)
705750
.prio(INFORMATION_LEVEL)
706751
.errcode(ER_PARSER_TRACE)
752+
.subsys(LOG_SUBSYSTEM_TAG)
753+
.component(LOG_COMPONENT_TAG)
707754
.message("item_inconsistent(#%d): %s", 4,
708755
consistent[-log_bi->item_inconsistent(li)]);
709756

@@ -718,6 +765,8 @@ static void banner() {
718765
.type(LOG_TYPE_ERROR)
719766
.prio(INFORMATION_LEVEL)
720767
.errcode(ER_PARSER_TRACE)
768+
.subsys(LOG_SUBSYSTEM_TAG)
769+
.component(LOG_COMPONENT_TAG)
721770
.message("item_inconsistent(#%d): %s", 5,
722771
consistent[-log_bi->item_inconsistent(li)]);
723772
}

components/mysql_server/log_builtins.cc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2727
someone's going out of their way to break to API)". :)
2828
*/
2929

30+
#define LOG_SUBSYSTEM_TAG "Server"
31+
3032
#include "log_builtins_filter_imp.h"
3133
#include "log_builtins_imp.h" // internal structs
3234
// connection_events_loop_aborted()
@@ -1079,12 +1081,13 @@ const char *log_label_from_prio(int prio) {
10791081
static int log_sink_trad(void *instance MY_ATTRIBUTE((unused)), log_line *ll) {
10801082
const char *label = "", *msg = "";
10811083
int c, out_fields = 0;
1082-
size_t msg_len = 0, ts_len = 0, label_len = 0;
1084+
size_t msg_len = 0, ts_len = 0, label_len = 0, subsys_len = 0;
10831085
enum loglevel prio = ERROR_LEVEL;
10841086
unsigned int errcode = 0;
10851087
log_item_type item_type = LOG_ITEM_END;
10861088
log_item_type_mask out_types = 0;
1087-
const char *iso_timestamp = "";
1089+
const char *iso_timestamp = "", *subsys = "";
1090+
;
10881091
my_thread_id thread_id = 0;
10891092

10901093
if (ll->count > 0) {
@@ -1110,6 +1113,11 @@ static int log_sink_trad(void *instance MY_ATTRIBUTE((unused)), log_line *ll) {
11101113
label = ll->item[c].data.data_string.str;
11111114
label_len = ll->item[c].data.data_string.length;
11121115
break;
1116+
case LOG_ITEM_SRV_SUBSYS:
1117+
subsys = ll->item[c].data.data_string.str;
1118+
if ((subsys_len = ll->item[c].data.data_string.length) > 12)
1119+
subsys_len = 12;
1120+
break;
11131121
case LOG_ITEM_LOG_TIMESTAMP:
11141122
iso_timestamp = ll->item[c].data.data_string.str;
11151123
ts_len = ll->item[c].data.data_string.length;
@@ -1161,20 +1169,19 @@ static int log_sink_trad(void *instance MY_ATTRIBUTE((unused)), log_line *ll) {
11611169
message; this should therefore not affect log aggregation.
11621170
Tools reacting to the contents of the message may wish to
11631171
use the new field instead as it's simpler to parse.
1164-
While for the time being, this field contains a numerical
1165-
value, the rules are like so:
1172+
The rules are like so:
11661173
11671174
'[' [ <namespace> ':' ] <identifier> ']'
11681175
11691176
That is, an error identifier may be namespaced by a
11701177
subsystem/component name and a ':'; the identifier
11711178
itself should be considered opaque; in particular, it
1172-
may be non-numerical: [ <alpha> | <digit> | '_' | '.' ]
1179+
may be non-numerical: [ <alpha> | <digit> | '_' | '.' | '-' ]
11731180
*/
11741181
len = snprintf(buff_line, sizeof(buff_line),
1175-
"%.*s %u [%.*s] [MY-%06u] %.*s", (int)ts_len,
1182+
"%.*s %u [%.*s] [MY-%06u] [%.*s] %.*s", (int)ts_len,
11761183
iso_timestamp, thread_id, (int)label_len, label, errcode,
1177-
(int)msg_len, msg);
1184+
(int)subsys_len, subsys, (int)msg_len, msg);
11781185

11791186
log_write_errstream(buff_line, len);
11801187

@@ -1471,6 +1478,13 @@ int log_line_submit(log_line *ll) {
14711478
}
14721479
}
14731480

1481+
/* add the default sub-system if none is set */
1482+
if (!(ll->seen & LOG_ITEM_SRV_SUBSYS) && !log_line_full(ll)) {
1483+
log_item_data *d = log_line_item_set(ll, LOG_ITEM_SRV_SUBSYS);
1484+
d->data_string.str = LOG_SUBSYSTEM_TAG;
1485+
d->data_string.length = strlen(d->data_string.str);
1486+
}
1487+
14741488
/* normalize source line if needed */
14751489
DBUG_EXECUTE_IF("log_error_normalize", {
14761490
if (ll->seen & LOG_ITEM_SRC_LINE) {

0 commit comments

Comments
 (0)