mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The last 60 minutes in Shared API Report collapses requests, errors, response speed, and network traffic into hourly points. This affects the Data API, Auth, and Realtime reports using ClickHouse. ## Fix Choose minute buckets for short ClickHouse report ranges and retain hourly buckets for longer ranges. Existing preset consumers keep their hourly defaults, and route summaries retain their current behavior. ## How to test - Open Observability → Data API and select Last 60 minutes. With requests across the hour, the charts should show minute-level data. - Switch to Last 24 hours and confirm the charts retain hourly grouping. - Apply a report filter and confirm the charts and route summaries respect it. - Repeat the short-range check on Auth or Realtime. Validation: 80 focused report tests passed with retries disabled and shuffled order. The ClickHouse boundary tests failed when the 60-minute cutoff was deliberately broken, then passed after restoring the fix. Studio typecheck and changed-file formatting passed. Independent review found no issues. The ClickHouse behavior was verified in the preview: minute buckets for Last 60 minutes on Data API and Auth, hourly buckets for Last 24 hours, and route filtering on charts and summaries. Fixes https://linear.app/supabase/issue/DEBUG-95
62 lines
2.6 KiB
TypeScript
62 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { PRESET_CONFIG } from '@/components/interfaces/Reports/Reports.constants'
|
|
import type { ReportFilterItem } from '@/components/interfaces/Reports/Reports.types'
|
|
import { getLogsSql } from '@/components/interfaces/Reports/Reports.utils'
|
|
import { getSharedAPIReportSql } from '@/components/interfaces/Reports/SharedAPIReport/SharedAPIReport.constants'
|
|
|
|
const timeSeries = ['totalRequests', 'errorCounts', 'responseSpeed', 'networkTraffic'] as const
|
|
const filters: ReportFilterItem[] = [
|
|
{ key: 'request.path', value: '/rest', compare: 'matches' },
|
|
{ key: 'request.method', value: 'GET', compare: 'is' },
|
|
]
|
|
const start = '2026-10-22T12:00:00.000Z'
|
|
|
|
describe('Shared API Report ClickHouse time buckets', () => {
|
|
it.each([
|
|
['last 10 minutes', '2026-10-22T12:10:00.000Z', 'minute'],
|
|
['last 60 minutes', '2026-10-22T13:00:00.000Z', 'minute'],
|
|
['last 60 minutes with clock drift', '2026-10-22T13:00:00.500Z', 'minute'],
|
|
['61 minutes', '2026-10-22T13:01:00.000Z', 'hour'],
|
|
['last 24 hours', '2026-10-23T12:00:00.000Z', 'hour'],
|
|
] as const)('uses the expected resolution for %s', (_label, end, granularity) => {
|
|
for (const name of timeSeries) {
|
|
const sql = getSharedAPIReportSql(name, filters, { start, end, useOtel: true })
|
|
const bucketFunction = granularity === 'minute' ? 'toStartOfMinute' : 'toStartOfHour'
|
|
const bucket = `toUnixTimestamp(${bucketFunction}(logs.timestamp)) * 1000000`
|
|
expect(sql).toContain(`${bucket} as timestamp`)
|
|
expect(sql).toContain(`group by ${bucket}`)
|
|
expect(sql).toContain(`order by ${bucket} asc`)
|
|
expect(sql).toContain("match(log_attributes['request.path'], '/rest')")
|
|
expect(sql).toContain("log_attributes['request.method'] = 'GET'")
|
|
if (name === 'errorCounts') {
|
|
expect(sql).toContain("toInt32OrZero(log_attributes['response.status_code']) >= 400")
|
|
}
|
|
}
|
|
})
|
|
|
|
it.each(['topRoutes', 'topErrorRoutes', 'topSlowRoutes'] as const)(
|
|
'keeps %s summaries independent of bucket size',
|
|
(name) => {
|
|
expect(
|
|
getSharedAPIReportSql(name, filters, {
|
|
start,
|
|
end: '2026-10-22T13:00:00.000Z',
|
|
useOtel: true,
|
|
})
|
|
).toBe(
|
|
getSharedAPIReportSql(name, filters, {
|
|
start,
|
|
end: '2026-10-23T12:00:00.000Z',
|
|
useOtel: true,
|
|
})
|
|
)
|
|
}
|
|
)
|
|
|
|
it.each(timeSeries)('preserves hourly defaults for other %s consumers', (name) => {
|
|
const sql = getLogsSql(PRESET_CONFIG.api.queries[name], filters, true)
|
|
expect(sql).toContain('toStartOfHour(logs.timestamp)')
|
|
})
|
|
})
|