ci(core): Retry sending data over TCP in case of error

The first attempt occasionally fails, probably due to a race with the
listener's startup.

Additionally, perform minor adjustments to the output written to stderr
to ensure it is properly flushed in the CI environment.
This commit is contained in:
Antoine Cotten
2021-10-28 16:41:49 +02:00
parent c3cc7ae15c
commit 9fde1ac351
4 changed files with 56 additions and 12 deletions

View File

@@ -37,15 +37,31 @@ log 'Searching index pattern via Kibana API'
response="$(curl "http://${ip_kb}:5601/api/saved_objects/_find?type=index-pattern" -s -u elastic:testpasswd)"
echo "$response"
count="$(jq -rn --argjson data "${response}" '$data.total')"
if [[ $count -ne 1 ]]; then
if (( count != 1 )); then
echo "Expected 1 index pattern, got ${count}"
exit 1
fi
log 'Sending message to Logstash TCP input'
echo 'dockerelk' | nc -q0 "$ip_ls" 5000
sleep 1
declare -i was_retried=0
# retry for max 10s (5*2s)
for _ in $(seq 1 5); do
if echo 'dockerelk' | nc -q0 "$ip_ls" 5000; then
break
fi
was_retried=1
echo -n 'x' >&2
sleep 2
done
if ((was_retried)); then
# flush stderr, important in non-interactive environments (CI)
echo >&2
fi
sleep 3
curl -X POST "http://${ip_es}:9200/_refresh" -u elastic:testpasswd \
-s -w '\n'
@@ -53,7 +69,7 @@ log 'Searching message in Elasticsearch'
response="$(curl "http://${ip_es}:9200/logstash-*/_count?q=message:dockerelk&pretty" -s -u elastic:testpasswd)"
echo "$response"
count="$(jq -rn --argjson data "${response}" '$data.count')"
if [[ $count -ne 1 ]]; then
if (( count != 1 )); then
echo "Expected 1 document, got ${count}"
exit 1
fi