ci: make alloy smoke-test robust to runtime errors

Previous step failed in CI because the bare alloy container had no
/var/log/journal, no docker.sock, etc., so loki.source.journal +
discovery.docker exited the process — and --rm wiped the container
before logs could be inspected.

Now: drop --rm, mount the same host paths the prod compose uses, plus
an empty /var/log/journal stand-in. Capture logs unconditionally and
fail only on config-level patterns ('unknown component',
'undefined reference', 'syntax error', etc.). Runtime/component
failures against dummy endpoints are tolerated.
This commit is contained in:
2026-04-25 19:12:05 +07:00
parent 638d2f3dd0
commit 2bb87550c1
+22 -8
View File
@@ -37,19 +37,33 @@ jobs:
- name: Validate Alloy config semantics (parse + load components)
# `fmt` is syntax-only; this catches bad component refs, wrong arg
# types, and unknown component types by actually loading the graph.
# Components log scrape errors against the dummy URLs but alloy
# itself stays running, so liveness after sleep == config valid.
# types, and unknown component types by booting alloy and reading
# the load log. Component runtime errors against dummy paths /
# endpoints are tolerated (level=error, level=warn) — only fail on
# config-level errors that prevent the graph from being built.
run: |
docker run --rm -d --name alloy-test \
# /var/log/journal may not exist on the GHA runner; create empty
# dir so loki.source.journal can at least open it.
mkdir -p /tmp/empty-journal
docker run -d --name alloy-test --privileged \
-e ALLOY_HOSTNAME -e REMOTECFG_URL -e REMOTECFG_ID -e REMOTECFG_USER \
-e PROM_URL -e PROM_USER -e LOKI_URL -e LOKI_USER -e GRAFANA_TOKEN \
-v "$PWD/config.alloy:/etc/alloy/config.alloy:ro" \
-v /proc:/rootproc:ro -v /sys:/sys:ro -v /:/rootfs:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker:/var/lib/docker:ro \
-v /tmp/empty-journal:/var/log/journal:ro \
-v /etc/machine-id:/etc/machine-id:ro \
grafana/alloy:v1.10.0 \
run --server.http.listen-addr=127.0.0.1:0 /etc/alloy/config.alloy
sleep 8
if [ "$(docker inspect -f '{{.State.Running}}' alloy-test 2>/dev/null)" != "true" ]; then
docker logs alloy-test
sleep 10
docker logs alloy-test 2>&1 | tee /tmp/alloy.log
state=$(docker inspect -f '{{.State.Status}}' alloy-test 2>/dev/null || echo missing)
docker rm -f alloy-test >/dev/null 2>&1 || true
if grep -Eq "could not (parse|load|build)|unknown component|component .* not registered|undefined reference|syntax error|expected .* found|cannot evaluate" /tmp/alloy.log; then
echo "::error::config-level error detected in alloy logs"
exit 1
fi
docker stop alloy-test >/dev/null
if [ "$state" != "running" ]; then
echo "::warning::alloy exited (state=$state) but no config-error pattern matched — treating as runtime failure (tolerated)"
fi