From f7f0313090c2495006f9650cc6968e7e35d64723 Mon Sep 17 00:00:00 2001 From: lufia Date: Thu, 15 Dec 2022 13:34:33 +0900 Subject: [PATCH 1/2] [plugin-elasticsearch] wait until running the instance --- mackerel-plugin-elasticsearch/test.sh | 4 ++- tool/waituntil.bash | 35 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 tool/waituntil.bash diff --git a/mackerel-plugin-elasticsearch/test.sh b/mackerel-plugin-elasticsearch/test.sh index 3957fc1dd..caab75d46 100755 --- a/mackerel-plugin-elasticsearch/test.sh +++ b/mackerel-plugin-elasticsearch/test.sh @@ -29,8 +29,10 @@ trap 'docker stop test-$plugin; docker rm test-$plugin; exit' EXIT sleep 60 # to store previous value to calculate a diff of metrics -$plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error >/dev/null 2>&1 +../tool/waituntil.bash -n 300 $plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error >/dev/null 2>&1 + sleep 1 + $plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error | graphite-metric-test -f rule.txt status=$? diff --git a/tool/waituntil.bash b/tool/waituntil.bash new file mode 100755 index 000000000..0b3f3ad57 --- /dev/null +++ b/tool/waituntil.bash @@ -0,0 +1,35 @@ +#!/bin/bash +# usage: waituntil [-n count] command [arg ...] + +usage() +{ + echo "usage: $(basename $0) [-n count] command [arg ...]" >&2 + exit 2 +} + +count=0 # unlimited +while getopts :n: OPT +do + case "$OPT" in + :) usage ;; + n) count="$OPTARG" ;; + \?) usage ;; + esac +done +shift $((OPTIND - 1)) +if (($# == 0)) +then + usage +fi + +i=0 +while (($count == 0 || $i < $count)) +do + if command "$@" + then + exit 0 + fi + sleep 1 + ((i++)) +done +exit 1 From 902904fd7187d716b0c059177097b0c87b95b192 Mon Sep 17 00:00:00 2001 From: lufia Date: Thu, 15 Dec 2022 13:39:10 +0900 Subject: [PATCH 2/2] [plugin-elasticsearch] fix No such container error --- mackerel-plugin-elasticsearch/test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mackerel-plugin-elasticsearch/test.sh b/mackerel-plugin-elasticsearch/test.sh index caab75d46..1c00ea85f 100755 --- a/mackerel-plugin-elasticsearch/test.sh +++ b/mackerel-plugin-elasticsearch/test.sh @@ -25,8 +25,7 @@ docker run -d \ -e "discovery.type=single-node" \ -e "ingest.geoip.downloader.enabled=false" \ elasticsearch:8.5.0 -trap 'docker stop test-$plugin; docker rm test-$plugin; exit' EXIT -sleep 60 +trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15 # to store previous value to calculate a diff of metrics ../tool/waituntil.bash -n 300 $plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error >/dev/null 2>&1