Merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-fails-when-variable-or-threshold-is-non-integer-1335322 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.9

Proposed by Frank Cizmich
Status: Merged
Merged at revision: 610
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-fails-when-variable-or-threshold-is-non-integer-1335322
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.9
Diff against target: 60 lines (+27/-2)
3 files modified
bin/pt-stalk (+1/-2)
t/pt-stalk/pt-stalk.t (+21/-0)
t/pt-stalk/samples/plugin003.sh (+5/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-fails-when-variable-or-threshold-is-non-integer-1335322
Reviewer Review Type Date Requested Status
Percona Toolkit developers Pending
Review via email: mp+224900@code.launchpad.net

Description of the change

solves pt-stalk not handling non-integers

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-stalk'
2--- bin/pt-stalk 2014-06-05 07:24:48 +0000
3+++ bin/pt-stalk 2014-06-27 20:57:34 +0000
4@@ -1245,13 +1245,12 @@
5 if [ "$OPT_STALK" ]; then
6 local value=$($TRIGGER_FUNCTION $OPT_VARIABLE)
7 local trg_exit_status=$?
8-
9 if [ -z "$value" ]; then
10 # No value. Maybe we failed to connect to MySQL?
11 warn "Detected value is empty; something failed? Trigger exit status: $trg_exit_status"
12 matched=""
13 cycles_true=0
14- elif [ $value -gt $OPT_THRESHOLD ]; then
15+ elif (( $(echo "$value $OPT_THRESHOLD" | awk '{print ($1 > $2)}') )); then
16 matched="yes"
17 cycles_true=$(($cycles_true + 1))
18 else
19
20=== modified file 't/pt-stalk/pt-stalk.t'
21--- t/pt-stalk/pt-stalk.t 2013-08-13 03:45:38 +0000
22+++ t/pt-stalk/pt-stalk.t 2014-06-27 20:57:34 +0000
23@@ -402,6 +402,27 @@
24 "Bug 942114: no bad find usage"
25 );
26
27+
28+# ###########################################################################
29+# Test that it handles floating point values
30+# ###########################################################################
31+
32+cleanup();
33+
34+system("$trunk/bin/pt-stalk --daemonize --variable=PI --dest $dest --no-collect --log $log_file --iterations=1 --run-time=2 --cycles=2 --sleep=1 --function $trunk/t/pt-stalk/samples/plugin003.sh --threshold 3.1415 --pid $pid_file --defaults-file=$cnf >$log_file 2>&1");
35+
36+
37+sleep 5;
38+PerconaTest::kill_program(pid_file => $pid_file);
39+
40+$output = `cat $log_file 2>/dev/null`;
41+like(
42+ $output,
43+ qr/matched=yes/,
44+ "Accepts floating point values as treshold variable"
45+);
46+
47+
48 # #############################################################################
49 # Done.
50 # #############################################################################
51
52=== added file 't/pt-stalk/samples/plugin003.sh'
53--- t/pt-stalk/samples/plugin003.sh 1970-01-01 00:00:00 +0000
54+++ t/pt-stalk/samples/plugin003.sh 2014-06-27 20:57:34 +0000
55@@ -0,0 +1,5 @@
56+#!/bin/sh
57+
58+trg_plugin() {
59+ echo 3.1416
60+}

Subscribers

People subscribed via source and target branches

to all changes: