mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
- refactors new charts in homepage to use stable analytics endpoints
- changes are behind newHomepageUsageV2 flag
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Centralized per-service health metrics hook with per-service data,
loading/error states and refresh.
* **Improvements**
* Time-series normalization into fixed buckets aligned to an end time.
* Updated UI: success-rate formatting, per-service loading/error
surfaced, refreshed click/refresh behavior; removed delta display.
* **Removals**
* Legacy project-metrics query and mapping utilities removed.
* **Tests**
* Extensive unit tests added for date ranges, bucket normalization, and
health metric calculations; some obsolete tests removed.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
computeSuccessAndNonSuccessRates,
|
|
sumErrors,
|
|
sumTotal,
|
|
sumWarnings,
|
|
toLogsBarChartData,
|
|
} from './ProjectUsage.metrics'
|
|
|
|
describe('ProjectUsage.metrics', () => {
|
|
const rows = [
|
|
{ timestamp: '2025-10-22T13:00:00Z', ok_count: 90, warning_count: 5, error_count: 5 },
|
|
{ timestamp: '2025-10-22T13:01:00Z', ok_count: 50, warning_count: 10, error_count: 0 },
|
|
]
|
|
|
|
it('toLogsBarChartData maps and coerces fields correctly', () => {
|
|
const data = toLogsBarChartData(rows)
|
|
expect(data).toHaveLength(2)
|
|
expect(data[0]).toEqual({
|
|
timestamp: '2025-10-22T13:00:00Z',
|
|
ok_count: 90,
|
|
warning_count: 5,
|
|
error_count: 5,
|
|
})
|
|
})
|
|
|
|
it('sum helpers compute totals correctly', () => {
|
|
const data = toLogsBarChartData(rows)
|
|
expect(sumTotal(data)).toBe(160)
|
|
expect(sumWarnings(data)).toBe(15)
|
|
expect(sumErrors(data)).toBe(5)
|
|
})
|
|
|
|
it('computeSuccessAndNonSuccessRates returns expected percentages', () => {
|
|
const data = toLogsBarChartData(rows)
|
|
const total = sumTotal(data)
|
|
const warns = sumWarnings(data)
|
|
const errs = sumErrors(data)
|
|
const { successRate, nonSuccessRate } = computeSuccessAndNonSuccessRates(total, warns, errs)
|
|
|
|
// success = 160 - (15 + 5) = 140 → 87.5%
|
|
expect(successRate).toBeCloseTo(87.5)
|
|
expect(nonSuccessRate).toBeCloseTo(12.5)
|
|
})
|
|
})
|