mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 23:49:03 +00:00
## Problem The Warehouse report only shows the last hour. ## Solution Add date selection and refresh using the shared report controls. Respect the organisation’s log retention limits and the metrics API’s 30-day maximum. | After | | --- | | <img width="1688" height="1050" alt="CleanShot 2026-11-18 at 11 35 24@2x" src="https://github.com/user-attachments/assets/88267bf8-1054-480b-ac26-c0c2b58386bc" /> | | _The new controls._ | | <img width="2420" height="1028" alt="CleanShot 2026-11-18 at 11 47 52@2x" src="https://github.com/user-attachments/assets/383c06a0-5470-4748-b9a6-fe80647a1399" /> | | _The standard retention upgrade prompt follow tapping either of these on a Pro plan._ | ## Review instructions 1. Open the [Studio staging preview](https://studio-staging-git-dnywh-warehouse-metrics-range-supabase.vercel.app) and select a staging project with Warehouse access. 2. Open **Observability > Warehouse**, or `/project/<ref>/observability/warehouse` ([example](https://studio-staging-git-dnywh-warehouse-metrics-range-supabase.vercel.app/dashboard/project/yirnfrgkxmnqgexikhfc/observability/warehouse)). Change Last 60 minutes to Last 24 hours and check that the chart or no-data state reflects the selected period. 3. Refresh the report. Check that the selected period stays selected. 4. On a paid staging organisation, select a period beyond its log retention (for example, Last 14 days with 7-day retention). Check that the retention upgrade prompt appears and the current period stays selected. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
118 lines
3.4 KiB
TypeScript
118 lines
3.4 KiB
TypeScript
import dayjs from 'dayjs'
|
|
import { describe, expect, test } from 'vitest'
|
|
|
|
import { getWarehouseMetricsInterval, resolveWarehouseMetricsRange } from './WarehouseMetrics.range'
|
|
import { REPORTS_DATEPICKER_HELPERS } from '@/components/interfaces/Reports/Reports.constants'
|
|
|
|
describe('getWarehouseMetricsInterval', () => {
|
|
const interval = (hours: number) => {
|
|
const start = '2026-01-01T00:00:00.000Z'
|
|
return getWarehouseMetricsInterval(start, dayjs(start).add(hours, 'hour').toISOString())
|
|
}
|
|
|
|
test.each([
|
|
[0.5, '1m'],
|
|
[3, '1m'],
|
|
[3.01, '5m'],
|
|
[24, '5m'],
|
|
[24.5, '30m'],
|
|
[120, '30m'],
|
|
[121, '1h'],
|
|
[24 * 30, '1h'],
|
|
])('%s hours uses %s', (hours, expected) => {
|
|
expect(interval(hours)).toBe(expected)
|
|
})
|
|
})
|
|
|
|
describe('resolveWarehouseMetricsRange', () => {
|
|
const now = dayjs('2026-11-05T12:34:56.789Z')
|
|
const flooredNow = '2026-11-05T12:34:00.000Z'
|
|
const earliest = '2026-10-06T12:39:00.000Z'
|
|
|
|
test('leaves in-range values untouched', () => {
|
|
const start = '2026-11-05T11:34:56.789Z'
|
|
const end = '2026-11-05T12:30:10.000Z'
|
|
expect(resolveWarehouseMetricsRange({ start, end, now })).toEqual({
|
|
status: 'ok',
|
|
startDate: start,
|
|
endDate: end,
|
|
interval: '1m',
|
|
isClamped: false,
|
|
})
|
|
})
|
|
|
|
test('normalizes offsets to ISO without marking the range as clamped', () => {
|
|
const result = resolveWarehouseMetricsRange({
|
|
start: '2026-11-05T11:00:00+01:00',
|
|
end: '2026-11-05T11:30:00+01:00',
|
|
now,
|
|
})
|
|
expect(result).toMatchObject({
|
|
status: 'ok',
|
|
startDate: '2026-11-05T10:00:00.000Z',
|
|
endDate: '2026-11-05T10:30:00.000Z',
|
|
isClamped: false,
|
|
})
|
|
})
|
|
|
|
test('clamps a start older than 30 days and keeps the end', () => {
|
|
const end = '2026-11-05T12:00:00.000Z'
|
|
expect(resolveWarehouseMetricsRange({ start: '2026-09-01T00:00:00Z', end, now })).toEqual({
|
|
status: 'ok',
|
|
startDate: earliest,
|
|
endDate: end,
|
|
interval: '1h',
|
|
isClamped: true,
|
|
})
|
|
})
|
|
|
|
test('clamps an end in the future to the current minute', () => {
|
|
const start = '2026-11-05T11:34:00.000Z'
|
|
expect(resolveWarehouseMetricsRange({ start, end: '2026-11-05T13:00:00Z', now })).toEqual({
|
|
status: 'ok',
|
|
startDate: start,
|
|
endDate: flooredNow,
|
|
interval: '1m',
|
|
isClamped: true,
|
|
})
|
|
})
|
|
|
|
test('is out of range when the whole range is older than the window', () => {
|
|
expect(
|
|
resolveWarehouseMetricsRange({
|
|
start: '2026-08-01T00:00:00Z',
|
|
end: '2026-09-01T00:00:00Z',
|
|
now,
|
|
})
|
|
).toEqual({ status: 'out_of_range' })
|
|
})
|
|
|
|
test('is out of range when the whole range is in the future', () => {
|
|
expect(
|
|
resolveWarehouseMetricsRange({
|
|
start: '2026-11-06T00:00:00Z',
|
|
end: '2026-11-07T00:00:00Z',
|
|
now,
|
|
})
|
|
).toEqual({ status: 'out_of_range' })
|
|
})
|
|
|
|
test('is out of range when end is not after start', () => {
|
|
const same = '2026-11-05T10:00:00.000Z'
|
|
expect(resolveWarehouseMetricsRange({ start: same, end: same, now })).toEqual({
|
|
status: 'out_of_range',
|
|
})
|
|
})
|
|
|
|
test.each(REPORTS_DATEPICKER_HELPERS.map((helper) => [helper.text, helper] as const))(
|
|
'the "%s" date picker option resolves without clamping',
|
|
(_text, helper) => {
|
|
const result = resolveWarehouseMetricsRange({
|
|
start: helper.calcFrom(),
|
|
end: helper.calcTo(),
|
|
})
|
|
expect(result).toMatchObject({ status: 'ok', isClamped: false })
|
|
}
|
|
)
|
|
})
|