Skip to content

Commit 956a011

Browse files
authored
Add execution report heartbeat alerts (#130)
1 parent 6636a15 commit 956a011

3 files changed

Lines changed: 506 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Execution Report Heartbeat
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
lookback_hours:
7+
description: "Report lookback window in hours."
8+
required: false
9+
type: string
10+
default: "36"
11+
fail_workflow_on_alert:
12+
description: "Fail this workflow when an alert is emitted."
13+
required: false
14+
type: choice
15+
default: "true"
16+
options:
17+
- "true"
18+
- "false"
19+
schedule:
20+
- cron: "15 23 * * 1-5"
21+
22+
env:
23+
GCP_PROJECT_ID: interactivebrokersquant
24+
GCP_WORKLOAD_IDENTITY_PROVIDER: projects/303168642265/locations/global/workloadIdentityPools/github-actions/providers/github-main
25+
GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: ibkr-platform-deploy@interactivebrokersquant.iam.gserviceaccount.com
26+
27+
jobs:
28+
heartbeat:
29+
name: Check execution report heartbeat
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
id-token: write
34+
env:
35+
RUNTIME_HEARTBEAT_NAME: InteractiveBrokersPlatform
36+
RUNTIME_HEARTBEAT_REPORT_PLATFORM: interactive_brokers
37+
RUNTIME_HEARTBEAT_REQUIRED_SERVICES: ${{ vars.RUNTIME_HEARTBEAT_REQUIRED_SERVICES }}
38+
RUNTIME_HEARTBEAT_GCS_URIS: ${{ vars.RUNTIME_HEARTBEAT_GCS_URIS || vars.EXECUTION_REPORT_GCS_URI }}
39+
RUNTIME_HEARTBEAT_LOOKBACK_HOURS: ${{ inputs.lookback_hours || vars.RUNTIME_HEARTBEAT_LOOKBACK_HOURS || '36' }}
40+
RUNTIME_HEARTBEAT_FAIL_WORKFLOW_ON_ALERT: ${{ inputs.fail_workflow_on_alert || vars.RUNTIME_HEARTBEAT_FAIL_WORKFLOW_ON_ALERT || 'true' }}
41+
RUNTIME_HEARTBEAT_ACCEPT_STATUSES: ${{ vars.RUNTIME_HEARTBEAT_ACCEPT_STATUSES }}
42+
RUNTIME_HEARTBEAT_REJECT_STATUSES: ${{ vars.RUNTIME_HEARTBEAT_REJECT_STATUSES }}
43+
CLOUD_RUN_SERVICE: ${{ vars.CLOUD_RUN_SERVICE }}
44+
CLOUD_RUN_SERVICES: ${{ vars.CLOUD_RUN_SERVICES }}
45+
CLOUD_RUN_SERVICE_TARGETS_JSON: ${{ vars.CLOUD_RUN_SERVICE_TARGETS_JSON }}
46+
GLOBAL_TELEGRAM_CHAT_ID: ${{ vars.GLOBAL_TELEGRAM_CHAT_ID }}
47+
CRISIS_ALERT_TELEGRAM_CHAT_IDS: ${{ vars.CRISIS_ALERT_TELEGRAM_CHAT_IDS }}
48+
CRISIS_ALERT_TELEGRAM_API_BASE_URL: ${{ vars.CRISIS_ALERT_TELEGRAM_API_BASE_URL }}
49+
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
50+
CRISIS_ALERT_TELEGRAM_BOT_TOKEN: ${{ secrets.CRISIS_ALERT_TELEGRAM_BOT_TOKEN }}
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v6
54+
55+
- name: Authenticate to Google Cloud
56+
uses: google-github-actions/auth@v3
57+
with:
58+
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
59+
service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}
60+
61+
- name: Set up gcloud
62+
uses: google-github-actions/setup-gcloud@v3
63+
64+
- name: Check recent execution report
65+
run: python scripts/execution_report_heartbeat.py

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ The scheduled guard runs every 30 minutes. For a missed-run heartbeat, set
391391
The default leaves the heartbeat check off to avoid false alerts outside the
392392
active trading window.
393393

394+
`Execution Report Heartbeat` (`.github/workflows/execution-report-heartbeat.yml`)
395+
is the stricter completion check. It runs on weekdays after the expected market
396+
window and verifies that a recent runtime report exists under
397+
`EXECUTION_REPORT_GCS_URI`. It reads the latest report JSON and alerts if no
398+
recent report exists or the recent reports have rejected statuses such as
399+
`error`. The deploy service account needs object read/list access on the report
400+
bucket.
401+
For slot deployments, `CLOUD_RUN_SERVICE_TARGETS_JSON` is used to require a
402+
recent acceptable report for each configured service; set
403+
`RUNTIME_HEARTBEAT_REQUIRED_SERVICES` when only a subset should be monitored.
404+
394405
### Deployment unit and naming
395406

396407
- `QuantPlatformKit` is only a shared dependency; Cloud Run now deploys `InteractiveBrokersPlatform`.
@@ -669,6 +680,14 @@ OIDC/IAM/audience 配错、Cloud Run 返回 4xx/5xx、或容器在 app-level Tel
669680
`RUNTIME_GUARD_REQUIRE_SUCCESS=true`,并把 `RUNTIME_GUARD_LOOKBACK_MINUTES` 设成覆盖预期
670681
Scheduler 运行时间的窗口。默认不强制心跳,避免非交易窗口误报。
671682

683+
更严格的完成检查是 `Execution Report Heartbeat`
684+
`.github/workflows/execution-report-heartbeat.yml`)。它会在工作日预期市场窗口后检查
685+
`EXECUTION_REPORT_GCS_URI` 下最近的 runtime report JSON,读取 `status/stage/errors`
686+
如果没有近期 report 或 report 状态为 `error` 等失败状态就发 Telegram。GitHub deploy
687+
service account 需要对 report bucket 有对象读取/列举权限。
688+
slot 部署会从 `CLOUD_RUN_SERVICE_TARGETS_JSON` 解析每个 service,并要求每个 service 都有近期
689+
可接受 report;如果只想监控部分服务,设置 `RUNTIME_HEARTBEAT_REQUIRED_SERVICES`
690+
672691
### 部署单元和命名建议
673692

674693
- `QuantPlatformKit` 只是共享依赖,不单独部署;Cloud Run 现在部署的是 `InteractiveBrokersPlatform`

0 commit comments

Comments
 (0)