From f1e3c2ab11620c35885ff7ec31042907344667c3 Mon Sep 17 00:00:00 2001 From: fawney19 Date: Tue, 16 Dec 2025 02:39:54 +0800 Subject: [PATCH] feat(frontend-usage): enhance usage UI with first byte latency metrics - Update usage records table to display first_byte_time_ms metrics - Improve request timeline visualization for latency tracking - Extend usage types for new timing information --- .../components/HorizontalRequestTimeline.vue | 17 +++++++++- .../usage/components/UsageRecordsTable.vue | 32 +++++++++++++------ frontend/src/features/usage/types.ts | 1 + 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/frontend/src/features/usage/components/HorizontalRequestTimeline.vue b/frontend/src/features/usage/components/HorizontalRequestTimeline.vue index 56310a3..cd77a76 100644 --- a/frontend/src/features/usage/components/HorizontalRequestTimeline.vue +++ b/frontend/src/features/usage/components/HorizontalRequestTimeline.vue @@ -479,10 +479,25 @@ const groupedTimeline = computed(() => { return groups }) -// 计算链路总耗时(从第一个节点开始到最后一个节点结束) +// 计算链路总耗时(使用成功候选的 latency_ms 字段) +// 优先使用 latency_ms,因为它与 Usage.response_time_ms 使用相同的时间基准 +// 避免 finished_at - started_at 带来的额外延迟(数据库操作时间) const totalTraceLatency = computed(() => { if (!timeline.value || timeline.value.length === 0) return 0 + // 查找成功的候选,使用其 latency_ms + const successCandidate = timeline.value.find(c => c.status === 'success') + if (successCandidate?.latency_ms != null) { + return successCandidate.latency_ms + } + + // 如果没有成功的候选,查找失败但有 latency_ms 的候选 + const failedWithLatency = timeline.value.find(c => c.status === 'failed' && c.latency_ms != null) + if (failedWithLatency?.latency_ms != null) { + return failedWithLatency.latency_ms + } + + // 回退:使用 finished_at - started_at 计算 let earliestStart: number | null = null let latestEnd: number | null = null diff --git a/frontend/src/features/usage/components/UsageRecordsTable.vue b/frontend/src/features/usage/components/UsageRecordsTable.vue index a0ff06f..0e184be 100644 --- a/frontend/src/features/usage/components/UsageRecordsTable.vue +++ b/frontend/src/features/usage/components/UsageRecordsTable.vue @@ -177,8 +177,9 @@ 费用 -
- 响应时间 +
+ 首字 + 总耗时
@@ -356,15 +357,28 @@
- - {{ getElapsedTime(record) }} - - - {{ (record.response_time_ms / 1000).toFixed(2) }}s - + + {{ getElapsedTime(record) }} + + +
+ {{ (record.first_byte_time_ms / 1000).toFixed(2) }}s + - + {{ (record.response_time_ms / 1000).toFixed(2) }}s +