Skip to content

feat(frontend): color-code first-token & total latency in usage views#43

Merged
acking-you merged 1 commit into
masterfrom
feat/usage-latency-color-viz
Jun 13, 2026
Merged

feat(frontend): color-code first-token & total latency in usage views#43
acking-you merged 1 commit into
masterfrom
feat/usage-latency-color-viz

Conversation

@acking-you

Copy link
Copy Markdown
Owner

背景

usage 相关视图里延迟只有数字(或仅整体延迟有颜色),不容易一眼看出快慢。本 PR 让首字延迟(首字 / TTFT)和整体延迟都按延迟高低映射到颜色,并为两者设计了不同宽度的色阶。

改动

1. 共享色阶 helper(llm_access_shared.rs

新增 LatencyBadgeColor 类型别名、format_latency_ms,以及两个色阶函数(带单元测试),供 admin 与公开页复用:

指标 色阶
首字延迟 (TTFT) <3s 🟢 emerald · <10s 🟡 amber · ≥10s 🔴 red
整体延迟 <8s 🟢 emerald · <24s 🟢 lime · <48s 🟡 amber · <96s 🟠 orange · ≥96s 🔴 red
  • 首字延迟沿用原先「整体延迟」的阈值——首字节之前的窗口即使上游慢也不会太大。
  • 整体延迟覆盖整段生成,流式推理请求跑过一分钟很正常,因此用更宽的 5 段色阶,并保持原来 1:3:6:12 的间距比例(绿色阈值 5s → 8s,其余同比例放大)。

2. Admin LLM Gateway(admin_llm_gateway.rs

  • Usage 标签页与 Usage journal preview 标签页:整体延迟改用更宽的色阶;首字延迟从灰色纯文本改为带颜色的徽章
  • 删除页面内私有的 format_latency_ms,统一使用共享实现。

3. 公开页 /llm-access/usagellm_access_usage.rs

  • 延迟单元格复用 admin 的彩色徽章样式,并新增首字延迟(之前只有整体延迟)。
  • 移除「账号」列

验证

  • cargo check -p static-flow-frontend --target wasm32-unknown-unknown
  • cargo test(latency 相关用例,含新增边界测试)5 passed ✅
  • Tailwind 构建确认新增的 lime / orange 工具类已生成 ✅

范围说明

监控(运行监控)面板里的 首字延迟 / 整体延迟聚合 KPI 卡片(均值/最大值),并非逐条 usage 表格,因此本 PR 未改动;如需要也给这些聚合卡片上色可以再开一个 PR。

🤖 Generated with Claude Code

Map latency magnitude to color across the usage surfaces, on two scales:

- 首字延迟 (first-token / TTFT): tight 3-step scale (<3s green / <10s amber
  / >=10s red) — the pre-first-byte window stays small even when upstreams
  are slow.
- 整体延迟 (total request latency): wider 5-step scale that keeps the original
  1:3:6:12 spacing (<8s emerald / <24s lime / <48s amber / <96s orange /
  >=96s red), since a streaming reasoning request can legitimately run well
  over a minute.

Changes:
- llm_access_shared.rs: add shared LatencyBadgeColor alias, format_latency_ms,
  first_token_latency_color and total_latency_color helpers + unit tests.
- admin_llm_gateway.rs: the Usage tab and Usage-journal-preview tab now use
  the shared helpers; first-token latency is rendered as a color-coded badge
  instead of plain muted text. The private format_latency_ms is dropped in
  favor of the shared one.
- llm_access_usage.rs (public /llm-access/usage): the latency cell reuses the
  colored-badge style and now shows first-token latency; the 账号 (account)
  column is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors and standardizes latency rendering across the LLM gateway admin and public usage pages. It extracts latency formatting and color-scale logic (for both total latency and first-token latency/TTFT) into a shared module (llm_access_shared.rs), adds corresponding unit tests, and updates the UI to display styled badges for both metrics. Additionally, it removes the account column from the public usage table. No review comments were provided, so there is no feedback to address.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@acking-you acking-you merged commit 484ae9a into master Jun 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant