feat(api): support traffic bytes tracking in edge access logs and refactor analytics models

- Add `bytes_sent` to `NodeAccessLog` on both Agent and Master Server.
- Create ClickHouse migration `202607120001_add_bytes_sent_to_node_access_logs.sql`.
- Refactor duplicate stats structs by centralizing them into `analyticsmodel` package with type aliases.
- Simplify access log store delegations and remove redundant mapping loops.
- Regenerate Swagger documentation.
- Update changelog index.md.
This commit is contained in:
ryan
2026-07-12 17:27:57 +08:00
parent f02fc9676a
commit 41cd23a64d
19 changed files with 246 additions and 245 deletions
+5 -3
View File
@@ -23,15 +23,17 @@ sidebar: false
### 新增
- 边缘访问日志 `of_node_access_logs` ClickHouse 表新增 `bytes_sent` 字段并打通 Agent 到 Server 的上报和 Zone 统计显示逻辑。
- Zone 概览页新增 Cloudflare 风格流量图:支持 24 小时 / 7 天 / 30 天,展示唯一访问者、请求总数与已提供数据趋势。
- 新增第一阶段 Zone 与正规化 Zone 域名数据库表及路由绑定模型,为后续以稳定 ID 管理网站与域名关联提供基础。
- 新增 Zone 管理 API 与显式历史域名导入命令,使用公共后缀列表验证注册根域和域名归属。
- 管理端网站入口改为 Zone 列表与 `/websites/:zoneId` 详情(概览 / 域名 / 路由 / 证书 / 设置),反代路由通过 Zone 域名选择器绑定。
- 新增 Zone 域名迁移指南(`docs/guide/zone-domain-migration.md`);历史域名在 Server 启动时由 goose 自动导入,无需单独命令。
### 修改
- 配置快照、OpenResty 渲染、Tunnel 与 Uptime Kuma 监控改为从 Zone 域名绑定读取域名和证书,移除对反代路由旧域名/证书字段的运行时回退。
- 重构并清理了分析仓统计层 `node_access_log_stats.go` 和 `openflare_access_log.go` 之间的重复模型,使用底层 type aliases 简化了类型转换和拷贝逻辑。
- 配置快照、OpenResty 渲染、Tunnel 与 Uptime Kuma 监控改为从 Zone 域名绑定读取域名 and 证书,移除对反代路由旧域名/证书字段的运行时回退。
- 管理端网站入口改为 Zone 列表与 `/websites/:zoneId` 详情(概览 / 域名 / 路由 / 证书 / 设置),反代路由通过 Zone 域名选择器绑定。
- 新增 Zone 域名迁移指南(`docs/guide/zone-domain-migration.md`);历史域名在 Server 启动时由 goose 自动导入,无需单独命令。
- 反代路由 API 以 `zone_domain_ids` / `zone_domains` 为唯一域名与证书关联来源,不再接受或返回路由内嵌域名/证书字段。
- 第二阶段迁移删除 `of_managed_domains` 及 `of_proxy_routes` 上的 `domain` / `domains` / `cert_id` / `cert_ids` / `domain_cert_ids` 冗余列。
+29 -5
View File
@@ -14041,6 +14041,9 @@ const docTemplate = `{
"github_com_Rain-kl_Wavelet_pkg_protocol.NodeAccessLog": {
"type": "object",
"properties": {
"bytes_sent": {
"type": "integer"
},
"host": {
"type": "string"
},
@@ -19023,15 +19026,15 @@ const docTemplate = `{
"type": "object",
"properties": {
"available": {
"description": "Available is false when analytics storage is unavailable (e.g. ClickHouse off).",
"type": "boolean"
},
"bucket_minutes": {
"type": "integer"
},
"bytes_sent": {
"description": "BytesSent is total response bytes. Currently always 0 until access logs store body_bytes_sent.",
"type": "integer"
},
"domain_count": {
"description": "DomainCount is the number of explicit Zone domains used to scope hosts.",
"type": "integer"
},
"range": {
@@ -19041,11 +19044,15 @@ const docTemplate = `{
"type": "integer"
},
"request_count": {
"description": "RequestCount is total access-log requests for Zone domains.",
"type": "integer"
},
"series": {
"type": "array",
"items": {
"$ref": "#/definitions/zone.StatsPoint"
}
},
"unique_visitors": {
"description": "UniqueVisitors is distinct client IPs (remote_addr) over the window.",
"type": "integer"
},
"window_ended_at": {
@@ -19056,6 +19063,23 @@ const docTemplate = `{
}
}
},
"zone.StatsPoint": {
"type": "object",
"properties": {
"bucket_started_at": {
"type": "string"
},
"bytes_sent": {
"type": "integer"
},
"request_count": {
"type": "integer"
},
"unique_visitors": {
"type": "integer"
}
}
},
"zone.StatsRange": {
"type": "string",
"enum": [
+29 -5
View File
@@ -14034,6 +14034,9 @@
"github_com_Rain-kl_Wavelet_pkg_protocol.NodeAccessLog": {
"type": "object",
"properties": {
"bytes_sent": {
"type": "integer"
},
"host": {
"type": "string"
},
@@ -19016,15 +19019,15 @@
"type": "object",
"properties": {
"available": {
"description": "Available is false when analytics storage is unavailable (e.g. ClickHouse off).",
"type": "boolean"
},
"bucket_minutes": {
"type": "integer"
},
"bytes_sent": {
"description": "BytesSent is total response bytes. Currently always 0 until access logs store body_bytes_sent.",
"type": "integer"
},
"domain_count": {
"description": "DomainCount is the number of explicit Zone domains used to scope hosts.",
"type": "integer"
},
"range": {
@@ -19034,11 +19037,15 @@
"type": "integer"
},
"request_count": {
"description": "RequestCount is total access-log requests for Zone domains.",
"type": "integer"
},
"series": {
"type": "array",
"items": {
"$ref": "#/definitions/zone.StatsPoint"
}
},
"unique_visitors": {
"description": "UniqueVisitors is distinct client IPs (remote_addr) over the window.",
"type": "integer"
},
"window_ended_at": {
@@ -19049,6 +19056,23 @@
}
}
},
"zone.StatsPoint": {
"type": "object",
"properties": {
"bucket_started_at": {
"type": "string"
},
"bytes_sent": {
"type": "integer"
},
"request_count": {
"type": "integer"
},
"unique_visitors": {
"type": "integer"
}
}
},
"zone.StatsRange": {
"type": "string",
"enum": [
+19 -9
View File
@@ -656,6 +656,8 @@ definitions:
type: object
github_com_Rain-kl_Wavelet_pkg_protocol.NodeAccessLog:
properties:
bytes_sent:
type: integer
host:
type: string
logged_at_unix:
@@ -3964,33 +3966,41 @@ definitions:
zone.Stats:
properties:
available:
description: Available is false when analytics storage is unavailable (e.g.
ClickHouse off).
type: boolean
bucket_minutes:
type: integer
bytes_sent:
description: BytesSent is total response bytes. Currently always 0 until access
logs store body_bytes_sent.
type: integer
domain_count:
description: DomainCount is the number of explicit Zone domains used to scope
hosts.
type: integer
range:
$ref: '#/definitions/zone.StatsRange'
range_hours:
type: integer
request_count:
description: RequestCount is total access-log requests for Zone domains.
type: integer
series:
items:
$ref: '#/definitions/zone.StatsPoint'
type: array
unique_visitors:
description: UniqueVisitors is distinct client IPs (remote_addr) over the
window.
type: integer
window_ended_at:
type: string
window_started_at:
type: string
type: object
zone.StatsPoint:
properties:
bucket_started_at:
type: string
bytes_sent:
type: integer
request_count:
type: integer
unique_visitors:
type: integer
type: object
zone.StatsRange:
enum:
- 24h