Merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-quiet into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 527
Merged at revision: 521
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-quiet
Merge into: lp:percona-toolkit/2.1
Diff against target: 910 lines (+391/-87)
13 files modified
bin/pt-ioprofile (+15/-6)
bin/pt-mysql-summary (+15/-6)
bin/pt-pmp (+1/-1)
bin/pt-sift (+1/-1)
bin/pt-stalk (+53/-14)
bin/pt-summary (+15/-6)
lib/PerconaTest.pm (+33/-1)
lib/bash/log_warn_die.sh (+14/-5)
t/lib/bash/log_warn_die.sh (+83/-10)
t/pt-stalk/option_sanity.t (+24/-0)
t/pt-stalk/pt-stalk.t (+90/-33)
t/pt-stalk/samples/plugin002.sh (+5/-0)
util/test-bash-functions (+42/-4)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-quiet
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+144766@code.launchpad.net
To post a comment you must log in.
525. By Daniel Nichter

Fix default log level in log_warn_die.sh.

526. By Daniel Nichter

Fix typo in t/pt-stalk/option_sanity.t.

527. By Daniel Nichter

Fix error caused on some boxes by using diff when it's not defined.

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-ioprofile'
--- bin/pt-ioprofile 2013-01-03 00:54:18 +0000
+++ bin/pt-ioprofile 2013-01-24 19:10:25 +0000
@@ -20,23 +20,32 @@
20PTDEBUG="${PTDEBUG:-""}"20PTDEBUG="${PTDEBUG:-""}"
21EXIT_STATUS=021EXIT_STATUS=0
2222
23ts() {
24 TS=$(date +%F-%T | tr ':-' '_')
25 echo "$TS $*"
26}
27
28info() {
29 [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
30}
31
23log() {32log() {
24 TS=$(date +%F-%T | tr ':-' '_');33 [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
25 echo "$TS $*"
26}34}
2735
28warn() {36warn() {
29 log "$*" >&237 [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
30 EXIT_STATUS=138 EXIT_STATUS=1
31}39}
3240
33die() {41die() {
34 warn "$*"42 ts "$*" >&2
43 EXIT_STATUS=1
35 exit 144 exit 1
36}45}
3746
38_d () {47_d () {
39 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&248 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
40}49}
4150
42# ###########################################################################51# ###########################################################################
@@ -861,7 +870,7 @@
861# Execute the program if it was not included from another file.870# Execute the program if it was not included from another file.
862# This makes it possible to include without executing, and thus test.871# This makes it possible to include without executing, and thus test.
863if [ "${0##*/}" = "$TOOL" ] \872if [ "${0##*/}" = "$TOOL" ] \
864 || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then873 || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
865874
866 # Parse command line options. We must do this first so we can875 # Parse command line options. We must do this first so we can
867 # see if --daemonize was specified.876 # see if --daemonize was specified.
868877
=== modified file 'bin/pt-mysql-summary'
--- bin/pt-mysql-summary 2013-01-03 00:54:18 +0000
+++ bin/pt-mysql-summary 2013-01-24 19:10:25 +0000
@@ -22,23 +22,32 @@
22PTDEBUG="${PTDEBUG:-""}"22PTDEBUG="${PTDEBUG:-""}"
23EXIT_STATUS=023EXIT_STATUS=0
2424
25ts() {
26 TS=$(date +%F-%T | tr ':-' '_')
27 echo "$TS $*"
28}
29
30info() {
31 [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
32}
33
25log() {34log() {
26 TS=$(date +%F-%T | tr ':-' '_');35 [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
27 echo "$TS $*"
28}36}
2937
30warn() {38warn() {
31 log "$*" >&239 [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
32 EXIT_STATUS=140 EXIT_STATUS=1
33}41}
3442
35die() {43die() {
36 warn "$*"44 ts "$*" >&2
45 EXIT_STATUS=1
37 exit 146 exit 1
38}47}
3948
40_d () {49_d () {
41 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&250 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
42}51}
4352
44# ###########################################################################53# ###########################################################################
@@ -2412,7 +2421,7 @@
2412# Execute the program if it was not included from another file.2421# Execute the program if it was not included from another file.
2413# This makes it possible to include without executing, and thus test.2422# This makes it possible to include without executing, and thus test.
2414if [ "${0##*/}" = "$TOOL" ] \2423if [ "${0##*/}" = "$TOOL" ] \
2415 || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then2424 || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
24162425
2417 # Set up temporary dir.2426 # Set up temporary dir.
2418 mk_tmpdir2427 mk_tmpdir
24192428
=== modified file 'bin/pt-pmp'
--- bin/pt-pmp 2013-01-03 00:54:18 +0000
+++ bin/pt-pmp 2013-01-24 19:10:25 +0000
@@ -215,7 +215,7 @@
215# Execute the program if it was not included from another file. This makes it215# Execute the program if it was not included from another file. This makes it
216# possible to include without executing, and thus test.216# possible to include without executing, and thus test.
217if [ "${0##*/}" = "$TOOL" ] \217if [ "${0##*/}" = "$TOOL" ] \
218 || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then218 || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
219 mk_tmpdir219 mk_tmpdir
220 main "$@"220 main "$@"
221 rm_tmpdir221 rm_tmpdir
222222
=== modified file 'bin/pt-sift'
--- bin/pt-sift 2013-01-03 00:54:18 +0000
+++ bin/pt-sift 2013-01-24 19:10:25 +0000
@@ -587,7 +587,7 @@
587# Execute the program if it was not included from another file. This makes it587# Execute the program if it was not included from another file. This makes it
588# possible to include without executing, and thus test.588# possible to include without executing, and thus test.
589if [ "${0##*/}" = "$TOOL" ] \589if [ "${0##*/}" = "$TOOL" ] \
590 || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then590 || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
591 main "${@:-""}"591 main "${@:-""}"
592fi592fi
593593
594594
=== modified file 'bin/pt-stalk'
--- bin/pt-stalk 2013-01-03 00:54:18 +0000
+++ bin/pt-stalk 2013-01-24 19:10:25 +0000
@@ -22,23 +22,32 @@
22PTDEBUG="${PTDEBUG:-""}"22PTDEBUG="${PTDEBUG:-""}"
23EXIT_STATUS=023EXIT_STATUS=0
2424
25ts() {
26 TS=$(date +%F-%T | tr ':-' '_')
27 echo "$TS $*"
28}
29
30info() {
31 [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
32}
33
25log() {34log() {
26 TS=$(date +%F-%T | tr ':-' '_');35 [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
27 echo "$TS $*"
28}36}
2937
30warn() {38warn() {
31 log "$*" >&239 [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
32 EXIT_STATUS=140 EXIT_STATUS=1
33}41}
3442
35die() {43die() {
36 warn "$*"44 ts "$*" >&2
45 EXIT_STATUS=1
37 exit 146 exit 1
38}47}
3948
40_d () {49_d () {
41 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&250 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
42}51}
4352
44# ###########################################################################53# ###########################################################################
@@ -962,6 +971,10 @@
962 :971 :
963}972}
964973
974after_interval_sleep() {
975 :
976}
977
965after_stalk() {978after_stalk() {
966 :979 :
967}980}
@@ -1066,9 +1079,7 @@
1066 local seconds="$1"1079 local seconds="$1"
1067 local msg="${2:-""}"1080 local msg="${2:-""}"
1068 if oktorun; then1081 if oktorun; then
1069 if [ -n "$msg" ]; then1082 [ "$msg" ] && info "$msg"
1070 log "$msg"
1071 fi
1072 sleep $seconds1083 sleep $seconds
1073 fi1084 fi
1074}1085}
@@ -1126,7 +1137,11 @@
1126 fi1137 fi
11271138
1128 local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true"1139 local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true"
1129 log "$msg"1140 if [ "$matched" ]; then
1141 log "$msg"
1142 else
1143 info "$msg"
1144 fi
1130 elif [ "$OPT_COLLECT" ]; then1145 elif [ "$OPT_COLLECT" ]; then
1131 # Make the next if condition true.1146 # Make the next if condition true.
1132 matched=11147 matched=1
@@ -1140,7 +1155,7 @@
1140 # ##################################################################1155 # ##################################################################
1141 # Start collecting, maybe.1156 # Start collecting, maybe.
1142 # ##################################################################1157 # ##################################################################
1143 log "Collect triggered"1158 log "Collect $ITER triggered"
11441159
1145 # Send email to whomever that collect has been triggered.1160 # Send email to whomever that collect has been triggered.
1146 if [ "$OPT_NOTIFY_BY_EMAIL" ]; then1161 if [ "$OPT_NOTIFY_BY_EMAIL" ]; then
@@ -1166,8 +1181,8 @@
1166 "$margin"1181 "$margin"
1167 if [ $? -eq 0 ]; then1182 if [ $? -eq 0 ]; then
1168 # There should be enough disk space, so collect.1183 # There should be enough disk space, so collect.
1169 log "$msg" >> "$OPT_DEST/$prefix-trigger"1184 ts "$msg" >> "$OPT_DEST/$prefix-trigger"
1170 log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"1185 ts "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"
1171 last_prefix="$prefix"1186 last_prefix="$prefix"
11721187
1173 # Plugin hook:1188 # Plugin hook:
@@ -1181,7 +1196,7 @@
1181 collect "$OPT_DEST" "$prefix"1196 collect "$OPT_DEST" "$prefix"
1182 ) >> "$OPT_DEST/$prefix-output" 2>&1 &1197 ) >> "$OPT_DEST/$prefix-output" 2>&1 &
1183 local collector_pid=$!1198 local collector_pid=$!
1184 log "Collector PID $collector_pid"1199 log "Collect $ITER PID $collector_pid"
11851200
1186 # Plugin hook:1201 # Plugin hook:
1187 after_collect $collector_pid1202 after_collect $collector_pid
@@ -1199,6 +1214,7 @@
1199 # ##################################################################1214 # ##################################################################
1200 # Done collecting.1215 # Done collecting.
1201 # ##################################################################1216 # ##################################################################
1217 log "Collect $ITER done"
1202 ITER=$((ITER + 1))1218 ITER=$((ITER + 1))
1203 cycles_true=01219 cycles_true=0
1204 sleep_ok "$OPT_SLEEP" "Sleeping $OPT_SLEEP seconds after collect"1220 sleep_ok "$OPT_SLEEP" "Sleeping $OPT_SLEEP seconds after collect"
@@ -1208,6 +1224,9 @@
1208 else1224 else
1209 # Trigger/check/value is ok, sleep until next check.1225 # Trigger/check/value is ok, sleep until next check.
1210 sleep_ok "$OPT_INTERVAL"1226 sleep_ok "$OPT_INTERVAL"
1227
1228 # Plugin hook:
1229 after_interval_sleep
1211 fi1230 fi
1212 done1231 done
12131232
@@ -1291,7 +1310,7 @@
1291# Execute the program if it was not included from another file.1310# Execute the program if it was not included from another file.
1292# This makes it possible to include without executing, and thus test.1311# This makes it possible to include without executing, and thus test.
1293if [ "${0##*/}" = "$TOOL" ] \1312if [ "${0##*/}" = "$TOOL" ] \
1294 || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then1313 || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
12951314
1296 # Parse command line options. We must do this first so we can1315 # Parse command line options. We must do this first so we can
1297 # see if --daemonize was specified.1316 # see if --daemonize was specified.
@@ -1737,6 +1756,10 @@
1737Called after sleeping L<"--sleep"> seconds for the collector process to finish.1756Called after sleeping L<"--sleep"> seconds for the collector process to finish.
1738This hook is called after C<after_collect>.1757This hook is called after C<after_collect>.
17391758
1759=item after_interval_sleep
1760
1761Called after sleeping L<"--interval"> seconds after each trigger check.
1762
1740=item after_stalk1763=item after_stalk
17411764
1742Called after stalking. Since pt-stalk stalks forever by default,1765Called after stalking. Since pt-stalk stalks forever by default,
@@ -1840,6 +1863,22 @@
18401863
1841The variable to compare against the threshold. See L<"--function"> for details.1864The variable to compare against the threshold. See L<"--function"> for details.
18421865
1866=item --verbose
1867
1868type: int; default: 2
1869
1870Print more or less information while running. Since the tool is designed
1871to be a long-running daemon, the default verbosity level only prints the
1872most important information. If you run the tool interactively, you may
1873want to use a higher verbosity level.
1874
1875 LEVEL PRINTS
1876 ===== =====================================
1877 0 Errors
1878 1 Warnings
1879 2 Matching triggers and collection info
1880 3 Non-matching triggers
1881
1843=item --version1882=item --version
18441883
1845Print tool's version and exit.1884Print tool's version and exit.
18461885
=== modified file 'bin/pt-summary'
--- bin/pt-summary 2013-01-03 00:54:18 +0000
+++ bin/pt-summary 2013-01-24 19:10:25 +0000
@@ -29,23 +29,32 @@
29PTDEBUG="${PTDEBUG:-""}"29PTDEBUG="${PTDEBUG:-""}"
30EXIT_STATUS=030EXIT_STATUS=0
3131
32ts() {
33 TS=$(date +%F-%T | tr ':-' '_')
34 echo "$TS $*"
35}
36
37info() {
38 [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
39}
40
32log() {41log() {
33 TS=$(date +%F-%T | tr ':-' '_');42 [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
34 echo "$TS $*"
35}43}
3644
37warn() {45warn() {
38 log "$*" >&246 [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
39 EXIT_STATUS=147 EXIT_STATUS=1
40}48}
4149
42die() {50die() {
43 warn "$*"51 ts "$*" >&2
52 EXIT_STATUS=1
44 exit 153 exit 1
45}54}
4655
47_d () {56_d () {
48 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&257 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
49}58}
5059
51# ###########################################################################60# ###########################################################################
@@ -2280,7 +2289,7 @@
2280# Execute the program if it was not included from another file. This makes it2289# Execute the program if it was not included from another file. This makes it
2281# possible to include without executing, and thus test.2290# possible to include without executing, and thus test.
2282if [ "${0##*/}" = "$TOOL" ] \2291if [ "${0##*/}" = "$TOOL" ] \
2283 || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then2292 || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
22842293
2285 # Set up temporary dir.2294 # Set up temporary dir.
2286 mk_tmpdir2295 mk_tmpdir
22872296
=== modified file 'lib/PerconaTest.pm'
--- lib/PerconaTest.pm 2013-01-03 00:19:16 +0000
+++ lib/PerconaTest.pm 2013-01-24 19:10:25 +0000
@@ -58,7 +58,6 @@
58 wait_until58 wait_until
59 wait_for59 wait_for
60 wait_until_slave_running60 wait_until_slave_running
61 wait_until_no_lag
62 test_log_parser61 test_log_parser
63 test_protocol_parser62 test_protocol_parser
64 test_packet_parser63 test_packet_parser
@@ -325,6 +324,39 @@
325 );324 );
326};325};
327326
327sub kill_program {
328 my (%args) = @_;
329
330 my $pid_file = $args{pid_file};
331 my $pid = $args{pid};
332
333 if ( $pid_file ) {
334 chomp($pid = `cat $pid_file 2>/dev/null`);
335 }
336
337 if ( $pid ) {
338 PTDEVDEBUG && _d('Killing PID', $pid);
339 kill(15, $pid);
340 wait_until(
341 sub { my $is_alive = kill(0, $pid); return !$is_alive; },
342 1.5, # sleep between tries
343 15, # max time to try
344 );
345 if ( kill(0, $pid) ) {
346 warn "PID $pid did not die; using kill -9\n";
347 kill(9, $pid);
348 }
349 }
350 else {
351 PTDEVDEBUG && _d('No PID to kill');
352 }
353
354 if ( $pid_file && -f $pid_file ) {
355 PTDEVDEBUG && _d('Removing PID file', $pid_file);
356 unlink $pid_file;
357 }
358}
359
328sub not_running {360sub not_running {
329 my ($cmd) = @_;361 my ($cmd) = @_;
330 PTDEVDEBUG && _d('Wait until not running:', $cmd);362 PTDEVDEBUG && _d('Wait until not running:', $cmd);
331363
=== modified file 'lib/bash/log_warn_die.sh'
--- lib/bash/log_warn_die.sh 2012-08-13 15:23:18 +0000
+++ lib/bash/log_warn_die.sh 2013-01-24 19:10:25 +0000
@@ -28,23 +28,32 @@
28PTDEBUG="${PTDEBUG:-""}"28PTDEBUG="${PTDEBUG:-""}"
29EXIT_STATUS=029EXIT_STATUS=0
3030
31ts() {
32 TS=$(date +%F-%T | tr ':-' '_')
33 echo "$TS $*"
34}
35
36info() {
37 [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
38}
39
31log() {40log() {
32 TS=$(date +%F-%T | tr ':-' '_');41 [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
33 echo "$TS $*"
34}42}
3543
36warn() {44warn() {
37 log "$*" >&245 [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
38 EXIT_STATUS=146 EXIT_STATUS=1
39}47}
4048
41die() {49die() {
42 warn "$*"50 ts "$*" >&2
51 EXIT_STATUS=1
43 exit 152 exit 1
44}53}
4554
46_d () {55_d () {
47 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&256 [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
48}57}
4958
50# ###########################################################################59# ###########################################################################
5160
=== modified file 't/lib/bash/log_warn_die.sh'
--- t/lib/bash/log_warn_die.sh 2012-06-11 20:51:43 +0000
+++ t/lib/bash/log_warn_die.sh 2013-01-24 19:10:25 +0000
@@ -1,17 +1,15 @@
1#!/usr/bin/env bash1#!/usr/bin/env bash
22
3plan 6
4
5source "$LIB_DIR/log_warn_die.sh"3source "$LIB_DIR/log_warn_die.sh"
64
7log "Hello world!" > $TEST_PT_TMPDIR/log5log "Hello world A!" > $TEST_PT_TMPDIR/log
8cmd_ok \6cmd_ok \
9 "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \7 "grep -q 'Hello world A!' $TEST_PT_TMPDIR/log" \
10 "log msg"8 "log msg"
119
12log "Hello" "world!" > $TEST_PT_TMPDIR/log10log "Hello" "world B!" > $TEST_PT_TMPDIR/log
13cmd_ok \11cmd_ok \
14 "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \12 "grep -q 'Hello world B!' $TEST_PT_TMPDIR/log" \
15 "log msg msg"13 "log msg msg"
1614
17is \15is \
@@ -19,14 +17,14 @@
19 "0" \17 "0" \
20 "Exit status 0"18 "Exit status 0"
2119
22warn "Hello world!" 2> $TEST_PT_TMPDIR/log20warn "Hello world C!" 2> $TEST_PT_TMPDIR/log
23cmd_ok \21cmd_ok \
24 "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \22 "grep -q 'Hello world C!' $TEST_PT_TMPDIR/log" \
25 "warn msg"23 "warn msg"
2624
27warn "Hello" "world!" 2> $TEST_PT_TMPDIR/log25warn "Hello" "world D!" 2> $TEST_PT_TMPDIR/log
28cmd_ok \26cmd_ok \
29 "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \27 "grep -q 'Hello world D!' $TEST_PT_TMPDIR/log" \
30 "warn msg msg"28 "warn msg msg"
3129
32is \30is \
@@ -34,6 +32,81 @@
34 "1" \32 "1" \
35 "Exit status 1"33 "Exit status 1"
3634
35OPT_VERBOSE=1
36
37info "Hello world 1!" > $TEST_PT_TMPDIR/log
38file_is_empty \
39 $TEST_PT_TMPDIR/log \
40 "verbose=1 info"
41
42log "Hello world 2!" > $TEST_PT_TMPDIR/log
43file_is_empty \
44 $TEST_PT_TMPDIR/log \
45 "verbose=1 log"
46
47warn "Hello world 3!" > $TEST_PT_TMPDIR/log 2>&1
48file_contains \
49 $TEST_PT_TMPDIR/log \
50 "Hello world 3!" \
51 "verbose=1 warn"
52
53OPT_VERBOSE=2
54
55info "Hello world 4!" > $TEST_PT_TMPDIR/log
56file_is_empty \
57 $TEST_PT_TMPDIR/log \
58 "verbose=2 info"
59
60log "Hello world 5!" > $TEST_PT_TMPDIR/log
61file_contains \
62 $TEST_PT_TMPDIR/log \
63 "Hello world 5!" \
64 "verbose=2 log"
65
66warn "Hello world 6!" > $TEST_PT_TMPDIR/log 2>&1
67file_contains \
68 $TEST_PT_TMPDIR/log \
69 "Hello world 6!" \
70 "verbose=2 warn"
71
72OPT_VERBOSE=3
73
74info "Hello world 7!" > $TEST_PT_TMPDIR/log
75file_contains \
76 $TEST_PT_TMPDIR/log \
77 "Hello world 7!" \
78 "verbose=3 info"
79
80log "Hello world 8!" > $TEST_PT_TMPDIR/log
81file_contains \
82 $TEST_PT_TMPDIR/log \
83 "Hello world 8!" \
84 "verbose=3 log"
85
86warn "Hello world 9!" > $TEST_PT_TMPDIR/log 2>&1
87file_contains \
88 $TEST_PT_TMPDIR/log \
89 "Hello world 9!" \
90 "verbose=3 warn"
91
92OPT_VERBOSE=0
93
94info "Hello world 10!" > $TEST_PT_TMPDIR/log
95file_is_empty \
96 $TEST_PT_TMPDIR/log \
97 "verbose=0 info"
98
99log "Hello world 11!" > $TEST_PT_TMPDIR/log
100file_is_empty \
101 $TEST_PT_TMPDIR/log \
102 "verbose=0 log"
103
104warn "Hello world 12!" > $TEST_PT_TMPDIR/log 2>&1
105file_is_empty \
106 $TEST_PT_TMPDIR/log \
107 "verbose=0 warn"
108
37# ###########################################################################109# ###########################################################################
38# Done110# Done
39# ###########################################################################111# ###########################################################################
112done_testing
40113
=== added file 't/pt-stalk/option_sanity.t'
--- t/pt-stalk/option_sanity.t 1970-01-01 00:00:00 +0000
+++ t/pt-stalk/option_sanity.t 2013-01-24 19:10:25 +0000
@@ -0,0 +1,24 @@
1#!/usr/bin/env perl
2
3BEGIN {
4 die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5 unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6 unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
7};
8
9use strict;
10use warnings FATAL => 'all';
11use English qw(-no_match_vars);
12use Test::More;
13
14use PerconaTest;
15
16my $output = `$trunk/bin/pt-stalk --help`;
17
18like(
19 $output,
20 qr/^\s+--verbose\s+2/m,
21 "Default --verbose=2"
22);
23
24done_testing;
025
=== modified file 't/pt-stalk/pt-stalk.t'
--- t/pt-stalk/pt-stalk.t 2012-10-23 23:51:59 +0000
+++ t/pt-stalk/pt-stalk.t 2013-01-24 19:10:25 +0000
@@ -28,11 +28,28 @@
28my $pid_file = "/tmp/pt-stalk.pid.$PID";28my $pid_file = "/tmp/pt-stalk.pid.$PID";
29my $log_file = "/tmp/pt-stalk.log.$PID";29my $log_file = "/tmp/pt-stalk.log.$PID";
30my $dest = "/tmp/pt-stalk.collect.$PID";30my $dest = "/tmp/pt-stalk.collect.$PID";
31my $int_file = "/tmp/pt-stalk-after-interval-sleep";
31my $pid;32my $pid;
3233
33diag(`rm $pid_file 2>/dev/null`);34sub cleanup {
34diag(`rm $log_file 2>/dev/null`);35 diag(`rm $pid_file $log_file $int_file 2>/dev/null`);
35diag(`rm -rf $dest 2>/dev/null`);36 diag(`rm -rf $dest 2>/dev/null`);
37}
38
39sub wait_n_cycles {
40 my ($n) = @_;
41 PerconaTest::wait_until(
42 sub {
43 return 0 unless -f "$dest/after_interval_sleep";
44 my $n_cycles = `wc -l "$dest/after_interval_sleep" | awk '{print \$1}'`;
45 $n_cycles ||= '';
46 chomp($n_cycles);
47 return ($n_cycles || 0) >= $n;
48 },
49 1.5,
50 15
51 );
52}
3653
37# ###########################################################################54# ###########################################################################
38# Test that it won't run if can't connect to MySQL.55# Test that it won't run if can't connect to MySQL.
@@ -56,11 +73,14 @@
56# ###########################################################################73# ###########################################################################
57# Test that it runs and dies normally.74# Test that it runs and dies normally.
58# ###########################################################################75# ###########################################################################
59diag(`rm $pid_file 2>/dev/null`);76
60diag(`rm $log_file 2>/dev/null`);77cleanup();
61diag(`rm -rf $dest 2>/dev/null`);78
6279# As of v2.1.9 when --verbose was added, non-matching checks are not
63$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest -- --defaults-file=$cnf");80# printed by default. So we use the --plugin to tell us when the tool
81# has completed a cycle.
82
83$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");
6484
65is(85is(
66 $retval >> 8,86 $retval >> 8,
@@ -94,21 +114,16 @@
94 "pt-stalk is running"114 "pt-stalk is running"
95);115);
96116
97PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null");117wait_n_cycles(2);
118PerconaTest::kill_program(pid_file => $pid_file);
119
98$output = `cat $log_file 2>/dev/null`;120$output = `cat $log_file 2>/dev/null`;
99like(121unlike(
100 $output,122 $output,
101 qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/,123 qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/,
102 "Check results logged"124 "Non-matching results not logged because --verbose=2"
103) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);125) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
104126
105$retval = system("kill $pid 2>/dev/null");
106is(
107 $retval >> 0,
108 0,
109 "Killed pt-stalk"
110);
111
112PerconaTest::wait_until(sub { !-f $pid_file });127PerconaTest::wait_until(sub { !-f $pid_file });
113128
114ok(129ok(
@@ -123,12 +138,56 @@
123 "Caught signal logged"138 "Caught signal logged"
124) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);139) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
125140
141# #############################################################################
142# --verbose 3 (non-matching results)
143# #############################################################################
144
145cleanup();
146
147$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 3 -- --defaults-file=$cnf");
148
149PerconaTest::wait_for_files($pid_file, $log_file);
150PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null");
151PerconaTest::kill_program(pid_file => $pid_file);
152
153$output = `cat $log_file 2>/dev/null`;
154like(
155 $output,
156 qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/,
157 "Matching results logged with --verbose 3"
158) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
159
160# #############################################################################
161# --verbose 1 (just errors and warnings)
162# #############################################################################
163
164cleanup();
165
166$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 1 --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");
167
168PerconaTest::wait_for_files($pid_file, $log_file);
169wait_n_cycles(2);
170PerconaTest::kill_program(pid_file => $pid_file);
171
172$output = `cat $log_file 2>/dev/null`;
173
174like(
175 $output,
176 qr/Caught signal, exiting/,
177 "Warning logged (--verbose 1)"
178);
179
180unlike(
181 $output,
182 qr/Start|Collect|Check/i,
183 "No run info log (--verbose 1)"
184);
185
126# ###########################################################################186# ###########################################################################
127# Test collect.187# Test collect.
128# ###########################################################################188# ###########################################################################
129diag(`rm $pid_file 2>/dev/null`);189
130diag(`rm $log_file 2>/dev/null`);190cleanup();
131diag(`rm $dest/* 2>/dev/null`);
132191
133# We'll have to watch Uptime since it's the only status var that's going192# We'll have to watch Uptime since it's the only status var that's going
134# to be predictable.193# to be predictable.
@@ -180,10 +239,10 @@
180 "Trigger file logs how pt-stalk was ran"239 "Trigger file logs how pt-stalk was ran"
181);240);
182241
183chomp($output = `cat $log_file 2>/dev/null | grep 'Collector PID'`);242chomp($output = `cat $log_file 2>/dev/null | grep 'Collect [0-9] PID'`);
184like(243like(
185 $output,244 $output,
186 qr/Collector PID \d+/,245 qr/Collect 1 PID \d+/,
187 "Collector PID logged"246 "Collector PID logged"
188)247)
189or diag(248or diag(
@@ -195,9 +254,8 @@
195# ###########################################################################254# ###########################################################################
196# Triggered but --no-collect.255# Triggered but --no-collect.
197# ###########################################################################256# ###########################################################################
198diag(`rm $pid_file 2>/dev/null`);257
199diag(`rm $log_file 2>/dev/null`);258cleanup();
200diag(`rm $dest/* 2>/dev/null`);
201259
202(undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");260(undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
203$threshold = $uptime + 2;261$threshold = $uptime + 2;
@@ -209,7 +267,7 @@
209$output = `cat $log_file 2>/dev/null`;267$output = `cat $log_file 2>/dev/null`;
210like(268like(
211 $output,269 $output,
212 qr/Collect triggered/,270 qr/Collect 1 triggered/,
213 "Collect triggered"271 "Collect triggered"
214);272);
215273
@@ -227,6 +285,8 @@
227# --config285# --config
228# #############################################################################286# #############################################################################
229287
288cleanup();
289
230diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`);290diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`);
231diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`);291diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`);
232292
@@ -254,9 +314,8 @@
254# #############################################################################314# #############################################################################
255# Don't stalk, just collect.315# Don't stalk, just collect.
256# #############################################################################316# #############################################################################
257diag(`rm $pid_file 2>/dev/null`);317
258diag(`rm $log_file 2>/dev/null`);318cleanup();
259diag(`rm $dest/* 2>/dev/null`);
260319
261$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");320$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
262321
@@ -343,9 +402,7 @@
343# #############################################################################402# #############################################################################
344# Done.403# Done.
345# #############################################################################404# #############################################################################
346diag(`rm $pid_file 2>/dev/null`);405cleanup();
347diag(`rm $log_file 2>/dev/null`);
348diag(`rm -rf $dest 2>/dev/null`);406diag(`rm -rf $dest 2>/dev/null`);
349ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");407ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
350
351done_testing;408done_testing;
352409
=== added file 't/pt-stalk/samples/plugin002.sh'
--- t/pt-stalk/samples/plugin002.sh 1970-01-01 00:00:00 +0000
+++ t/pt-stalk/samples/plugin002.sh 2013-01-24 19:10:25 +0000
@@ -0,0 +1,5 @@
1#!/bin/sh
2
3after_interval_sleep() {
4 date >> "$OPT_DEST/after_interval_sleep"
5}
06
=== modified file 'util/test-bash-functions'
--- util/test-bash-functions 2012-08-22 20:50:11 +0000
+++ util/test-bash-functions 2013-01-24 19:10:25 +0000
@@ -100,6 +100,7 @@
100result() {100result() {
101 local result=$1101 local result=$1
102 local test_name=${2:-""}102 local test_name=${2:-""}
103 testno=$((testno + 1))
103 if [ $result -eq 0 ]; then104 if [ $result -eq 0 ]; then
104 echo "ok $testno - $TEST_FILE $test_name"105 echo "ok $testno - $TEST_FILE $test_name"
105 else106 else
@@ -110,7 +111,6 @@
110 cat $TEST_PT_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2111 cat $TEST_PT_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2
111 fi112 fi
112 fi113 fi
113 testno=$((testno + 1))
114 return $result114 return $result
115}115}
116116
@@ -121,19 +121,21 @@
121 fi121 fi
122}122}
123123
124done_testing() {
125 echo "1..$testno"
126}
127
124#128#
125# The following subs are for the test files to call.129# The following subs are for the test files to call.
126#130#
127131
128pass() {132pass() {
129 local reason="${1:-""}"133 local reason="${1:-""}"
130
131 result 0 "$reason"134 result 0 "$reason"
132}135}
133136
134fail() {137fail() {
135 local reason="${1:-""}"138 local reason="${1:-""}"
136
137 result 1 "$reason"139 result 1 "$reason"
138}140}
139141
@@ -177,6 +179,42 @@
177 result $? "$test_name"179 result $? "$test_name"
178}180}
179181
182file_is_empty() {
183 local file=$1
184 local test_name=${2:-""}
185 test_command="-s $file"
186 if [ ! -f "$file" ]; then
187 echo "$file does not exist" > $TEST_PT_TMPDIR/failed_result
188 result 1 "$test_name"
189 fi
190 if [ -s "$file" ]; then
191 echo "$file is not empty:" > $TEST_PT_TMPDIR/failed_result
192 cat "$file" >> $TEST_PT_TMPDIR/failed_result
193 result 1 "$test_name"
194 else
195 result 0 "$test_name"
196 fi
197}
198
199file_contains() {
200 local file="$1"
201 local pat="$2"
202 local test_name=${3:-""}
203 test_command="grep -q '$pat' '$file'"
204 if [ ! -f "$file" ]; then
205 echo "$file does not exist" > $TEST_PT_TMPDIR/failed_result
206 result 1 "$test_name"
207 fi
208 grep -q "$pat" $file
209 if [ $? -ne 0 ]; then
210 echo "$file does not contain '$pat':" > $TEST_PT_TMPDIR/failed_result
211 cat "$file" >> $TEST_PT_TMPDIR/failed_result
212 result 1 "$test_name"
213 else
214 result 0 "$test_name"
215 fi
216}
217
180cmd_ok() {218cmd_ok() {
181 local test_command=$1219 local test_command=$1
182 local test_name=${2:-""}220 local test_name=${2:-""}
@@ -226,7 +264,7 @@
226# Script starts here264# Script starts here
227# ############################################################################265# ############################################################################
228266
229testno=1267testno=0
230failed_tests=0268failed_tests=0
231269
232if [ $# -eq 0 ]; then270if [ $# -eq 0 ]; then

Subscribers

People subscribed via source and target branches