Merge lp:~percona-toolkit-dev/percona-toolkit/fix-885382 into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Merged at revision: 271
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-885382
Merge into: lp:percona-toolkit/2.1
Diff against target: 90 lines (+51/-4)
2 files modified
bin/pt-query-digest (+14/-2)
t/pt-query-digest/option_sanity.t (+37/-2)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-885382
Reviewer Review Type Date Requested Status
Brian Fraser (community) Approve
Daniel Nichter Approve
Review via email: mp+107646@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

The option's value should be validated earlier, just after creating the OptionParser, so the tool doesn't get started only to die later. So instead of die() it will be $o->save_error().

It might also be nice to qr// the option's two values to ensure that they're valid regex.

Given that, the test in bugs.t can be moved to option_sanity.t.

review: Needs Fixing
269. By Brian Fraser <email address hidden>

Fix for 885382: Check the cardinality of --embedded-attributes

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve
Revision history for this message
Brian Fraser (fraserbn) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-query-digest'
--- bin/pt-query-digest 2012-05-24 17:25:20 +0000
+++ bin/pt-query-digest 2012-05-30 17:23:19 +0000
@@ -11974,6 +11974,18 @@
11974 if ( $o->get('apdex-threshold') <= 0 ) {11974 if ( $o->get('apdex-threshold') <= 0 ) {
11975 $o->save_error("Apdex threshold must be a positive decimal value");11975 $o->save_error("Apdex threshold must be a positive decimal value");
11976 }11976 }
11977 if ( my $patterns = $o->get('embedded-attributes') ) {
11978 $o->save_error("--embedded-attributes should be passed two "
11979 . "comma-separated patterns, got " . scalar(@$patterns) )
11980 unless scalar(@$patterns) == 2;
11981 for my $re (@$patterns) {
11982 no re 'eval';
11983 eval { qr/$re/ };
11984 if ( $EVAL_ERROR ) {
11985 $o->save_error("--embedded-attributes $EVAL_ERROR")
11986 }
11987 }
11988 }
11977 }11989 }
1197811990
11979 # Set an orderby for each groupby; use the default orderby if there11991 # Set an orderby for each groupby; use the default orderby if there
@@ -12416,8 +12428,8 @@
12416 } # get events from log file12428 } # get events from log file
1241712429
12418 if ( my $patterns = $o->get('embedded-attributes') ) {12430 if ( my $patterns = $o->get('embedded-attributes') ) {
12419 $misc->{embed} = qr/$patterns->[0]/o;12431 $misc->{embed} = qr/$patterns->[0]/;
12420 $misc->{capture} = qr/$patterns->[1]/o;12432 $misc->{capture} = qr/$patterns->[1]/;
12421 PTDEBUG && _d('Patterns for embedded attributes:', $misc->{embed},12433 PTDEBUG && _d('Patterns for embedded attributes:', $misc->{embed},
12422 $misc->{capture});12434 $misc->{capture});
12423 }12435 }
1242412436
=== modified file 't/pt-query-digest/option_sanity.t'
--- t/pt-query-digest/option_sanity.t 2011-07-12 22:56:55 +0000
+++ t/pt-query-digest/option_sanity.t 2012-05-30 17:23:19 +0000
@@ -9,7 +9,7 @@
9use strict;9use strict;
10use warnings FATAL => 'all';10use warnings FATAL => 'all';
11use English qw(-no_match_vars);11use English qw(-no_match_vars);
12use Test::More tests => 2;12use Test::More tests => 6;
1313
14use PerconaTest;14use PerconaTest;
1515
@@ -22,7 +22,42 @@
22$output = `$trunk/bin/pt-query-digest --review h=127.1,P=12345,u=msandbox,p=msandbox,D=test`;22$output = `$trunk/bin/pt-query-digest --review h=127.1,P=12345,u=msandbox,p=msandbox,D=test`;
23like($output, qr/--review DSN requires a D/, 'Dies if no t part in --review DSN');23like($output, qr/--review DSN requires a D/, 'Dies if no t part in --review DSN');
2424
2525# #############################################################################
26# https://bugs.launchpad.net/percona-toolkit/+bug/885382
27# pt-query-digest --embedded-attributes doesn't check cardinality
28# #############################################################################
29my $sample = "$trunk/t/lib/samples/slowlogs/";
30
31my @options = qw(
32 --report-format=query_report
33 --limit 10
34 --group-by file
35);
36
37$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*' $sample.slow010.txt`;
38
39like $output,
40 qr/\Q--embedded-attributes should be passed two comma-separated patterns, got 1/,
41 'Bug 885382: --embedded-attributes cardinality';
42
43$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*,(?{1234})' $sample.slow010.txt`;
44
45like $output,
46 qr/\Q--embedded-attributes Eval-group /,
47 "Bug 885382: --embedded-attributes rejects invalid patterns early";
48
49$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*,(?*asdasd' $sample.slow010.txt`;
50
51like $output,
52 qr/\Q--embedded-attributes Sequence (?*...) not recognized/,
53 "Bug 885382: --embedded-attributes rejects invalid patterns early";
54
55$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*,[:alpha:]' $sample.slow010.txt`;
56
57like $output,
58 qr/\Q--embedded-attributes POSIX syntax [: :] belongs inside character/,
59 "Bug 885382: --embedded-attributes rejects warning patterns early";;
60
26# #############################################################################61# #############################################################################
27# Done.62# Done.
28# #############################################################################63# #############################################################################

Subscribers

People subscribed via source and target branches