From 9eb95cb4da1dfa4d9305de06942e000b853ff6ba Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Wed, 20 Jul 2016 15:53:59 -0300 Subject: [PATCH] Tests added for SlowLogParser SlowLogParser now is able to handle MySQL dates in RFC3339 format. A new test for this case was added and all scripts using SlowLogParser in bin/ have been updated. --- bin/pt-index-usage | 2 +- bin/pt-table-usage | 2 +- bin/pt-upgrade | 2 +- t/lib/SlowLogParser.t | 40 +++++++++++++++++++++++++++++ t/lib/samples/slowlogs/mysql5.7.log | 16 ++++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100755 t/lib/samples/slowlogs/mysql5.7.log diff --git a/bin/pt-index-usage b/bin/pt-index-usage index 47c61dfd..c7f11879 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -2799,7 +2799,7 @@ sub new { return bless $self, $class; } -my $slow_log_ts_line = qr/^# Time: ([0-9: ]{15})/; +my $slow_log_ts_line = qr/^# Time: ((?:[0-9: ]{15})|(?:[-0-9: T]{19}))/; my $slow_log_uh_line = qr/# User\@Host: ([^\[]+|\[[^[]+\]).*?@ (\S*) \[(.*)\]\s*(?:Id:\s*(\d+))?/; my $slow_log_hd_line = qr{ ^(?: diff --git a/bin/pt-table-usage b/bin/pt-table-usage index f5508579..2af3ff19 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -2239,7 +2239,7 @@ sub new { return bless $self, $class; } -my $slow_log_ts_line = qr/^# Time: ([0-9: ]{15})/; +my $slow_log_ts_line = qr/^# Time: ((?:[0-9: ]{15})|(?:[-0-9: T]{19}))/; my $slow_log_uh_line = qr/# User\@Host: ([^\[]+|\[[^[]+\]).*?@ (\S*) \[(.*)\]\s*(?:Id:\s*(\d+))?/; my $slow_log_hd_line = qr{ ^(?: diff --git a/bin/pt-upgrade b/bin/pt-upgrade index 66c406f7..66d881e1 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -6628,7 +6628,7 @@ sub new { return bless $self, $class; } -my $slow_log_ts_line = qr/^# Time: ([0-9: ]{15})/; +my $slow_log_ts_line = qr/^# Time: ((?:[0-9: ]{15})|(?:[-0-9: T]{19}))/; my $slow_log_uh_line = qr/# User\@Host: ([^\[]+|\[[^[]+\]).*?@ (\S*) \[(.*)\]\s*(?:Id:\s*(\d+))?/; my $slow_log_hd_line = qr{ ^(?: diff --git a/t/lib/SlowLogParser.t b/t/lib/SlowLogParser.t index 28fdbb7e..a618b665 100644 --- a/t/lib/SlowLogParser.t +++ b/t/lib/SlowLogParser.t @@ -17,6 +17,46 @@ use PerconaTest; my $p = new SlowLogParser; my $sample = "t/lib/samples/slowlogs"; +# Check that we can parse MySQL 5.7+ slow log with dates in RFC3339 format. +test_log_parser( + parser => $p, + file => "$sample/mysql5.7.log", + result => [ + { + Lock_time => '0.000324', + Query_time => '0.003464', + Rows_examined => '2000', + Rows_sent => '1000', + Thread_id => '3', + arg => 'SELECT * FROM db_facturacion.facturas LIMIT 0, 1000', + bytes => 51, + cmd => 'Query', + host => 'localhost', + ip => '127.0.0.1', + pos_in_log => 0, + timestamp => '1469038405', + ts => '2016-07-20T18:13:25', + user => 'root' + }, + { + Lock_time => '0.000055', + Query_time => '0.000241', + Rows_examined => '0', + Rows_sent => '0', + Thread_id => '4', + arg => 'SHOW INDEX FROM `db_facturacion`.`facturas`', + bytes => 43, + cmd => 'Query', + host => 'localhost', + ip => '127.0.0.1', + pos_in_log => 608, + timestamp => '1469038405', + ts => '2016-07-20T18:13:25', + user => 'root' + } + + ], +); # Check that I can parse a slow log in the default slow log format. test_log_parser( parser => $p, diff --git a/t/lib/samples/slowlogs/mysql5.7.log b/t/lib/samples/slowlogs/mysql5.7.log new file mode 100755 index 00000000..24dde943 --- /dev/null +++ b/t/lib/samples/slowlogs/mysql5.7.log @@ -0,0 +1,16 @@ +/usr/sbin/mysqld, Version: 5.7.12-0ubuntu1.1-log ((Ubuntu)). started with: +Tcp port: 3306 Unix socket: /var/run/mysqld/mysqld.sock +Time Id Command Argument +/usr/sbin/mysqld, Version: 5.7.12-0ubuntu1.1-log ((Ubuntu)). started with: +Tcp port: 3306 Unix socket: /var/run/mysqld/mysqld.sock +Time Id Command Argument +# Time: 2016-07-20T18:13:25.698433Z +# User@Host: root[root] @ localhost [127.0.0.1] Id: 3 +# Query_time: 0.003464 Lock_time: 0.000324 Rows_sent: 1000 Rows_examined: 2000 +SET timestamp=1469038405; +SELECT * FROM db_facturacion.facturas LIMIT 0, 1000; +# Time: 2016-07-20T18:13:25.699880Z +# User@Host: root[root] @ localhost [127.0.0.1] Id: 4 +# Query_time: 0.000241 Lock_time: 0.000055 Rows_sent: 0 Rows_examined: 0 +SET timestamp=1469038405; +SHOW INDEX FROM `db_facturacion`.`facturas`;