Skip to content

Commit 2c7e20a

Browse files
committed
ci: fail payload aggregation loudly when total is zero
Parsing (TRX regex or the agent-log regex in AgentLogFile) breaking would otherwise yield a valid-but-empty result and silently report zeros to New Relic with a green build. Add build/Scripts/check-payload-not-empty.sh (with tests) and a non-continue-on-error guard step before the report step that fails the aggregation job when the consolidated total is <= 0.
1 parent 1ee4ffb commit 2c7e20a

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/all_solutions.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,11 @@ jobs:
13521352
path: final_payload_summary.json
13531353
if-no-files-found: warn
13541354

1355+
- name: Guard against empty payload data
1356+
if: inputs.aggregate_payload_data == true || github.event_name == 'schedule'
1357+
run: bash build/Scripts/check-payload-not-empty.sh final_payload_summary.json
1358+
shell: bash
1359+
13551360
- name: Report payload metrics to New Relic (staging)
13561361
if: inputs.aggregate_payload_data == true || github.event_name == 'schedule'
13571362
continue-on-error: true
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Guard: fail loudly if the consolidated payload summary reports (near-)zero total bytes.
3+
#
4+
# When payload aggregation runs, the test suites always send a large amount of
5+
# data (every test app at least does a connect handshake), so an overall total
6+
# of zero is never legitimate - it means the TRX / agent-log parsing broke
7+
# (e.g. a log-line format change) somewhere upstream. Without this guard the
8+
# pipeline would silently report zeros to New Relic and the dashboard would
9+
# flatline with no failure. This step turns that silent failure into a loud one.
10+
#
11+
# Usage:
12+
# check-payload-not-empty.sh [SUMMARY_FILE]
13+
# SUMMARY_FILE path to final_payload_summary.json
14+
# (arg 1, or PAYLOAD_SUMMARY_FILE env var)
15+
# MIN_EXPECTED_PAYLOAD_BYTES floor; fail if total <= this (default 0).
16+
# Raise it later to catch partial breakage too.
17+
#
18+
# Exit codes:
19+
# 0 total is above the floor
20+
# 1 summary file missing/unparseable, or total <= floor
21+
set -euo pipefail
22+
23+
SUMMARY_FILE="${1:-${PAYLOAD_SUMMARY_FILE:-}}"
24+
FLOOR="${MIN_EXPECTED_PAYLOAD_BYTES:-0}"
25+
26+
if [ -z "$SUMMARY_FILE" ] || [ ! -f "$SUMMARY_FILE" ]; then
27+
echo "ERROR: payload summary file not found (got '$SUMMARY_FILE')." >&2
28+
exit 1
29+
fi
30+
31+
total="$(jq -r '(.bytes // 0) | floor' "$SUMMARY_FILE" 2>/dev/null || true)"
32+
case "$total" in
33+
'' | *[!0-9]*)
34+
echo "ERROR: could not read a numeric total from '$SUMMARY_FILE' (got '$total')." >&2
35+
exit 1
36+
;;
37+
esac
38+
39+
echo "Overall payload bytes: $total (floor: $FLOOR)"
40+
if [ "$total" -le "$FLOOR" ]; then
41+
echo "ERROR: payload total ($total) is at or below the floor ($FLOOR)." >&2
42+
echo "This almost certainly means the TRX / agent-log parsing broke (e.g. a log-line" >&2
43+
echo "format change), not a real zero. Failing so it is investigated instead of" >&2
44+
echo "silently reporting zeros to New Relic." >&2
45+
exit 1
46+
fi
47+
48+
echo "Payload guard passed."
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Tests for check-payload-not-empty.sh: the guard must pass on a real total and
3+
# fail on zero / missing bytes / missing file / below-floor.
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
SCRIPT="$SCRIPT_DIR/../check-payload-not-empty.sh"
8+
tmp="$(mktemp -d)"
9+
trap 'rm -rf "$tmp"' EXIT
10+
11+
fail() { echo "FAIL: $1" >&2; exit 1; }
12+
13+
# Non-zero total -> pass (exit 0).
14+
echo '{"bytes": 69209939, "byType": {}}' > "$tmp/ok.json"
15+
bash "$SCRIPT" "$tmp/ok.json" >/dev/null 2>&1 || fail "expected pass on non-zero total"
16+
17+
# Zero total -> fail (exit 1).
18+
echo '{"bytes": 0, "byType": {}}' > "$tmp/zero.json"
19+
if bash "$SCRIPT" "$tmp/zero.json" >/dev/null 2>&1; then fail "expected failure on zero total"; fi
20+
21+
# Missing bytes field (treated as 0) -> fail.
22+
echo '{"byType": {}}' > "$tmp/missing.json"
23+
if bash "$SCRIPT" "$tmp/missing.json" >/dev/null 2>&1; then fail "expected failure on missing bytes field"; fi
24+
25+
# Missing file -> fail.
26+
if bash "$SCRIPT" "$tmp/does-not-exist.json" >/dev/null 2>&1; then fail "expected failure on missing file"; fi
27+
28+
# Below an explicit floor -> fail.
29+
echo '{"bytes": 500}' > "$tmp/low.json"
30+
if MIN_EXPECTED_PAYLOAD_BYTES=1000 bash "$SCRIPT" "$tmp/low.json" >/dev/null 2>&1; then fail "expected failure below floor"; fi
31+
32+
# Above an explicit floor -> pass.
33+
echo '{"bytes": 5000}' > "$tmp/high.json"
34+
MIN_EXPECTED_PAYLOAD_BYTES=1000 bash "$SCRIPT" "$tmp/high.json" >/dev/null 2>&1 || fail "expected pass above floor"
35+
36+
echo "PASS: all guard assertions passed"

0 commit comments

Comments
 (0)