diff --git a/bin/pt-query-digest b/bin/pt-query-digest index d86755a9..36736753 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -9692,7 +9692,8 @@ sub parse_event { $cmd = $arg; } else { - my ($user, undef, $db) = $arg =~ /(\S+)/g; + my ($user) = $arg =~ m/(\S+)/; + my ($db) = $arg =~ m/on (\S+)/; my $host; ($user, $host) = split(/@/, $user); PTDEBUG && _d('Connect', $user, '@', $host, 'on', $db); diff --git a/lib/GeneralLogParser.pm b/lib/GeneralLogParser.pm index b13337d6..14f47945 100644 --- a/lib/GeneralLogParser.pm +++ b/lib/GeneralLogParser.pm @@ -129,7 +129,8 @@ sub parse_event { else { # The Connect command may or may not be followed by 'on'. # When it is, 'on' may or may not be followed by a database. - my ($user, undef, $db) = $arg =~ /(\S+)/g; + my ($user) = $arg =~ m/(\S+)/; + my ($db) = $arg =~ m/on (\S+)/; my $host; ($user, $host) = split(/@/, $user); PTDEBUG && _d('Connect', $user, '@', $host, 'on', $db); diff --git a/t/lib/GeneralLogParser.t b/t/lib/GeneralLogParser.t index 619e3883..d45afa93 100644 --- a/t/lib/GeneralLogParser.t +++ b/t/lib/GeneralLogParser.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 7; +use Test::More; use GeneralLogParser; use PerconaTest; @@ -219,7 +219,58 @@ test_log_parser( ] ); +# Customer issue from Ernie. +test_log_parser( + parser => $p, + file => $sample.'genlog004.txt', + oktorun => sub { $oktorun = $_[0]; }, + result => [ + { + Query_time => 0, + Thread_id => '12345', + arg => q/administrator command: Access denied for user 'nobody'@'localhost' (using password: NO) +/, + bytes => 88, + cmd => 'Admin', + pos_in_log => 0, + ts => undef + }, + { + Query_time => 0, + Thread_id => '12345', + arg => 'administrator command: Connect', + bytes => 30, + cmd => 'Admin', + host => 'localhost', + pos_in_log => 81, + ts => undef, + user => 'nobody' + }, + { + Query_time => 0, + Thread_id => '31519', + arg => 'BEGIN', + bytes => 5, + cmd => 'Query', + pos_in_log => 122, + ts => undef + }, + { + Query_time => 0, + Thread_id => '98765', + arg => 'administrator command: Connect', + bytes => 30, + cmd => 'Admin', + db => 'sar', + host => '1.2.3.4', + pos_in_log => 184, + ts => undef, + user => 'payments_r' + }, + ], +); + # ############################################################################# # Done. # ############################################################################# -exit; +done_testing; diff --git a/t/lib/samples/genlogs/genlog004.txt b/t/lib/samples/genlogs/genlog004.txt new file mode 100644 index 00000000..d006d369 --- /dev/null +++ b/t/lib/samples/genlogs/genlog004.txt @@ -0,0 +1,4 @@ + 12345 Connect Access denied for user 'nobody'@'localhost' (using password: NO) + 12345 Connect nobody@localhost as on + 31519 Query BEGIN + 98765 Connect payments_r@1.2.3.4 on sar