fixes pt-stalk not being to handle non-integers - issue 1335322

This commit is contained in:
Frank Cizmich
2014-06-27 17:49:50 -03:00
parent 885cdce7bf
commit c149dbf5ff
3 changed files with 27 additions and 2 deletions

View File

@@ -1245,13 +1245,12 @@ stalk() {
if [ "$OPT_STALK" ]; then
local value=$($TRIGGER_FUNCTION $OPT_VARIABLE)
local trg_exit_status=$?
if [ -z "$value" ]; then
# No value. Maybe we failed to connect to MySQL?
warn "Detected value is empty; something failed? Trigger exit status: $trg_exit_status"
matched=""
cycles_true=0
elif [ $value -gt $OPT_THRESHOLD ]; then
elif (( $(echo "$value $OPT_THRESHOLD" | awk '{print ($1 > $2)}') )); then
matched="yes"
cycles_true=$(($cycles_true + 1))
else

View File

@@ -402,6 +402,27 @@ unlike(
"Bug 942114: no bad find usage"
);
# ###########################################################################
# Test that it handles floating point values
# ###########################################################################
cleanup();
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");
sleep 5;
PerconaTest::kill_program(pid_file => $pid_file);
$output = `cat $log_file 2>/dev/null`;
like(
$output,
qr/matched=yes/,
"Accepts floating point values as treshold variable"
);
# #############################################################################
# Done.
# #############################################################################

View File

@@ -0,0 +1,5 @@
#!/bin/sh
trg_plugin() {
echo 3.1416
}