Skip to content

Commit 7bf00a4

Browse files
authored
fix COD-56:凭证分组文案改为全维度小时汇总永久保留 (#99)
1 parent a6c3481 commit 7bf00a4

5 files changed

Lines changed: 81 additions & 5 deletions

File tree

‎tests/api/test_admin_stats.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def test_stats_endpoints_scope_by_principal(admin_client):
4343
"p95_latency_ms": None, "p95_ttfb_ms": None,
4444
"p99_latency_ms": None, "p99_ttfb_ms": None},
4545
]
46-
# 凭证分组读明细:本用例两条记录都没带 credential_id,故为空
46+
# 凭证分组读全维度小时汇总(`usage_hourly_dim`):本用例两条记录都没带
47+
# credential_id(哨兵 ''),故为空
4748
assert client.get("/api/stats/by-credential").json() == {"credentials": []}
4849
timeline = client.get("/api/stats/timeline").json()
4950
assert timeline["points"]

‎web/src/api/hooks.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export function useStatsByUser(username?: string, target?: string, since?: numbe
237237
});
238238
}
239239

240-
/** 按凭证聚合:数据源是明细表(仅 45 天),非 admin/operator 看不到他人凭证。 */
240+
/** 按凭证聚合:数据源是全维度小时汇总(`usage_hourly_dim`,永久保留、整点桶
241+
* 粒度),非 admin/operator 看不到他人凭证。 */
241242
export function useStatsByCredential(username?: string, target?: string, since?: number,
242243
until?: number, sort?: string, order?: string,
243244
enabled = true) {

‎web/src/i18n/text.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ export const TEXT_EN: Record<string, string> = {
410410
"(a request failing multiple times counts multiple times; a separate successful row for the same request counts as rescued). Click any row to drill into the “Request details” below (failures only).",
411411
"口径说明(数据源 · 延迟 · 速度)": "Definitions (data source · latency · speed)",
412412
"口径说明(速度的分子与分母)": "Definitions (speed numerator and denominator)",
413-
"凭证分组取自逐请求明细(仅保留 45 天),无凭证的预热失败等请求不计入。":
414-
"Credential grouping comes from per-request details (45 days only); requests without a credential, such as warm-up failures, are excluded.",
413+
"凭证分组取自全维度小时汇总(永久保留,整点桶粒度),无凭证的预热失败等请求不计入。":
414+
"Credential grouping comes from the full-dimension hourly aggregates (kept forever, hourly buckets); requests without a credential, such as warm-up failures, are excluded.",
415415
"各维度数据源为小时汇总(永久保留),最近 5 分钟内的请求可能尚未计入。":
416416
"Each dimension uses hourly aggregates (kept forever); requests from the last 5 minutes may not be counted yet.",
417417
"点任意一行可钻取到下方「请求明细」。": "Click any row to drill into the “Request details” below.",

‎web/src/pages/stats/GroupStatsPanel.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ export function GroupStatsPanel(props: GroupStatsPanelProps) {
282282
)}
283283
<Footnote summary={tr("口径说明(数据源 · 延迟 · 速度)")} testId="group-footnote">
284284
<p>
285+
{/* 凭证分组的数据源是 `usage_hourly_dim`(全维度小时汇总,永久保留),
286+
不是逐请求明细;写成 45 天会让人以为凭证维度数据会消失。 */}
285287
{groupKey === "credential_id"
286-
? tr("凭证分组取自逐请求明细(仅保留 45 天),无凭证的预热失败等请求不计入。")
288+
? tr("凭证分组取自全维度小时汇总(永久保留,整点桶粒度),无凭证的预热失败等请求不计入。")
287289
: tr("各维度数据源为小时汇总(永久保留),最近 5 分钟内的请求可能尚未计入。")}
288290
{" "}{tr("点任意一行可钻取到下方「请求明细」。")}
289291
</p>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* 分组表「口径说明」的数据源必须与后端实际读的表一致。
3+
*
4+
* 回归:凭证分组已改读 `usage_hourly_dim`(全维度小时汇总,永久保留),
5+
* 说明文案却还写「取自逐请求明细(仅保留 45 天)」,用户会把「永久可查」
6+
* 读成「45 天后消失」,运维排障时误判数据缺失。
7+
*/
8+
import { render, screen } from "@testing-library/react";
9+
import { describe, expect, it } from "vitest";
10+
import { userEvent } from "@/test-utils";
11+
import { GroupStatsPanel } from "../GroupStatsPanel";
12+
import {
13+
GROUP_DIMENSIONS,
14+
type GroupDimension,
15+
type GroupRow,
16+
type StatsSortState,
17+
} from "../constants";
18+
19+
const GROUP_SORT: StatsSortState = {
20+
sort: "requests",
21+
order: "desc",
22+
toggle: () => {},
23+
};
24+
25+
function dimension(value: string): GroupDimension {
26+
const found = GROUP_DIMENSIONS.find((item) => item.value === value);
27+
if (!found) throw new Error(`未知分组维度: ${value}`);
28+
return found;
29+
}
30+
31+
function renderPanel(value: string, rows: GroupRow[] = []) {
32+
const group = dimension(value);
33+
return render(
34+
<GroupStatsPanel
35+
groupDimension={group.value}
36+
groupDimensions={GROUP_DIMENSIONS}
37+
onGroupDimensionChange={() => {}}
38+
percentile="p95"
39+
onPercentileChange={() => {}}
40+
groupSort={GROUP_SORT}
41+
group={group}
42+
groupRows={rows}
43+
onDrill={() => {}}
44+
/>,
45+
);
46+
}
47+
48+
/** 展开折叠的脚注并返回正文第一段(数据源那段)。 */
49+
async function expandDataSourceParagraph(): Promise<HTMLElement> {
50+
await userEvent.click(screen.getByText("口径说明(数据源 · 延迟 · 速度)"));
51+
const paragraphs = screen.getByTestId("group-footnote").querySelectorAll("p");
52+
expect(paragraphs.length).toBeGreaterThan(0);
53+
return paragraphs[0] as HTMLElement;
54+
}
55+
56+
describe("分组表口径说明与数据源一致", () => {
57+
it("凭证分组:说明小时汇总永久保留,不再提 45 天", async () => {
58+
renderPanel("credential");
59+
const source = await expandDataSourceParagraph();
60+
expect(source).toHaveTextContent("凭证分组取自全维度小时汇总(永久保留,整点桶粒度)");
61+
expect(source).toHaveTextContent("无凭证的预热失败等请求不计入");
62+
expect(source).not.toHaveTextContent("逐请求明细");
63+
expect(source.textContent).not.toContain("45 天");
64+
});
65+
66+
it("渠道分组:仍写小时汇总永久保留", async () => {
67+
renderPanel("provider");
68+
const source = await expandDataSourceParagraph();
69+
expect(source).toHaveTextContent("各维度数据源为小时汇总(永久保留)");
70+
expect(source).not.toHaveTextContent("凭证分组");
71+
});
72+
});

0 commit comments

Comments
 (0)