refactor(api): update traffic chart response structure

Change the traffic chart API response from bucket-based to series-based
to better support frontend visualization libraries. The new format
provides a shared X-axis and aligned data arrays for each model series.

- Replace `buckets` with `x` and `series` in response
- Implement data alignment and zero-filling for time slots
- Update Swagger documentation including pending definitions

BREAKING CHANGE: The `GET /admin/logs/stats/traffic-chart` response
schema has changed. `buckets` and `models` fields are removed.
This commit is contained in:
zenfun
2026-01-08 18:40:44 +08:00
parent 341b54b185
commit f400ffde95
10 changed files with 3239 additions and 294 deletions

View File

@@ -371,6 +371,49 @@ curl "http://localhost:8080/admin/logs/stats?group_by=minute&since=1704150000&un
}
```
#### 流量图表统计
`GET /admin/logs/stats/traffic-chart`
**参数**
| 参数 | 类型 | 说明 | 约束 |
| :--- | :--- | :--- | :--- |
| `granularity` | string | 时间粒度:`hour` / `minute` | `minute` 必须提供 `since` + `until` 且跨度 ≤ 6 小时 |
| `since` | int | 起始时间 (Unix 秒) | 默认 24 小时前 |
| `until` | int | 结束时间 (Unix 秒) | 默认当前 |
| `top_n` | int | Top 模型数量 | 1-20默认 5其余聚合为 `other` |
**响应示例**
```json
{
"granularity": "hour",
"since": 1735689600,
"until": 1735776000,
"x": {
"labels": ["2025-01-01T00:00:00Z", "2025-01-01T01:00:00Z"],
"timestamps": [1735689600, 1735693200],
"totals": {
"data": [2050, 1800],
"tokens_in": [82000, 70000],
"tokens_out": [128000, 110000]
}
},
"series": [
{
"name": "gpt-4-turbo",
"data": [1200, 900],
"tokens_in": [50000, 38000],
"tokens_out": [80000, 62000]
},
{
"name": "other",
"data": [850, 900],
"tokens_in": [32000, 32000],
"tokens_out": [48000, 48000]
}
]
}
```
### 6.2 API Key 状态筛选
`GET /admin/api-keys?status=active|suspended|auto_disabled|manual_disabled`