test: verify history rows link raw frames
This commit is contained in:
@@ -169,7 +169,7 @@ python3 tools/go_native_prod_smoke.py --date 2026-07-02 --timeout 8
|
||||
|
||||
`go_systemd_prod_smoke.py` 通过 SSH 检查四个 Go systemd 服务是否 `active` 且 `enabled`,并确认 `808`、`32960` 由 `gateway` 监听、`20210` 由 `realtime-api` 监听,同时要求 `/opt/lingniu-go-native/spool/gateway` 没有待回放文件,避免旧 Java/Docker 进程占用生产端口或 Kafka spool 静默堆积。运行环境需要已配置 SSH 免密或已建立可用的 SSH 认证方式。
|
||||
|
||||
`go_native_prod_smoke.py` 通过 `20210` HTTP API 验证 GB32960、JT808、宇通 MQTT 的 RAW 查询及结构化 `parsed_json`,三类协议的位置和里程点查询,GB32960/JT808 的 `daily_mileage_km`、`daily_total_mileage_km` 统计,以及三类协议的 Redis realtime snapshot、online、protocol 查询。默认检查今天东八区数据时,还会要求三类 RAW 最新样本不超过 15 分钟,避免旧数据误判为接收正常;任一检查不达标时退出码为非 0。
|
||||
`go_native_prod_smoke.py` 通过 `20210` HTTP API 验证 GB32960、JT808、宇通 MQTT 的 RAW 查询及结构化 `parsed_json`,三类协议的位置和里程点查询及 `frame_id` RAW 回链,GB32960/JT808 的 `daily_mileage_km`、`daily_total_mileage_km` 统计,以及三类协议的 Redis realtime snapshot、online、protocol 查询。默认检查今天东八区数据时,还会要求三类 RAW 最新样本不超过 15 分钟,避免旧数据误判为接收正常;任一检查不达标时退出码为非 0。
|
||||
|
||||
## 部署命令
|
||||
|
||||
@@ -218,6 +218,6 @@ journalctl -u lingniu-go-realtime-api --since '5 minutes ago' --no-pager
|
||||
- gateway Kafka spool 当前无待回放文件。
|
||||
- GB32960、JT808、YUTONG_MQTT 的东八区 RAW 查询均可命中生产数据,且最新 RAW 样本包含结构化 `parsed_json`。
|
||||
- GB32960、JT808、YUTONG_MQTT 的最新 RAW 样本均在 15 分钟内。
|
||||
- GB32960、JT808、YUTONG_MQTT 的 `vehicle_locations`、`vehicle_mileage_points` 查询均可命中生产数据。
|
||||
- GB32960、JT808、YUTONG_MQTT 的 `vehicle_locations`、`vehicle_mileage_points` 查询均可命中生产数据,且样本包含 `frame_id` 回链 RAW。
|
||||
- `vehicle_daily_metric` 可查到 `daily_mileage_km` 和 `daily_total_mileage_km`。
|
||||
- Redis realtime 可查到 GB32960、JT808、YUTONG_MQTT 的在线状态和协议快照。
|
||||
|
||||
@@ -28,7 +28,7 @@ python3 tools/go_prod_acceptance.py --date 2026-07-02
|
||||
|
||||
- `go_systemd_prod_smoke.py`:应用 ECS systemd 服务 active/enabled、端口归属和 gateway spool
|
||||
- `go_kafka_prod_smoke.py`:Kafka topic 和消费组 lag
|
||||
- `go_native_prod_smoke.py`:HTTP API、RAW `parsed_json`、TDengine/MySQL/Redis 数据链路
|
||||
- `go_native_prod_smoke.py`:HTTP API、RAW `parsed_json`、历史核心表 `frame_id` 回链、TDengine/MySQL/Redis 数据链路
|
||||
|
||||
如需单独检查 systemd:
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class CheckSpec:
|
||||
kind: str = "total"
|
||||
max_age_minutes: float | None = None
|
||||
require_parsed_json: bool = False
|
||||
require_frame_id: bool = False
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -68,6 +69,7 @@ def check_total(
|
||||
max_age_minutes: float | None = None,
|
||||
now: dt.datetime | None = None,
|
||||
require_parsed_json: bool = False,
|
||||
require_frame_id: bool = False,
|
||||
) -> Check:
|
||||
count = int(payload.get("total") or 0)
|
||||
items = payload.get("items") or []
|
||||
@@ -92,9 +94,16 @@ def check_total(
|
||||
parsed_message = parsed_json_message(items)
|
||||
if not parsed_message.startswith("parsed_json=ok"):
|
||||
return Check(name, "fail", count, minimum, f"count={count}; {parsed_message}; sample={sample}")
|
||||
frame_message = ""
|
||||
if require_frame_id:
|
||||
frame_message = frame_id_message(items)
|
||||
if not frame_message.startswith("frame_id=ok"):
|
||||
return Check(name, "fail", count, minimum, f"count={count}; {frame_message}; sample={sample}")
|
||||
details = [f"count={count}", age_message]
|
||||
if parsed_message:
|
||||
details.append(parsed_message)
|
||||
if frame_message:
|
||||
details.append(frame_message)
|
||||
return Check(name, "pass", count, minimum, "; ".join(details) + f"; sample={sample}")
|
||||
return Check(name, "fail", count, minimum, f"count={count}; expected >= {minimum}; {age_message}; sample={sample}")
|
||||
|
||||
@@ -143,6 +152,15 @@ def parsed_json_message(items: list[Any]) -> str:
|
||||
return "invalid parsed_json"
|
||||
|
||||
|
||||
def frame_id_message(items: list[Any]) -> str:
|
||||
if not items or not isinstance(items[0], dict):
|
||||
return "missing frame_id"
|
||||
frame_id = str(items[0].get("frame_id") or "").strip()
|
||||
if frame_id:
|
||||
return "frame_id=ok"
|
||||
return "missing frame_id"
|
||||
|
||||
|
||||
def check_realtime(name: str, payload: dict[str, Any]) -> Check:
|
||||
if payload.get("online") is False:
|
||||
return Check(name, "fail", 0, 1, "online=false")
|
||||
@@ -237,12 +255,12 @@ def build_check_specs(
|
||||
max_age_minutes=max_raw_age_minutes,
|
||||
require_parsed_json=True,
|
||||
),
|
||||
CheckSpec("gb32960.locations", "/api/history/locations", gb32960_history_params, min_history),
|
||||
CheckSpec("gb32960.mileage_points", "/api/history/mileage-points", gb32960_history_params, min_history),
|
||||
CheckSpec("jt808.locations", "/api/history/locations", jt808_history_params, min_history),
|
||||
CheckSpec("jt808.mileage_points", "/api/history/mileage-points", jt808_history_params, min_history),
|
||||
CheckSpec("yutong_mqtt.locations", "/api/history/locations", yutong_mqtt_history_params, min_history),
|
||||
CheckSpec("yutong_mqtt.mileage_points", "/api/history/mileage-points", yutong_mqtt_history_params, min_history),
|
||||
CheckSpec("gb32960.locations", "/api/history/locations", gb32960_history_params, min_history, require_frame_id=True),
|
||||
CheckSpec("gb32960.mileage_points", "/api/history/mileage-points", gb32960_history_params, min_history, require_frame_id=True),
|
||||
CheckSpec("jt808.locations", "/api/history/locations", jt808_history_params, min_history, require_frame_id=True),
|
||||
CheckSpec("jt808.mileage_points", "/api/history/mileage-points", jt808_history_params, min_history, require_frame_id=True),
|
||||
CheckSpec("yutong_mqtt.locations", "/api/history/locations", yutong_mqtt_history_params, min_history, require_frame_id=True),
|
||||
CheckSpec("yutong_mqtt.mileage_points", "/api/history/mileage-points", yutong_mqtt_history_params, min_history, require_frame_id=True),
|
||||
CheckSpec(
|
||||
"gb32960.daily_mileage",
|
||||
"/api/stats/daily-metrics",
|
||||
@@ -340,6 +358,7 @@ def run_checks(base_url: str, specs: list[CheckSpec], timeout: float) -> list[Ch
|
||||
spec.minimum,
|
||||
spec.max_age_minutes,
|
||||
require_parsed_json=spec.require_parsed_json,
|
||||
require_frame_id=spec.require_frame_id,
|
||||
))
|
||||
except Exception as exc: # pragma: no cover - exercised by live failures.
|
||||
checks.append(Check(spec.name, "fail", 0, spec.minimum, f"request failed: {exc}"))
|
||||
@@ -359,6 +378,7 @@ def query_payloads(base_url: str, specs: list[CheckSpec], timeout: float) -> tup
|
||||
spec.minimum,
|
||||
spec.max_age_minutes,
|
||||
require_parsed_json=spec.require_parsed_json,
|
||||
require_frame_id=spec.require_frame_id,
|
||||
))
|
||||
except Exception as exc:
|
||||
checks.append(Check(spec.name, "fail", 0, spec.minimum, f"request failed: {exc}"))
|
||||
|
||||
@@ -207,6 +207,28 @@ class GoNativeProdSmokeTest(unittest.TestCase):
|
||||
self.assertEqual(check.status, "pass")
|
||||
self.assertIn("parsed_json=ok", check.message)
|
||||
|
||||
def test_history_check_requires_frame_id_backlink(self):
|
||||
check = smoke.check_total(
|
||||
"jt808.locations",
|
||||
{"total": 1, "items": [{"ts": "2026-07-01 17:45:00", "frame_id": ""}]},
|
||||
minimum=1,
|
||||
require_frame_id=True,
|
||||
)
|
||||
|
||||
self.assertEqual(check.status, "fail")
|
||||
self.assertIn("missing frame_id", check.message)
|
||||
|
||||
def test_history_check_accepts_frame_id_backlink(self):
|
||||
check = smoke.check_total(
|
||||
"jt808.mileage_points",
|
||||
{"total": 1, "items": [{"ts": "2026-07-01 17:45:00", "frame_id": "go_abc"}]},
|
||||
minimum=1,
|
||||
require_frame_id=True,
|
||||
)
|
||||
|
||||
self.assertEqual(check.status, "pass")
|
||||
self.assertIn("frame_id=ok", check.message)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user