Skip to content

Commit

Permalink
chore: fix test/integration.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
  • Loading branch information
simonpasquier committed Feb 14, 2024
1 parent 323b9e3 commit ec14ab3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,14 @@ test-format:
make --always-make format && git diff --exit-code

test-integration: build | $(THANOS_BIN) $(UP_BIN) $(MEMCACHED_BIN) $(PROMETHEUS_BIN)
@echo "Running integration tests: V1"
PATH=$$PATH:$$(pwd)/$(BIN_DIR) ./test/integration.sh
@echo "Running integration tests: V2"
@echo "================================="
@echo ">>> Running integration tests: V1"
@echo "================================="
PATH=$$PATH:$$(pwd)/$(BIN_DIR) ./test/integration.sh 2>&1
@echo
@echo "================================="
@echo ">>> Running integration tests: V2"
@echo "================================="
PATH=$$PATH:$$(pwd)/$(BIN_DIR) LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$$(pwd)/$(LIB_DIR) ./test/integration-v2.sh

test-benchmark: build $(GOJSONTOYAML_BIN)
Expand Down
39 changes: 21 additions & 18 deletions test/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ trap 'kill $(jobs -p); exit $result' EXIT

( ./authorization-server localhost:9001 ./test/tokens.json ) &

( prometheus --config.file=./test/prom-local.conf --web.listen-address=localhost:9090 "--storage.tsdb.path=$(mktemp -d)" --log.level=warn ) &
( prometheus --config.file=./test/prom-local.yaml --web.listen-address=localhost:9090 "--storage.tsdb.path=$(mktemp -d)" --log.level=warn ) &

(
(
sleep 5
exec ./telemeter-client \
--from "http://localhost:9090" \
Expand All @@ -26,7 +26,7 @@ trap 'kill $(jobs -p); exit $result' EXIT
--match '{__name__="scrape_samples_scraped"}'
) &

(
(
./telemeter-server \
--ratelimit=15s \
--authorize http://localhost:9001 \
Expand All @@ -53,44 +53,47 @@ thanos query \
--store=127.0.0.1:9006
) &

sleep 1

retries=100
retries=1
while true; do
if [[ "${retries}" -lt 0 ]]; then
echo "error: Did not successfully retrieve cluster metrics from the local Prometheus server" 1>&2
echo "info: attempt #${retries} $(date +%H:%M:%S)"
sleep 1

if [[ "${retries}" -gt 100 ]]; then
echo "error: Did not successfully retrieve cluster metrics from the local Prometheus server"
exit 1
fi

# verify we scrape metrics from the test cluster and give it _id test
if [[ "$( curl http://localhost:9008/api/v1/query --data-urlencode 'query=count({_id="test"})' -G 2>/dev/null | python3 -c 'import sys, json; print(json.load(sys.stdin)["data"]["result"][0]["value"][1])' 2>/dev/null )" -eq 0 ]]; then
retries=$((retries-1))
sleep 1
retries=$((retries+1))
continue
fi

# verify we rename scrape_samples_scraped to scraped
if [[ "$( curl http://localhost:9008/api/v1/query --data-urlencode 'query=count(scraped{_id="test"})' -G 2>/dev/null | python3 -c 'import sys, json; print(json.load(sys.stdin)["data"]["result"][0]["value"][1])' 2>/dev/null )" -eq 0 ]]; then
retries=$((retries-1))
sleep 1
retries=$((retries+1))
continue
fi

# verify we got alerts as remapped from ALERTS
if [[ "$( curl http://localhost:9008/api/v1/query --data-urlencode 'query=count(alerts{_id="test"})' -G 2>/dev/null | python3 -c 'import sys, json; print(json.load(sys.stdin)["data"]["result"][0]["value"][1])' 2>/dev/null )" -eq 0 ]]; then
retries=$((retries-1))
sleep 1
retries=$((retries+1))
continue
fi

# verify we don't get elided labels
if [[ "$( curl http://localhost:9008/api/v1/query --data-urlencode 'query=count(alerts{_id="test",_elide=~".+"})' -G 2>/dev/null | python3 -c 'import sys, json; print(len(json.load(sys.stdin)["data"]["result"]))' 2>/dev/null )" -gt 0 ]]; then
retries=$((retries-1))
sleep 1
retries=$((retries+1))
continue
fi

break
done
echo "tests: ok"

echo "info: tests ok"
result=0
exit 0

echo "tests: failed" 1>&2
echo "error: tests failed" 1>&2
result=1
exit 1
3 changes: 2 additions & 1 deletion test/prom-local-alerts.conf → test/prom-local-alerts.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
groups:
- name: basic
interval: 1s
rules:
- alert: DeadMansSwitch
expr: vector(1)
labels:
severity: none
severity: none
4 changes: 2 additions & 2 deletions test/prom-local.conf → test/prom-local.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
rule_files:
- prom-local-alerts.conf
- prom-local-alerts.yaml

scrape_configs:
- job_name: 'telemeter-server'
scrape_interval: 30s
scrape_interval: 5s

metrics_path: '/metrics'

Expand Down

0 comments on commit ec14ab3

Please sign in to comment.