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
1=== modified file 'bin/pt-query-digest'
2--- bin/pt-query-digest 2012-05-24 17:25:20 +0000
3+++ bin/pt-query-digest 2012-05-30 17:23:19 +0000
4@@ -11974,6 +11974,18 @@
5 if ( $o->get('apdex-threshold') <= 0 ) {
6 $o->save_error("Apdex threshold must be a positive decimal value");
7 }
8+ if ( my $patterns = $o->get('embedded-attributes') ) {
9+ $o->save_error("--embedded-attributes should be passed two "
10+ . "comma-separated patterns, got " . scalar(@$patterns) )
11+ unless scalar(@$patterns) == 2;
12+ for my $re (@$patterns) {
13+ no re 'eval';
14+ eval { qr/$re/ };
15+ if ( $EVAL_ERROR ) {
16+ $o->save_error("--embedded-attributes $EVAL_ERROR")
17+ }
18+ }
19+ }
20 }
21
22 # Set an orderby for each groupby; use the default orderby if there
23@@ -12416,8 +12428,8 @@
24 } # get events from log file
25
26 if ( my $patterns = $o->get('embedded-attributes') ) {
27- $misc->{embed} = qr/$patterns->[0]/o;
28- $misc->{capture} = qr/$patterns->[1]/o;
29+ $misc->{embed} = qr/$patterns->[0]/;
30+ $misc->{capture} = qr/$patterns->[1]/;
31 PTDEBUG && _d('Patterns for embedded attributes:', $misc->{embed},
32 $misc->{capture});
33 }
34
35=== modified file 't/pt-query-digest/option_sanity.t'
36--- t/pt-query-digest/option_sanity.t 2011-07-12 22:56:55 +0000
37+++ t/pt-query-digest/option_sanity.t 2012-05-30 17:23:19 +0000
38@@ -9,7 +9,7 @@
39 use strict;
40 use warnings FATAL => 'all';
41 use English qw(-no_match_vars);
42-use Test::More tests => 2;
43+use Test::More tests => 6;
44
45 use PerconaTest;
46
47@@ -22,7 +22,42 @@
48 $output = `$trunk/bin/pt-query-digest --review h=127.1,P=12345,u=msandbox,p=msandbox,D=test`;
49 like($output, qr/--review DSN requires a D/, 'Dies if no t part in --review DSN');
50
51-
52+# #############################################################################
53+# https://bugs.launchpad.net/percona-toolkit/+bug/885382
54+# pt-query-digest --embedded-attributes doesn't check cardinality
55+# #############################################################################
56+my $sample = "$trunk/t/lib/samples/slowlogs/";
57+
58+my @options = qw(
59+ --report-format=query_report
60+ --limit 10
61+ --group-by file
62+);
63+
64+$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*' $sample.slow010.txt`;
65+
66+like $output,
67+ qr/\Q--embedded-attributes should be passed two comma-separated patterns, got 1/,
68+ 'Bug 885382: --embedded-attributes cardinality';
69+
70+$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*,(?{1234})' $sample.slow010.txt`;
71+
72+like $output,
73+ qr/\Q--embedded-attributes Eval-group /,
74+ "Bug 885382: --embedded-attributes rejects invalid patterns early";
75+
76+$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*,(?*asdasd' $sample.slow010.txt`;
77+
78+like $output,
79+ qr/\Q--embedded-attributes Sequence (?*...) not recognized/,
80+ "Bug 885382: --embedded-attributes rejects invalid patterns early";
81+
82+$output = `$trunk/bin/pt-query-digest @options --embedded-attributes '-- .*,[:alpha:]' $sample.slow010.txt`;
83+
84+like $output,
85+ qr/\Q--embedded-attributes POSIX syntax [: :] belongs inside character/,
86+ "Bug 885382: --embedded-attributes rejects warning patterns early";;
87+
88 # #############################################################################
89 # Done.
90 # #############################################################################

Subscribers

People subscribed via source and target branches