优化系统健康评分与缓存监测

This commit is contained in:
Cheng Zhou
2026-06-30 10:43:24 +08:00
parent b25055775e
commit 668e719b6d
10 changed files with 412 additions and 42 deletions
@@ -15,6 +15,17 @@ vi.mock("@/api/projectPermissions", () => ({
cache_metrics: {
total_accesses: 1000, cache_hits: 850, cache_misses: 150,
cache_invalidations: 5, hit_rate: 85.0, miss_rate: 15.0,
window_seconds: 3600, scope: "sliding_window",
by_cache: {
project_permissions: {
total_accesses: 800, cache_hits: 700, cache_misses: 100,
cache_invalidations: 5, hit_rate: 87.5, miss_rate: 12.5,
},
member_roles: {
total_accesses: 200, cache_hits: 150, cache_misses: 50,
cache_invalidations: 5, hit_rate: 75, miss_rate: 25,
},
},
},
uptime_seconds: 3600,
},
@@ -22,7 +33,21 @@ vi.mock("@/api/projectPermissions", () => ({
fetchPermissionHealth: vi.fn().mockResolvedValue({
data: {
status: "healthy", health_score: 95, issues: [],
metrics: {}, cache_stats: { cache_items: { total_count: 60 }, cache_metrics: {} },
sample_sufficient: true,
score_breakdown: {
performance: { weight: 40, deduction: 0 },
deny_rate: { weight: 20, deduction: 0 },
cache: {
weight: 25, deduction: 5, sample_sufficient: true,
scope: "sliding_window", window_seconds: 3600,
},
alerts: { weight: 15, deduction: 0 },
},
last_hour: {
total_checks: 30, denied_checks: 2, deny_rate: 6.67,
avg_elapsed_ms: 3.5, error_alerts: 0, warning_alerts: 0,
},
cache_stats: { cache_items: { total_count: 60 }, cache_metrics: {} },
},
}),
fetchPermissionAlerts: vi.fn().mockResolvedValue({ data: { total: 0, alerts: [] } }),
@@ -94,7 +119,7 @@ describe("PermissionMonitoring.vue", () => {
it("resizes the source-analysis chart when its tab becomes active", () => {
const source = readFileSync(resolve(__dirname, "./PermissionMonitoring.vue"), "utf8");
expect(source).toContain('import { ref, computed, h, nextTick, onMounted } from "vue"');
expect(source).toContain("onUnmounted");
expect(source).toContain("type IpLocationsExpose");
expect(source).toContain("resize: () => void | Promise<void>");
expect(source).toContain('if (tab === "ip-locations")');