用于EagleEye3.0 规则集漏报和误报测试的示例项目,项目收集于github和gitee
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

164 lines
5.3 KiB

--echo #
--echo # WL#9323: Logging services: Improved error logging in 8.0
--echo #
#
# this test uses the debug mode where we pipe all error logging
# to stderr, so log_sink_test (square brackets) and log_sink_json
# (curly braces) are interleaved below. log_components_split
# tests the "production setup" where different formats go to
# different files.
#
--source include/have_debug.inc
--source include/have_log_component.inc
--source include/xplugin_wait_for_interfaces.inc
let GREP_START=`SELECT DATE_FORMAT(CONVERT_TZ(SYSDATE(6),'SYSTEM','UTC'),'%Y%m%d%H%i%s%f');`;
SET @orig_log_error_verbosity= @@GLOBAL.log_error_verbosity;
SET @@global.log_error_verbosity=3;
let $log_error_= `SELECT @@GLOBAL.log_error`;
if($log_error_ == "stderr")
{
let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err;
}
FLUSH LOGS;
# Send parse-trace to error log; first one with a current timestamp
# to compare against our GREP_START defined above.
SET @@session.debug="+d,parser_stmt_to_error_log";
# Now normalize timestamp and thread_ID on all following lines,
# for less hassle with --regex_replace in test files. Once
# WL#9651 goes live, we can use that to achieve the same thing.
SET @@session.debug="+d,log_error_normalize";
SELECT @@global.log_error_services;
--echo
## WL#9651
# SET @@global.log_error_filter_rules='+source_line? delete_field. +thread? delete_field. +user? delete_field. +host? delete_field. +query_id? delete_field. +time? delete_field. +_pid? delete_field. +_platform? delete_field. +_client_version? delete_field. +_os? delete_field. +err_code? delete_field.';
# --echo
SELECT "*** SWITCHING ERROR LOG TO JSON ***";
INSTALL COMPONENT "file://component_log_sink_json";
SET @@global.log_error_services="log_filter_internal; log_sink_json;";
--echo # may not start with a delimiter
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.log_error_services=";log_sink_internal";
SHOW WARNINGS;
--echo # may not end on a filter
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.log_error_services="log_sink_internal; log_filter_internal";
SHOW WARNINGS;
--echo # may not mix delimiters
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.log_error_services="log_filter_internal;,log_sink_internal";
SHOW WARNINGS;
--echo # whitespace alone is no valid delimiter
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.log_error_services="log_filter_internal log_sink_internal";
SHOW WARNINGS;
--echo # unknown component
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.log_error_services="azundris";
SHOW WARNINGS;
--echo # disallowed. this component exists, but only for internal use during
--echo # start-up; it may not be set by the user
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.log_error_services="log_sink_buffer";
SHOW WARNINGS;
SELECT "logging as JSON";
SET @@global.log_error_services="log_filter_internal, log_sink_internal,";
UNINSTALL COMPONENT "file://component_log_sink_json";
--echo
SELECT "*** SWITCHING ERROR LOG TO TRAD AND JSON ***";
INSTALL COMPONENT "file://component_log_sink_json";
SET @@global.log_error_services="log_filter_internal, log_sink_internal, log_sink_json";
SELECT "logging as traditional MySQL error log and as JSON";
SET @@global.log_error_services="log_filter_internal; log_sink_internal";
UNINSTALL COMPONENT "file://component_log_sink_json";
--echo
SELECT "*** TRYING TO LOG THINGS FROM EXTERNAL SERVICE ***";
--echo # NB: log_sink_test must self-disable its sink after one line.
INSTALL COMPONENT "file://component_log_sink_json";
INSTALL COMPONENT "file://component_log_sink_test";
SET @@global.log_error_services="log_filter_internal; log_sink_test; log_sink_json";
SELECT "logging as traditional MySQL error log and as JSON";
--echo # Force a call to variable-checking in all loaded log-services
# currently nothing is loaded that can handle this, so we'll fail on update
--error ER_UNKNOWN_SYSTEM_VARIABLE
SET @@global.log_error_filter_rules= DEFAULT;
--echo # Reload logging services
FLUSH ERROR LOGS;
--echo # Should not be able to uninstall as it's in use.
--error ER_COMPONENTS_UNLOAD_CANT_UNREGISTER_SERVICE
UNINSTALL COMPONENT "file://component_log_sink_test";
--echo # Remove from active set:
SET @@global.log_error_services="log_filter_internal; log_sink_internal";
--echo # Now we can uninstall.
UNINSTALL COMPONENT "file://component_log_sink_test";
UNINSTALL COMPONENT "file://component_log_sink_json";
--echo
--echo # cleanup
SET @@session.debug="-d,parser_stmt_to_error_log";
SET @@session.debug="-d,log_error_normalize";
SET @@global.log_error_verbosity= @orig_log_error_verbosity;
## WL#9651
# SET @@global.log_error_filter_rules=@save_filters;
FLUSH ERROR LOGS;
--echo
--echo ###
--echo ### error log file
--echo ###
--echo
let GREP_FILE=$log_error_;
perl;
use strict;
use File::stat;
my $file= $ENV{'GREP_FILE'} or die("grep file not set");
my $pattern="^20";
my $stime= $ENV{'GREP_START'};
open(FILE, "$file") or die("Unable to open $file: $!");
while (<FILE>) {
my $line = $_;
my $ts = 0;
if ($stime == 0) {
print "$line";
}
elsif ($line =~ /$pattern/) {
$line =~ /([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])T([0-9][0-9]):([0-9][0-9]):([0-9][0-9])\.([0-9][0-9][0-9][0-9][0-9][0-9])[-+Z][0-9:]* *[0-9]* *?(\[.*)/;
$ts=$1.$2.$3.$4.$5.$6.$7;
if ($ts >= $stime) {
$stime= 0;
}
}
}
close(FILE);
EOF
--echo
--echo ###
--echo ### done
--echo ###