hailin
|
ce9cc5b72e
|
feat(telemetry): 完整实现 presence-service 迁移 + Flutter 遥测接入
## 后端 (backend/services/telemetry-service)
### 修复骨架中的关键缺陷
- 创建本地 JwtAuthGuard / AdminGuard,替换不存在的 @genex/common 包
- 修复 req.user.sub → req.user.id(与 JwtStrategy.validate() 返回值对齐)
- 重写 Dockerfile,移除对不存在的 packages/common 目录的引用
- 更新 telemetry.module.ts,将 JwtAuthGuard / AdminGuard 注册为 providers
- admin-telemetry.controller.ts 改用本地 AdminGuard(检查 role === 'admin')
### 新增功能
- GET /api/v1/telemetry/config:公开配置下发接口
Flutter TelemetryConfig.syncFromRemote() 每小时拉取,返回全局开关、采样率、
心跳间隔等配置,所有字段支持环境变量覆盖(TELEMETRY_GLOBAL_ENABLED 等)
- 设备字段(deviceBrand/deviceModel/deviceOs/appVersion/locale)提升为顶层列
BatchEventsDto / TelemetryEvent 实体 / recordEvents() 全链路补齐
原因:JSONB 内字段无法走 B-tree 索引,千万级数据分组查询需独立列
### DB 迁移
- 050_add_device_fields_to_telemetry_events.sql:为已有 telemetry_events 表
新增 5 个设备字段列和 device_brand / app_version 索引
### docker-compose 环境变量
- telemetry-service 新增 TELEMETRY_GLOBAL_ENABLED / SAMPLING_RATE /
HEARTBEAT_INTERVAL / CONFIG_VERSION 环境变量,支持生产环境热调整
## 前端
### genex-mobile (Flutter 消费者端)
- 复制 lib/core/telemetry/ 模块(11个文件):TelemetryService、
HeartbeatService、SessionManager、TelemetryUploader、TelemetryStorage 等
- 修正 API 路径:presence/heartbeat → telemetry/heartbeat,
analytics/events → telemetry/events
- pubspec.yaml 新增依赖:uuid ^4.3.3、equatable ^2.0.5、device_info_plus ^10.1.0
- main.dart:initState 首帧回调初始化 TelemetryService(需 BuildContext 采集设备信息)
已登录时自动注入 accessToken
- auth_service.dart:_setAuth() 登录成功后注入 userId + accessToken;
_clearAuth() 退出时清除(同时覆盖 Token 过期自动清除场景)
### admin-app (Flutter 发行方控制台)
- 复制 lib/core/telemetry/ 模块(同上)
- pubspec.yaml 新增依赖:uuid、equatable、device_info_plus、shared_preferences
- IssuerLoginPage:initState 首帧初始化 + 登录成功后注入 userId/token
使用 api.gogenex.cn(与 UpdateService 域名一致)
- settings_page.dart:退出登录时调用 clearUserId() + clearAccessToken()
## 架构说明
- 在线人数:Redis Sorted Set (genex:presence:online),心跳 60s/次,180s 窗口判定在线
- DAU:app_session_start 事件写入 telemetry_events,每天凌晨 1 点聚合到
daily_active_stats 表,同时每小时滚动更新当日 DAU
- 设备字段采用 Amplitude 风格:前端本地队列存 properties 内,
toServerJson() 上传时自动提升为顶层字段,后端写入独立索引列
- 心跳需要 JWT 认证(未登录用户自动跳过,不报错)
- 遥测完全异步,任何失败只打 debug 日志,不影响主流程
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
2026-03-05 23:33:13 -08:00 |
hailin
|
e8e2d14fbc
|
fix(health): 修正NestJS服务健康检查URL路径 /health → /api/v1/health
NestJS服务注册了全局路由前缀 api/v1,HealthController 实际挂载在
/api/v1/health 而非 /health,导致 Docker HEALTHCHECK 返回 404。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-20 05:50:26 -08:00 |
hailin
|
c5787020d2
|
feat(health): 为全部12个微服务添加Docker健康检查
## 变更概要
所有后端微服务均增加 Docker HEALTHCHECK 指令,统一通过 GET /health
端点检测服务存活状态。解决 `docker ps` 中13个容器无 (healthy) 状态的问题。
## NestJS 服务 (9个)
- auth-service (:3010), user-service (:3001), issuer-service (:3002),
clearing-service (:3004), compliance-service (:3005), ai-service (:3006),
notification-service (:3008), telemetry-service (:3011), admin-service (:3012)
- 7个服务的 app.module.ts 新增 `import { HealthModule } from '@genex/common'`
注册标准健康检查控制器 (GET /health, /health/ready, /health/live)
- telemetry-service 和 admin-service 已有自建 HealthController,无需导入
- Dockerfile: HEALTHCHECK --interval=30s --start-period=15s --retries=3
## Go 服务 (3个)
- trading-service (:3003), translate-service (:3007), chain-indexer (:3009)
- 已有 /health 端点 (Gin 路由),仅 Dockerfile 添加 HEALTHCHECK
- Dockerfile: HEALTHCHECK --interval=30s --start-period=10s --retries=3
## Kafka Connect
- docker-compose.yml 添加 healthcheck (curl http://localhost:8083/)
## 健康检查方式
- 所有服务统一使用 `wget --spider http://localhost:PORT/health`
(node:20-alpine 和 alpine:3.19 均自带 BusyBox wget)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-20 05:39:25 -08:00 |
hailin
|
d48bd3acb9
|
feat(docker): 重构Monorepo构建 — 支持@genex/common共享包
- docker-compose.yml build context从service目录改为backend根目录
- 所有NestJS Dockerfile改为先构建共享@genex/common包
- 共享包编译后复制到service的node_modules供运行时解析
- 新增backend/.dockerignore减少构建上下文体积
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-19 19:00:27 -08:00 |
hailin
|
12bb31ede1
|
fix(docker): 所有NestJS服务Dockerfile使用npm install替代npm ci
项目未包含package-lock.json,npm ci要求该文件存在才能运行。
改用npm install确保Docker构建正常完成。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-19 17:33:31 -08:00 |
hailin
|
c11d009ae7
|
fix: admin-service/telemetry-service Dockerfile 改为多阶段构建
修复缺少 builder 阶段导致 COPY dist/ 找不到目录的问题
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-19 17:29:56 -08:00 |
hailin
|
e20c321d12
|
refactor: 遥测与版本管理拆分为独立微服务 (telemetry-service + admin-service)
架构重构: 将遥测(Telemetry)和版本管理(App Version)从 user-service 拆分为两个独立微服务,
严格遵循 DDD + Clean Architecture 四层架构。
新增服务:
- telemetry-service (:3011) — 用户心跳检测、事件采集、DAU统计、Prometheus指标
- domain: 3实体 + 3值对象(EventName/InstallId/TimeWindow) + 2领域事件
- infrastructure: Redis(Sorted Set心跳) + Kafka(事件发布) + Prometheus(5指标)
- 定时任务: 每分钟在线快照、每小时清理过期、凌晨DAU精确计算、滚动DAU更新
- admin-service (:3012) — APK/IPA版本管理、OTA更新、MinIO文件存储
- domain: 1实体 + 4值对象(VersionCode/VersionName/FileSha256/DownloadUrl)
- infrastructure: MinIO(文件上传/下载) + APK/IPA解析器
- 移动端: 检查更新API(无认证) + 下载重定向(预签名URL)
- 管理端: 版本CRUD + 上传解析 + 启禁用
user-service 清理:
- 删除24个已迁移文件(4实体+4服务+4基础设施+5控制器+6DTO+1gitkeep)
- 移除不再需要的依赖: @nestjs/schedule, minio, prom-client, kafkajs
- 精简 user.module.ts,仅保留用户核心功能(Profile/KYC/Wallet/Message/Admin)
基础设施更新:
- Kong: 遥测路由 → telemetry-service:3011, 版本路由 → admin-service:3012
- docker-compose: 新增2个服务容器 + MinIO app-releases bucket
- 07开发指南: 更新为独立服务架构描述
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-12 18:30:39 -08:00 |