Debian Codegraph @

mysql-test/suite/perfschema/t/error_log.test

raw
1 --echo # WL#13681: Make error-log available for queries from a connection
2 --echo
3
4 --source include/not_parallel.inc
5
6 let $LOG_VERBOSE= `select @@global.log_error_verbosity`;
7 SET @@global.log_error_verbosity=3;
8
9 # This test does not rely on debug features. If you need to add a case that
10 # does, start a new file, or add it to error_log_debug.test instead.
11
12 --echo
13 --echo # FR-1.1 Table name
14 --echo # FR-1.2 Columns and names
15 DESC performance_schema.error_log;
16
17
18 --echo #
19 --echo # PART I - Traditional error log
20 --echo #
21 --echo
22
23 # Make timestamps in file and table agree in case we need to correlate them.
24 SET @@session.time_zone=@@global.log_timestamps;
25
26 --echo
27 --echo # We have 4 new status variables to monitor the ring-buffer:
28 # We only show the presence of the variables, not their values.
29 SELECT VARIABLE_NAME
30 FROM performance_schema.global_status
31 WHERE VARIABLE_NAME LIKE "Error_log_%";
32
33 --echo
34 --echo # Show that we're logging to stderr:
35 SELECT @@global.log_error;
36
37 --echo
38 --echo # Determine start-up time. Must succeed for other results to have meaning.
39 # If this test is run with --repeat=..., any number of entries could
40 # be present in the log. We therefore use the latest ER_STARTING_AS
41 # (which is issued very early in the start-up, and of SYSTEM priority)
42 # as an approximate marker for when the current run was started, and
43 # fetch the timestamp for it. We can then use that as a starting point
44 # (logged>=@startup) in subsequent queries.
45 # This is also a good first test to show that
46 # - We have something in the ring-buffer
47 # - It looks like sensible log-events
48 # - We can SELECT things in the ring-buffer
49 # If this fails, something went very wrong, and all results below are
50 # of questionable worth.
51 SELECT logged INTO @startup
52 FROM performance_schema.error_log
53 WHERE error_code="MY-010116" ORDER BY logged DESC LIMIT 1;
54
55 --echo
56 --echo # Since we're logging to stderr, we should see this message exactly once
57 --echo # (from our current start-up). Otherwise, we might see more of them from
58 --echo # previous runs:
59 SELECT COUNT(logged)
60 FROM performance_schema.error_log
61 WHERE error_code="MY-010116" ORDER BY logged;
62
63 --echo
64 --echo # number of buffered events should agree between status and COUNT(*)
65 # get COUNT(*). also: SELECT with >= cond
66 SELECT COUNT(*) INTO @count_select
67 FROM performance_schema.error_log
68 WHERE logged>=@startup
69 ORDER BY logged;
70 # get status variable
71 SELECT VARIABLE_VALUE INTO @count_status
72 FROM performance_schema.global_status
73 WHERE VARIABLE_NAME LIKE "Error_log_buffered_events";
74
75 --echo #
76 --echo # SELECT with = cond on indexed field
77 SELECT prio,error_code,subsystem,data
78 FROM performance_schema.error_log
79 WHERE data="InnoDB initialization has ended.";
80
81 --echo
82 --echo # FR-1.3.2 Trad log mode
83 --echo # Show the log. No messages here because of non-deterministic parts.
84 --echo # We're also filtering out a number of messages that behave differently
85 --echo # on the first run vis-a-vis subsequent runs with --repeat=..., and some
86 --echo # that we don't know the sequence of because of multi-threading, or that
87 --echo # may or may not appear depending on the machine the test is run on.
88 --echo #
89 --echo # We're filtering this here explicitly to make it more obvious what is
90 --echo # happening. In a real world scenario, this kind of filtering is unlikely
91 --echo # to be desired, and where it is, using --log-error-suppression-list=...
92 --echo # should address the issue. Alternatively, a table of exclusions or a
93 --echo # user-variable and dynamic SQL could be used to streamline the statement
94 --echo # and de-duplicate the exclusion list. For testing in other .tests (i.e.
95 --echo # where we're testing things other than the pfs.error_log mechanism
96 --echo # itself), any of those options could be pre-populated with a sensible
97 --echo # default list of exclusions by mysql-test-run.
98 #
99 # List of exclusions. Reason is race between threads unless otherwise noted.
100 # There are some events we filter out elsewhere because of variable parts in
101 # the actual messages that we can ignore here (as we don't show messages here).
102 #
103 # MY-011243, MY-011240, MY-011245, MY-011323: x-plugin
104 # MY-010931: ER_SERVER_STARTUP_MSG (variable parts: port, path, version)
105 # MY-010949: ER_BASEDIR_SET_TO (variable part: path)
106 # MY-010747: ER_PLUGIN_DISABLED
107 # MY-013546,MY-011946,MY-011952: InnoDB %s
108 # MY-010051: ER_SCHEDULER_STARTED (--repeat=...)
109 # MY-012922: ER_IB_MSG_1097 (seeing on PB but not locally)
110 # MY-011810: ER_PID_FILE_PRIV_DIRECTORY_INSECURE (seeing on PB but not locally)
111 # MY-012932: punchhole support not available on all systems
112 # MY-010902: ER_THREAD_PRIORITY_IGNORED (ignored on Lin, available on Win)
113 # MY-012937: not on -stage for: win+el7+sol11
114 # MY-012366: not on -stage for: solaris11-x86-64bit
115 # MY-010159: on -stage for: OS X (lower_case_table_names)
116 # MY-000067: "unknown variable" - number of these depends on platform/build
117 # MY-010108: ER_CORE_VALUES - thrown when ASAN testing
118 # MY-013602,MY-010069,MY-013595: SSL
119 # MY-012363: InnoDB-page-size changed, for chtest
120 # MY-011953: InnoDB page cleaner. Timing-dependent and thus indeterministic.
121 # MY-000000: sql_print_(error|warning|information)
122 # MY-013623: fallocate() failed (on redo file creation so timing dependent)
123 # MY-013711: Manifest file RO check. Depends on how MTR creates manifest
124 # file and thus indeterministic.
125 # MY-013880: The latest found checkpoint is at lsn...
126 # MY-013881: Redo log capacity sysvar has been changed.
127 # MY-013882: Redo log has been requested to resize. Depends on existing files.
128 # MY-013883: Redo log resize has been cancelled. Depends on existing files.
129 # MY-013884: Redo log has been resized. Depends on existing files.
130 # MY-013908: Invalid systemd socket. Bit indeterministic.
131 # MY-013930: systemd debug.
132 SELECT prio,error_code,subsystem
133 FROM performance_schema.error_log
134 WHERE logged>=@startup
135 AND error_code NOT IN("MY-011243", "MY-011240", "MY-011245", "MY-010931",
136 "MY-010949", "MY-010747", "MY-013546", "MY-010051",
137 "MY-011946", "MY-012922", "MY-011810", "MY-012932",
138 "MY-011952", "MY-011323", "MY-010902", "MY-000000",
139 "MY-012937", "MY-012366", "MY-000067", "MY-010159",
140 "MY-013602", "MY-010069", "MY-013595", "MY-010108",
141 "MY-012363", "MY-011953", "MY-013623", "MY-013711",
142 "MY-013880", "MY-013881", "MY-013882", "MY-013883",
143 "MY-013884", "MY-013908", "MY-013930")
144 ORDER BY logged, error_code;
145
146 --echo
147 --echo # Don't show NOTEs:
148 # A shorter filter-list will do here as the bulk of what we filter above is
149 # Notes, all of which we discard here by Prio. Conversely, we need to filter
150 # out some messages we didn't have to above because this time, we'll show
151 # the actual message part of the event, so we'll have to account for messages
152 # with variable parts.
153 #
154 # MY-011323: x-plugin
155 # MY-010075: ER_CREATING_NEW_UUID (variable part: UUID)
156 # MY-010068: ER_CA_SELF_SIGNED (variable part: CA)
157 # MY-010069: ER_SSL_LIBRARY_ERROR (variable part: error string)
158 # MY-010931: see above
159 # MY-012363: see above
160 # MY-010116: ER_STARTING_AS (variable part: PID)
161 # MY-011810: see above (also, variable part: path)
162 # MY-010159, MY-000067, MY-000000, MY-010108, MY-013602,MY-013595: see above
163 # MY-013711: Manifest file RO check (variable part: path)
164 # MY-013908: Invalid systemd socket. Bit indeterministic.
165 SELECT prio,error_code,subsystem,data
166 FROM performance_schema.error_log
167 WHERE logged>=@startup
168 AND prio!="Note"
169 AND error_code NOT IN("MY-011323", "MY-010075", "MY-010068", "MY-010069",
170 "MY-010931", "MY-010116", "MY-011810", "MY-000000",
171 "MY-000067", "MY-010159", "MY-013595", "MY-013602",
172 "MY-010108", "MY-012363", "MY-013711", "MY-013908",
173 "MY-013930" )
174 ORDER BY logged;
175
176 --echo
177 --echo # FR-1.4.1 Show the log-error-verbosity applies
178 --echo # We passed --log-error-verbosity=3 at start-up. Show that we have Notes.
179 SELECT COUNT(*)>0
180 FROM performance_schema.error_log
181 WHERE logged>=@startup
182 AND prio NOT IN("System", "Warning", "Error");
183
184
185 --echo
186 --echo ########################################################################
187 --echo # Restart with a broken trad log ...
188 --echo
189 --let LOG_FILE_TRAD_SRC=$MYSQLTEST_VARDIR/std_data/wl13681.trad
190 --let LOG_FILE_TRAD_DST=$MYSQLTEST_VARDIR/tmp/wl13681.err
191 --copy_file $LOG_FILE_TRAD_SRC $LOG_FILE_TRAD_DST
192 --let restart_parameters="restart: --log-error=$LOG_FILE_TRAD_DST --log-error-verbosity=3"
193
194 --replace_result $LOG_FILE_TRAD_DST LOG_FILE_TRAD
195 --source include/restart_mysqld.inc
196
197 SET @@session.time_zone=@@global.log_timestamps;
198
199 SELECT logged INTO @startup
200 FROM performance_schema.error_log
201 WHERE error_code="MY-010116" ORDER BY logged DESC LIMIT 1;
202
203 SELECT LEFT(logged,19), error_code, subsystem, data
204 FROM performance_schema.error_log
205 WHERE logged<@startup AND error_code="MY-999999";
206
207
208 --echo
209 --echo ########################################################################
210 --echo # Restart with JSON logging ...
211 --echo
212 --let LOG_FILE_JSON=$MYSQLTEST_VARDIR/tmp/wl13681.err
213 --let LOG_FILE_JSON_SRC=$MYSQLTEST_VARDIR/std_data/wl13681.json
214 --let LOG_FILE_JSON_DST=$MYSQLTEST_VARDIR/tmp/wl13681.err.00.json
215 --copy_file $LOG_FILE_JSON_SRC $LOG_FILE_JSON_DST
216 --let $log_services="log_filter_internal;log_sink_json"
217 --let restart_parameters="restart: --log-error-services=$log_services --log-error=$LOG_FILE_JSON --log-error-verbosity=3"
218
219 --replace_result $LOG_FILE_JSON LOG_FILE_JSON
220 --source include/restart_mysqld.inc
221
222 --echo #
223 --echo # PART II - JSON error log
224 --echo #
225 --echo
226
227 # Make timestamps in file and table agree in case we need to correlate them.
228 SET @@session.time_zone=@@global.log_timestamps;
229
230 --echo
231 --echo # Determine start-up time. Must succeed for other results to have meaning
232 SELECT logged INTO @startup
233 FROM performance_schema.error_log
234 WHERE error_code="MY-010116" ORDER BY logged DESC LIMIT 1;
235
236 --echo
237 --echo # FR-1.3.3 JSON log mode
238 --echo # SELECT with = cond with (possibly) several results
239 SELECT logged=@startup
240 FROM performance_schema.error_log
241 WHERE error_code="MY-010116" ORDER BY logged DESC LIMIT 1;
242
243 --echo
244 --echo # Extract a key/value pair from a JSON record:
245 SELECT prio,error_code,subsystem,JSON_EXTRACT(data,'$.err_symbol')
246 FROM performance_schema.error_log
247 WHERE logged>=@startup
248 AND LEFT(data,1)='{'
249 AND JSON_EXTRACT(data,'$.err_symbol')="ER_STARTING_AS"
250 ORDER BY logged;
251
252 --echo
253 --echo # FR-1.4.2 Information from previous run/log
254 --echo # FR-2 Loading information from previous run
255 --echo # FR-2.2.3 Restoring from the JSON log
256 --echo # Pre-existing record appears BEFORE our start-up marker.
257 --echo # Note also the timestamps:
258 --echo # - The timestamp in the JSON record preserves the original timestamp.
259 --echo # - The timestamp in the logged column is strictly increasing.
260 SELECT logged, prio, error_code, subsystem, data
261 FROM performance_schema.error_log
262 WHERE logged<@startup
263 AND JSON_EXTRACT(data,'$.Azundris')="was here"
264 ORDER BY logged;
265
266 --echo
267 --echo # - The "zero" timestamp in the input is replaced with present date/time.
268 SELECT logged>"2020-02-24 12:34:56.123456", prio, error_code, subsystem, data
269 FROM performance_schema.error_log
270 WHERE logged<@startup
271 AND JSON_EXTRACT(data,'$.Azundris')="auto-generate timestamp"
272 ORDER BY logged;
273
274 --echo
275 --echo # Cleanup.
276 SET GLOBAL log_error_services= DEFAULT;
277 DELETE FROM mysql.component
278 WHERE component_urn="file://component_log_sink_json";
279
280
281 --echo #
282 --echo # Various tests to help QA WL#13681 - performance_schema.error_log
283 --echo #
284 --echo
285
286 --echo
287 --echo # First, restart with various --log-error-verbosity=...,
288 --echo # but not --log-error=... (so when running from mtr,
289 --echo # errors will be logged to stderr).
290 --echo
291
292 --echo
293 --echo # Restarting server with --log-error-verbosity=1
294 --let restart_parameters="restart: --log-error-verbosity=1"
295 --source include/restart_mysqld.inc
296
297 # find "first" entry in latest run
298 SELECT logged INTO @startup
299 FROM performance_schema.error_log
300 WHERE error_code="MY-010116"
301 ORDER BY logged DESC LIMIT 1;
302
303 --echo
304 --echo # There should be no warnings/infos with verbosity=1.
305 SELECT COUNT(*)=0
306 FROM performance_schema.error_log
307 WHERE logged>=@startup AND prio NOT IN("Error","System");
308
309
310 --echo
311 --echo # Restarting server with --log-error-verbosity=2
312 --let restart_parameters="restart: --log-error-verbosity=2"
313 --source include/restart_mysqld.inc
314
315 # find "first" entry in latest run
316 SELECT logged INTO @startup
317 FROM performance_schema.error_log
318 WHERE error_code="MY-010116"
319 ORDER BY logged DESC LIMIT 1;
320
321 --echo
322 --echo # There should be no infos with verbosity=2.
323 SELECT COUNT(*)=0
324 FROM performance_schema.error_log
325 WHERE logged>=@startup AND prio NOT IN("Warning", "Error", "System");
326
327
328 --echo
329 --echo # Now restart with various --log-error-verbosity=...,
330 --echo # and --log-error=... (so when running from mtr,
331 --echo # errors will be logged to a file, and if a suitable
332 --echo # log-sink is used, previous logs can be read).
333 --echo
334
335 --echo
336 --echo # verbosity=1
337 --let LOG_FILE_V1=$LOG_FILE_JSON
338 --let restart_parameters="restart: --log-error=$LOG_FILE_V1 --log-error-verbosity=1"
339 --replace_result $LOG_FILE_V1 LOG_FILE_V1
340 --source include/restart_mysqld.inc
341
342 # find "first" entry in latest run
343 SELECT logged INTO @startup
344 FROM performance_schema.error_log
345 WHERE error_code="MY-010116"
346 ORDER BY logged DESC LIMIT 1;
347
348 --echo
349 --echo # There should be no warnings/infos with verbosity=1.
350 SELECT COUNT(*)=0
351 FROM performance_schema.error_log
352 WHERE logged>=@startup AND prio NOT IN("Error", "System");
353
354 --echo
355 --echo # verbosity=2
356
357 --let LOG_FILE_V2=$MYSQLTEST_VARDIR/tmp/wl13681_v2.err
358 --let restart_parameters="restart: --log-error=$LOG_FILE_V2 --log-error-verbosity=2"
359 --replace_result $LOG_FILE_V2 LOG_FILE_V2
360 --source include/restart_mysqld.inc
361
362 # find "first" entry in latest run
363 SELECT logged INTO @startup
364 FROM performance_schema.error_log
365 WHERE error_code="MY-010116"
366 ORDER BY logged DESC LIMIT 1;
367
368 --echo
369 --echo # There should be warnings/infos with verbosity=2.
370 SELECT COUNT(*)>0
371 FROM performance_schema.error_log
372 WHERE logged>=@startup AND prio NOT IN("Error", "System");
373
374 --echo
375 --echo # verbosity=3
376
377 --let LOG_FILE_V3=$MYSQLTEST_VARDIR/tmp/wl13681_v3.err
378 --let restart_parameters="restart: --log-error=$LOG_FILE_V3 --log-error-verbosity=3"
379 --replace_result $LOG_FILE_V3 LOG_FILE_V3
380 --source include/restart_mysqld.inc
381 SELECT logged INTO @startup
382 FROM performance_schema.error_log
383 WHERE error_code="MY-010116"
384 ORDER BY logged DESC LIMIT 1;
385
386 --echo
387 --echo # There should be infos with verbosity=3.
388 SELECT COUNT(*)>0
389 FROM performance_schema.error_log
390 WHERE logged>=@startup AND prio NOT IN("Note");
391
392
393
394 --echo
395 --echo # Pass --log-error-suppression-list at start-up, then show that the
396 --echo # listed errors have been excluded from the table!
397 --let restart_parameters="restart: --log-error-suppression-list=MY-013595,MY-010069,MY-011810,MY-010116 --log-error-verbosity=3"
398 --source include/restart_mysqld.inc
399 --echo # Show that log_error_suppression_list was accepted from the command-line.
400 SELECT @@global.log_error_suppression_list;
401 --echo # Show that we have no log file (i.e. we're logging to stderr).
402 --echo # This is to guard against --log-error=... being added to the .opt file,
403 --echo # which would then be applied on every restart and skew results in subtle ways.
404 SELECT @@global.log_error;
405 SELECT error_code
406 FROM performance_schema.error_log
407 WHERE error_code IN("MY-013595","MY-010069","MY-011810","MY-010116")
408 AND prio<>"System";
409
410
411
412 --echo
413 --echo # Likewise, show that log_filter_dragnet affects the table.
414 INSTALL COMPONENT "file://component_log_filter_dragnet";
415 # previously MY-011300 - ER_XPLUGIN_LISTENER_SETUP_FAILED
416 SET PERSIST dragnet.log_error_filter_rules='IF ERR_CODE == ER_SERVER_STARTUP_MSG THEN drop.';
417 UNINSTALL COMPONENT "file://component_log_filter_dragnet";
418 --let $log_services="log_filter_dragnet;log_sink_internal"
419 --let LOG_FILE_D=$MYSQLTEST_VARDIR/tmp/wl13681_d.err
420 --let restart_parameters="restart: --log-error-services=$log_services --log-error=$LOG_FILE_D"
421 --replace_result $LOG_FILE_D LOG_FILE_D
422 --source include/restart_mysqld.inc
423
424 --echo # Show that the variable is there, implying the component was loaded,
425 --echo # and that it's value is as expected.
426 SELECT @@global.dragnet.log_error_filter_rules;
427
428 --echo # get start-up timestamp from ER_STARTING_AS
429 SELECT COUNT(logged)
430 FROM performance_schema.error_log
431 WHERE error_code="MY-010116"
432 ORDER BY logged DESC LIMIT 1;
433 SELECT logged INTO @startup
434 FROM performance_schema.error_log
435 WHERE error_code="MY-010116"
436 ORDER BY logged DESC LIMIT 1;
437
438 --echo # show that we filtered out ER_SERVER_STARTUP_MSG
439 SELECT IF(COUNT(*)<>0, "failed: not filtered", "success: filtered")
440 FROM performance_schema.error_log
441 WHERE logged>=@startup AND ERROR_CODE = "MY-010931";
442 SELECT *
443 FROM performance_schema.error_log
444 WHERE logged>=@startup AND ERROR_CODE = "MY-010931";
445
446 RESET PERSIST `dragnet.log_error_filter_rules`;
447 SET @@global.log_error_services=DEFAULT;
448
449 --echo
450 --echo # PERSIST + JSON
451
452 SET PERSIST log_error_verbosity=1;
453 SET PERSIST log_error_suppression_list="MY-013595,MY-010069,MY-011810,MY-010116";
454 SET PERSIST log_error_services="log_filter_internal; log_sink_json";
455
456 --let LOG_FILE_PJ=$MYSQLTEST_VARDIR/tmp/wl13681_pj.err
457 --let restart_parameters="restart: --log-error=$LOG_FILE_PJ"
458 --replace_result $LOG_FILE_PJ LOG_FILE_PJ
459 --source include/restart_mysqld.inc
460
461 SELECT logged INTO @startup
462 FROM performance_schema.error_log
463 WHERE error_code="MY-010116"
464 ORDER BY logged DESC LIMIT 1;
465
466 --echo # verbosity=1 (persisted), should apply (and result in 0 notes/warnings)
467 SELECT COUNT(*)=0 FROM performance_schema.error_log
468 WHERE logged>=@startup AND prio NOT IN("Error","System");
469
470 --echo # no errors excluded by log_error_suppression_list should appear:
471 SELECT COUNT(*)=0
472 FROM performance_schema.error_log
473 WHERE error_code IN("MY-013595","MY-010069","MY-011810","MY-010116")
474 AND logged>=@startup AND prio<>"System";
475
476 --echo # find a row that should exist, and extract JSON data from it
477 SELECT prio,error_code,subsystem,JSON_EXTRACT(data,'$.err_symbol')
478 FROM performance_schema.error_log
479 WHERE logged>=@startup
480 AND LEFT(data,1)='{'
481 AND JSON_EXTRACT(data,'$.err_symbol')="ER_STARTING_AS"
482 ORDER BY logged;
483
484 RESET PERSIST log_error_verbosity;
485 RESET PERSIST log_error_suppression_list;
486 RESET PERSIST log_error_services;
487 SET @@global.log_error_services=DEFAULT;
488
489 --echo
490 --echo # RENAME & DROP Error Expected
491
492 --error ER_DBACCESS_DENIED_ERROR
493 RENAME TABLE performance_schema.error_log to performance_schema.error_log_new;
494
495 --error ER_TABLEACCESS_DENIED_ERROR
496 DROP TABLE IF EXISTS performance_schema.error_log;
497
498 --echo
499
500 # Clean up
501
502 --let restart_parameters="restart:"
503 --source include/restart_mysqld.inc
504
505 SET @@global.log_error_suppression_list=DEFAULT;
506 eval SET @@global.log_error_verbosity=$LOG_VERBOSE;
507
508 --remove_file $LOG_FILE_JSON
509 --remove_file $LOG_FILE_JSON.00.json
510 --remove_file $LOG_FILE_V2
511 --remove_file $LOG_FILE_V3
512 --remove_file $LOG_FILE_D
513 --remove_file $LOG_FILE_D.00.json
514 --remove_file $LOG_FILE_PJ
515 --remove_file $LOG_FILE_PJ.00.json
516
517 --echo # Done!