test: add go systemd production smoke

This commit is contained in:
lingniu
2026-07-02 01:51:41 +08:00
parent 0ef88e1a4c
commit 96514898eb
4 changed files with 214 additions and 20 deletions

View File

@@ -155,10 +155,13 @@ curl -sS 'http://115.29.187.205:20210/api/stats/daily-metrics?dateFrom=2026-07-0
部署后推荐直接运行 Go 原生生产 smoke
```bash
python3 tools/go_systemd_prod_smoke.py --host 115.29.187.205 --user root
python3 tools/go_native_prod_smoke.py --date 2026-07-02 --timeout 8
```
该脚本通过 `20210` HTTP API 验证 GB32960、JT808、宇通 MQTT 的 RAW 查询三类协议的位置和里程点查询GB32960/JT808 的 `daily_mileage_km``daily_total_mileage_km` 统计,以及三类协议的 Redis realtime snapshot、online、protocol 查询。默认检查今天东八区数据时,还会要求三类 RAW 最新样本不超过 15 分钟,避免旧数据误判为接收正常;任一检查不达标时退出码为非 0
`go_systemd_prod_smoke.py` 通过 SSH 检查四个 Go systemd 服务是否 `active`,并确认 `808``32960``gateway` 监听、`20210``realtime-api` 监听,避免旧 Java/Docker 进程占用生产端口。运行环境需要已配置 SSH 免密或已建立可用的 SSH 认证方式
`go_native_prod_smoke.py` 通过 `20210` HTTP API 验证 GB32960、JT808、宇通 MQTT 的 RAW 查询三类协议的位置和里程点查询GB32960/JT808 的 `daily_mileage_km``daily_total_mileage_km` 统计,以及三类协议的 Redis realtime snapshot、online、protocol 查询。默认检查今天东八区数据时,还会要求三类 RAW 最新样本不超过 15 分钟,避免旧数据误判为接收正常;任一检查不达标时退出码为非 0。
## 部署命令
@@ -189,6 +192,8 @@ systemctl restart lingniu-go-realtime-api.service
## 运行检查
```bash
python3 tools/go_systemd_prod_smoke.py --host 115.29.187.205 --user root
systemctl is-active lingniu-go-gateway lingniu-go-history-writer lingniu-go-stat-writer lingniu-go-realtime-api
ss -lntp | egrep ':(808|32960|20210)\b'
journalctl -u lingniu-go-gateway --since '5 minutes ago' --no-pager

View File

@@ -18,32 +18,26 @@ go build ./cmd/stat-writer
go build ./cmd/realtime-api
```
## 镜像构建
## 生产原生部署验证
```bash
cd go/vehicle-gateway
docker build -t vehicle-gateway-go:local .
python3 tools/go_systemd_prod_smoke.py --host 115.29.187.205 --user root
```
同一个镜像包含四个二进制
脚本通过 SSH 检查
- `/app/gateway`
- `/app/history-writer`
- `/app/stat-writer`
- `/app/realtime-api`
- `lingniu-go-gateway.service`
- `lingniu-go-history-writer.service`
- `lingniu-go-stat-writer.service`
- `lingniu-go-realtime-api.service`
- `808``32960``gateway` 监听
- `20210``realtime-api` 监听
## Portainer 部署
## 生产环境变量
Go 旁路 stack 文件
当前 goal 的生产面使用 ECS 原生 systemd 部署,不再以 Docker/Portainer 作为生产运行方式。以下环境变量维护在 `/opt/lingniu-go-native/env/*.env`
```bash
deploy/portainer/docker-compose-go.yml
```
必填变量:
```bash
LINGNIU_GO_IMAGE_VERSION=<image-version>
KAFKA_BROKERS=172.17.111.56:9092
TDENGINE_DSN=root:<password>@ws(172.17.111.57:6041)/lingniu_vehicle_ts
MYSQL_DSN=lingniu_vehicle:<password>@tcp(rm-bp179zbv481rnw3e2.mysql.rds.aliyuncs.com:3306)/lingniu_vehicle_data?parseTime=true&charset=utf8mb4,utf8&loc=Asia%2FShanghai
@@ -68,8 +62,7 @@ YUTONG_MQTT_PASSWORD=<password>
## ECS 进程检查
```bash
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' \
| egrep 'go-vehicle-gateway|go-history-writer|go-stat-writer|go-realtime-api|NAMES'
systemctl is-active lingniu-go-gateway lingniu-go-history-writer lingniu-go-stat-writer lingniu-go-realtime-api
ss -lntp | egrep ':(808|32960|20210)\b'
```