Merge lp:~percona-toolkit-dev/percona-toolkit/collect-without-stalking into lp:percona-toolkit/2.0

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 185
Merged at revision: 193
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/collect-without-stalking
Merge into: lp:percona-toolkit/2.0
Diff against target: 226 lines (+106/-23)
3 files modified
bin/pt-stalk (+54/-20)
lib/PerconaTest.pm (+10/-0)
t/pt-stalk/pt-stalk.t (+42/-3)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/collect-without-stalking
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+95605@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-stalk'
--- bin/pt-stalk 2012-03-02 16:07:29 +0000
+++ bin/pt-stalk 2012-03-02 16:13:21 +0000
@@ -1032,25 +1032,34 @@
1032 # Run the trigger which returns the value of whatever is being1032 # Run the trigger which returns the value of whatever is being
1033 # checked. When the value is > --threshold for at least --cycle1033 # checked. When the value is > --threshold for at least --cycle
1034 # consecutive times, start collecting.1034 # consecutive times, start collecting.
1035 local value=$($TRIGGER_FUNCTION $OPT_VARIABLE)1035 if [ "$OPT_STALK" ]; then
1036 local trg_exit_status=$?1036 local value=$($TRIGGER_FUNCTION $OPT_VARIABLE)
10371037 local trg_exit_status=$?
1038 if [ -z "$value" ]; then1038
1039 # No value. Maybe we failed to connect to MySQL?1039 if [ -z "$value" ]; then
1040 warn "Detected value is empty; something failed? Trigger exit status: $trg_exit_status"1040 # No value. Maybe we failed to connect to MySQL?
1041 matched=""1041 warn "Detected value is empty; something failed? Trigger exit status: $trg_exit_status"
1042 cycles_true=01042 matched=""
1043 elif [ $value -gt $OPT_THRESHOLD ]; then1043 cycles_true=0
1044 matched="yes"1044 elif [ $value -gt $OPT_THRESHOLD ]; then
1045 cycles_true=$(($cycles_true + 1))1045 matched="yes"
1046 else1046 cycles_true=$(($cycles_true + 1))
1047 matched=""1047 else
1048 cycles_true=01048 matched=""
1049 cycles_true=0
1050 fi
1051
1052 local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true"
1053 log "$msg"
1054 elif [ "$OPT_COLLECT" ]; then
1055 # Make the next if condition true.
1056 matched=1
1057 cycles_true=$OPT_CYCLES
1058
1059 local msg="Not stalking; collect triggered immediately"
1060 log "$msg"
1049 fi1061 fi
10501062
1051 local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true"
1052 log "$msg"
1053
1054 if [ "$matched" -a $cycles_true -ge $OPT_CYCLES ]; then 1063 if [ "$matched" -a $cycles_true -ge $OPT_CYCLES ]; then
1055 # ##################################################################1064 # ##################################################################
1056 # Start collecting, maybe.1065 # Start collecting, maybe.
@@ -1085,7 +1094,6 @@
1085 log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"1094 log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"
1086 last_prefix="$prefix"1095 last_prefix="$prefix"
10871096
1088
1089 # Fork and background the collect subroutine which will1097 # Fork and background the collect subroutine which will
1090 # run for --run-time seconds. We (the parent) sleep1098 # run for --run-time seconds. We (the parent) sleep
1091 # while its collecting (hopefully --sleep is longer than1099 # while its collecting (hopefully --sleep is longer than
@@ -1166,6 +1174,14 @@
1166 option_error "Invalid --function value: $OPT_FUNCTION"1174 option_error "Invalid --function value: $OPT_FUNCTION"
1167 fi1175 fi
11681176
1177 if [ -z "$OPT_STALK" -a "$OPT_COLLECT" ]; then
1178 # Not stalking; do immediate collect once.
1179 OPT_ITERATIONS=1
1180 OPT_CYCLES=0
1181 OPT_SLEEP=0
1182 OPT_INTERVAL=0
1183 fi
1184
1169 usage_or_errors "$0"1185 usage_or_errors "$0"
1170 po_status=$?1186 po_status=$?
1171 rm_tmpdir1187 rm_tmpdir
@@ -1206,7 +1222,7 @@
1206 fi1222 fi
1207 fi1223 fi
12081224
1209 if [ "$OPT_DAEMONIZE" ]; then1225 if [ "$OPT_STALK" -a "$OPT_DAEMONIZE" ]; then
1210 # Check access to the --log file.1226 # Check access to the --log file.
1211 touch "$OPT_LOG" || die "Cannot write to --log $OPT_LOG"1227 touch "$OPT_LOG" || die "Cannot write to --log $OPT_LOG"
12121228
@@ -1226,7 +1242,7 @@
1226 # use $! to get the PID of the child we just forked.1242 # use $! to get the PID of the child we just forked.
1227 echo "$!" > "$OPT_PID"1243 echo "$!" > "$OPT_PID"
1228 else1244 else
1229 make_pid_file "$OPT_PID" $$1245 [ "$OPT_STALK" ] && make_pid_file "$OPT_PID" $$
1230 main "$@"1246 main "$@"
1231 fi1247 fi
1232fi1248fi
@@ -1360,6 +1376,8 @@
1360Collect system information. You can negate this option to make the tool watch1376Collect system information. You can negate this option to make the tool watch
1361the system but not actually gather any diagnostic data.1377the system but not actually gather any diagnostic data.
13621378
1379See also L<"--stalk">.
1380
1363=item --collect-gdb1381=item --collect-gdb
13641382
1365Collect GDB stacktraces. This is achieved by attaching to MySQL and printing1383Collect GDB stacktraces. This is achieved by attaching to MySQL and printing
@@ -1583,6 +1601,22 @@
1583It also prevents filling up the disk or gathering too much data to analyze1601It also prevents filling up the disk or gathering too much data to analyze
1584reasonably.1602reasonably.
15851603
1604=item --stalk
1605
1606default: yes; negatable: yes
1607
1608Watch the server and wait for the trigger to occur. You can negate this option
1609to make the tool immediately gather any diagnostic data once and exit. This is
1610useful if a problem is already happening, but pt-stalk is not running, so
1611you only want to collect diagnostic data.
1612
1613If this option is negate, L<"--daemonize">, L<"--log">, L<"--pid">, and other
1614stalking-related options have no effect; the tool simply collects diagnostic
1615data and exits. Safeguard options, like L<"--disk-bytes-free"> and
1616L<"--disk-pct-free">, are still respected.
1617
1618See also L<"--collect">.
1619
1586=item --threshold1620=item --threshold
15871621
1588type: int; default: 251622type: int; default: 25
15891623
=== modified file 'lib/PerconaTest.pm'
--- lib/PerconaTest.pm 2012-02-14 19:48:24 +0000
+++ lib/PerconaTest.pm 2012-03-02 16:13:21 +0000
@@ -294,6 +294,16 @@
294 );294 );
295}295}
296296
297sub wait_for_sh {
298 my ($cmd) = @_;
299 return wait_until(
300 sub {
301 my $retval = system("$cmd 2>/dev/null");
302 return $retval >> 8 == 0 ? 1 : 0;
303 }
304 );
305};
306
297sub _read {307sub _read {
298 my ( $fh ) = @_;308 my ( $fh ) = @_;
299 return <$fh>;309 return <$fh>;
300310
=== modified file 't/pt-stalk/pt-stalk.t'
--- t/pt-stalk/pt-stalk.t 2012-01-30 17:05:35 +0000
+++ t/pt-stalk/pt-stalk.t 2012-03-02 16:13:21 +0000
@@ -24,7 +24,7 @@
24 plan skip_all => 'Cannot connect to sandbox master';24 plan skip_all => 'Cannot connect to sandbox master';
25}25}
26else {26else {
27 plan tests => 21;27 plan tests => 25;
28}28}
2929
30my $cnf = "/tmp/12345/my.sandbox.cnf";30my $cnf = "/tmp/12345/my.sandbox.cnf";
@@ -155,7 +155,7 @@
155 "Collect ran for --run-time"155 "Collect ran for --run-time"
156);156);
157157
158$output = `ps x | grep -v grep | grep 'pt-stalk pt-stalk --iterations 1 --dest $dest'`;158$output = `ps x | grep -v grep | grep 'pt-stalk --iterations 1'`;
159is(159is(
160 $output,160 $output,
161 "",161 "",
@@ -202,7 +202,7 @@
202 "No files collected"202 "No files collected"
203);203);
204204
205$output = `ps x | grep -v grep | grep 'pt-stalk pt-stalk --iterations 1 --dest $dest'`;205$output = `ps x | grep -v grep | grep 'pt-stalk --no-collect'`;
206is(206is(
207 $output,207 $output,
208 "",208 "",
@@ -238,6 +238,45 @@
238diag(`cp $ENV{HOME}/.pt-stalk.conf.original $ENV{HOME}/.pt-stalk.conf 2>/dev/null`);238diag(`cp $ENV{HOME}/.pt-stalk.conf.original $ENV{HOME}/.pt-stalk.conf 2>/dev/null`);
239239
240# #############################################################################240# #############################################################################
241# Don't stalk, just collect.
242# #############################################################################
243diag(`rm $pid_file 2>/dev/null`);
244diag(`rm $log_file 2>/dev/null`);
245diag(`rm $dest/* 2>/dev/null`);
246
247$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk -- --defaults-file=$cnf >$log_file 2>&1");
248
249PerconaTest::wait_for_files("$dest/nostalk-trigger");
250$output = `cat $dest/nostalk-trigger`;
251like(
252 $output,
253 qr/Not stalking/,
254 "Not stalking, collect triggered"
255);
256
257PerconaTest::wait_for_files("$dest/nostalk-df");
258PerconaTest::wait_for_sh("test \$(grep -c '^TS' $dest/nostalk-df) -ge 2");
259chomp($output = `grep -c '^TS' $dest/nostalk-df`);
260is(
261 $output,
262 2,
263 "Not stalking, collect ran for --run-time"
264);
265
266is(
267 `cat $dest/nostalk-hostname`,
268 `hostname`,
269 "Not stalking, collect gathered data"
270);
271
272$output = `ps x | grep -v grep | grep 'pt-stalk --no-stalk'`;
273is(
274 $output,
275 "",
276 "Not stalking, pt-stalk is not running"
277);
278
279# #############################################################################
241# Done.280# Done.
242# #############################################################################281# #############################################################################
243diag(`rm $pid_file 2>/dev/null`);282diag(`rm $pid_file 2>/dev/null`);

Subscribers

People subscribed via source and target branches