feat(hub): expose occurred_at on recent-errors for CRM deploy verification

Add ISO-8601 occurred_at to each row returned by GET /api/error-monitoring/recent-errors
so operators can script post-deploy stability checks (BIT-1048).

Extend verify_pmx_bet_due_time_deploy.sh with a hub mode that queries open CRM
incidents matching ERRSIG 90a47beec0d7 and fails if the latest occurrence is
within HUB_DUE_TIME_STABILITY_SEC (default 7200). Skips with exit 0 when no
resolve key is present.

Document the field in HTTP_CONTRACTS, ERROR_MONITORING_PUBLIC_API, and
RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME §6.2.2.

Paperclip-Agent: 5d084b36-f38f-42a5-a92a-520005afda4f
Paperclip-Issue: BIT-1048
Paperclip-Run: 5138810f-9498-49a1-81eb-291fdeba8abc
This commit is contained in:
Peter Spark committed 2026-04-05 19:15:22 +00:00
1 parent 50282ab4dd
commit 410cd7e0aa
5 files changed
+100 -3

No files matched your search

+63 -2
View File
@@ -1,10 +1,11 @@
#!/usr/bin/env bash
# Gitea + runtime checks for CRM `due_time` normalization on crm.pmx.bet.
# Gitea + runtime + hub checks for CRM `due_time` normalization on crm.pmx.bet.
# See docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md §6 (BIT-1048 / BIT-1049 / BIT-887).
#
# Usage:
# ./scripts/crm/verify_pmx_bet_due_time_deploy.sh gitea
# [email protected] ./scripts/crm/verify_pmx_bet_due_time_deploy.sh runtime
# ERROR_RESOLVE_API_KEY=… ./scripts/crm/verify_pmx_bet_due_time_deploy.sh hub
set -euo pipefail
readonly CRM_REPO_URL="${CRM_REPO_URL:-https://git.bitreport.pt/BitReport.pt/CRM_Project.git}"
@@ -43,11 +44,71 @@ cmd_runtime() {
"set -euo pipefail; cd '${RUNTIME_GIT_DIR}' && git fetch -q origin && git rev-parse HEAD && git merge-base --is-ancestor ${SHA_E0} HEAD && git merge-base --is-ancestor ${SHA_30} HEAD && echo ancestors_ok"
}
cmd_hub() {
command -v curl >/dev/null 2>&1 || {
echo "verify_pmx_bet_due_time_deploy: hub: curl is required" >&2
exit 1
}
command -v jq >/dev/null 2>&1 || {
echo "verify_pmx_bet_due_time_deploy: hub: jq is required" >&2
exit 1
}
local api_key base resp data_count latest_ts latest_epoch now threshold
api_key="${ERROR_RESOLVE_API_KEY:-${ERROR_REPORTING_API_KEY:-}}"
base="${ER_API_BASE:-https://errors.bitreport.pt}"
readonly window_sec="${HUB_DUE_TIME_STABILITY_SEC:-7200}"
readonly hub_q="${HUB_DUE_TIME_HUB_QUERY:-90a47beec0d7}"
if [[ -z "${api_key}" ]]; then
echo "verify_pmx_bet_due_time_deploy: hub: ERROR_RESOLVE_API_KEY (or ERROR_REPORTING_API_KEY) not set — skipping recency check" >&2
exit 0
fi
resp="$(curl -sfG "${base}/api/error-monitoring/recent-errors" \
--data-urlencode "api_key=${api_key}" \
--data-urlencode "status=open,investigating" \
--data-urlencode "limit=500" \
--data-urlencode "project_slug=crm" \
--data-urlencode "q=${hub_q}" \
--max-time 30)" || {
echo "verify_pmx_bet_due_time_deploy: hub: recent-errors request failed" >&2
exit 1
}
data_count="$(echo "${resp}" | jq '.data | length')"
echo "verify_pmx_bet_due_time_deploy: hub: open/investigating rows (project=crm, q=${hub_q}): ${data_count}"
if [[ "${data_count}" -eq 0 ]]; then
echo "verify_pmx_bet_due_time_deploy: hub: OK — no matching open incidents"
return 0
fi
latest_ts="$(echo "${resp}" | jq -r '[.data[].occurred_at | select(. != null and . != "")] | max // empty')"
if [[ -z "${latest_ts}" ]]; then
echo "verify_pmx_bet_due_time_deploy: hub: warning: rows lack occurred_at (deploy hub API with recent-errors change, then retry)" >&2
exit 0
fi
latest_epoch="$(echo "${resp}" | jq '[.data[].occurred_at | select(. != null and . != "")] | map(fromdateiso8601) | max')"
now="$(date +%s)"
threshold=$((now - window_sec))
if ((latest_epoch > threshold)); then
echo "verify_pmx_bet_due_time_deploy: hub: FAIL — latest occurrence ${latest_ts} is within the last ${window_sec}s (open incidents still receiving recent traffic)" >&2
echo "${resp}" | jq -r '.data[] | "[\(.unique_id)] \(.occurred_at // "?") \(.message // .error_message // "")"' >&2
exit 1
fi
echo "verify_pmx_bet_due_time_deploy: hub: OK — latest matching occurrence ${latest_ts} is older than ${window_sec}s (no recent recurrence by this filter)"
}
case "${1:-}" in
gitea) cmd_gitea ;;
runtime) cmd_runtime ;;
hub) cmd_hub ;;
*)
echo "usage: $0 gitea|runtime" >&2
echo "usage: $0 gitea|runtime|hub" >&2
exit 1
;;
esac