mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
The edge function detail layout is now breadcrumbs plus tabs (`PageNav`), without the page header, so tabs like Logs and Code get the full height below the tabs. The function name, invoke URL and last deploy details move into a header on the Overview tab, which also holds the chart period selector. Both the new and legacy Overview render it, and both now default to a 1 hour period instead of 15 minutes. The Overview sections (invocations, errors, performance and usage) now sit in one default-width `PageContainer` instead of each nesting a full-width one, and the invocations chart moves into a chart card. Invocations has no section heading, since it's the headline metric right below the page header. Both overview versions use the same chart periods. Sparse chart data is filled only between returned API buckets, avoiding synthetic zeros outside the reported range. Chart navigation uses the full rolling period, including a full day for the 1 day option. The selector shows a checkmark for the selected period, and the header announces loaded details. Self-hosted Studio retains a Copy URL action in the detail toolbar because it has no Overview tab. This layer doesn't depend on the logs changes below it. **Heads-up:** the header now only appears on Overview. Code, Details, Invocations and Logs show breadcrumbs and tabs only. This change isn't behind a flag. ### How to test 1. Open an edge function's Overview. The header shows the name, URL (with copy) and last deploy hover card, and the period selector sits in the header with 1 hour selected. 2. Switch through the other tabs. Breadcrumbs and tabs stay sticky, and there's no header. 3. With the `edgeFunctionsOverview` flag off, the legacy Overview renders with the same header. ### Validation - 104 focused tests pass with retries disabled and shuffled order (seed 50968). New tests cover both overview versions, period changes, empty results, header loading and copying, and self-hosted URL copying. Test names describe observable behavior. - 12 targeted regression mutations were detected and restored; the selected-indicator mutation was repeated after the visual alignment fix. - Browser QA on the staging preview for `3d055c0dc4` covers the header and deploy details, copied URL, period changes, all detail tabs, sticky navigation, the legacy overview, and empty results. Temporary local flag overrides were removed. The final test-only commit `5af6a2896b` has identical production code; its matching preview also passed header, URL-copy, period-switching, and Settings smoke checks. - Independent code review and changed-file formatting checks pass. All 40 executed CI checks pass on `5af6a2896b`, including TypeScript/lint, unit tests, Next.js and TanStack E2E tests, and builds. All six review threads are resolved. ### Stack Merge in order: 1. #50953 — reusable logs table building blocks 2. #50954 — function-scoped unified logs queries 3. #50955 — slimmer function detail layout, header on Overview 4. #50957 — Invocations merged into a function-scoped Logs tab 5. #50958 — Overview errors in the shared logs table 6. #52281 — remove the legacy Overview --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jordi Enric <jordi.err@gmail.com>
273 lines
8.7 KiB
TypeScript
273 lines
8.7 KiB
TypeScript
import dayjs from 'dayjs'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
EDGE_FUNCTION_CHART_INTERVALS,
|
|
formatChartTimestamp,
|
|
formatMetric,
|
|
formatRate,
|
|
formatReferenceDelta,
|
|
getChartEmptyStateCopy,
|
|
getChartTimeRangeLabels,
|
|
getExecutionMetrics,
|
|
getInvocationChartData,
|
|
getInvocationChartNavigationUrl,
|
|
getInvocationTotals,
|
|
getInvocationUpdateAnnotation,
|
|
getMemoryTooltipDetail,
|
|
getRollingTimeRange,
|
|
getUsageMetrics,
|
|
toEdgeFunctionChartData,
|
|
type EdgeFunctionChartRawDatum,
|
|
} from './EdgeFunctionOverview.utils'
|
|
|
|
describe('Edge function overview chart summaries', () => {
|
|
it('counts every invocation status and groups redirects and client errors as warnings', () => {
|
|
const chartData = toEdgeFunctionChartData([
|
|
{
|
|
timestamp: '2026-03-20T10:00:00.000Z',
|
|
success_count: 10,
|
|
redirect_count: 2,
|
|
client_err_count: 1,
|
|
server_err_count: 3,
|
|
},
|
|
{
|
|
timestamp: '2026-03-20T10:15:00.000Z',
|
|
success_count: '4',
|
|
redirect_count: '1',
|
|
client_err_count: '0',
|
|
server_err_count: '2',
|
|
},
|
|
] satisfies EdgeFunctionChartRawDatum[])
|
|
const data = getInvocationChartData(chartData)
|
|
|
|
expect(data).toEqual([
|
|
{
|
|
timestamp: '2026-03-20T10:00:00.000Z',
|
|
ok_count: 10,
|
|
warning_count: 3,
|
|
error_count: 3,
|
|
},
|
|
{
|
|
timestamp: '2026-03-20T10:15:00.000Z',
|
|
ok_count: 4,
|
|
warning_count: 1,
|
|
error_count: 2,
|
|
},
|
|
])
|
|
|
|
expect(chartData[1]).toEqual({
|
|
timestamp: '2026-03-20T10:15:00.000Z',
|
|
success_count: 4,
|
|
redirect_count: 1,
|
|
client_err_count: 0,
|
|
server_err_count: 2,
|
|
avg_execution_time: 0,
|
|
max_execution_time: 0,
|
|
avg_cpu_time_used: 0,
|
|
max_cpu_time_used: 0,
|
|
avg_memory_used: 0,
|
|
avg_heap_memory_used: 0,
|
|
avg_external_memory_used: 0,
|
|
})
|
|
|
|
expect(getInvocationTotals(data)).toEqual({
|
|
totalInvocationCount: 23,
|
|
totalWarningCount: 4,
|
|
totalErrorCount: 5,
|
|
})
|
|
})
|
|
|
|
it('labels the first and last chart timestamps for the selected period', () => {
|
|
expect(
|
|
getChartTimeRangeLabels(
|
|
[{ timestamp: '2026-03-20T10:00:00.000Z' }, { timestamp: '2026-03-20T11:00:00.000Z' }],
|
|
'MMM D, h:mma'
|
|
)
|
|
).toEqual({
|
|
start: dayjs('2026-03-20T10:00:00.000Z').format('MMM D, h:mma'),
|
|
end: dayjs('2026-03-20T11:00:00.000Z').format('MMM D, h:mma'),
|
|
})
|
|
expect(getChartTimeRangeLabels([], 'MMM D')).toBeUndefined()
|
|
expect(formatChartTimestamp('2026-03-20T10:00:00.000Z', 'MMM D, h:mma')).toBe(
|
|
dayjs('2026-03-20T10:00:00.000Z').format('MMM D, h:mma')
|
|
)
|
|
})
|
|
|
|
it('summarizes execution time, CPU time, and memory across the returned invocation buckets', () => {
|
|
const stats = [
|
|
{
|
|
timestamp: '2026-03-20T10:00:00.000Z',
|
|
success_count: 0,
|
|
redirect_count: 0,
|
|
client_err_count: 0,
|
|
server_err_count: 0,
|
|
avg_execution_time: 10,
|
|
max_execution_time: 18,
|
|
avg_cpu_time_used: 5,
|
|
max_cpu_time_used: 8,
|
|
avg_memory_used: 100,
|
|
avg_heap_memory_used: 75,
|
|
avg_external_memory_used: 25,
|
|
},
|
|
{
|
|
timestamp: '2026-03-20T10:15:00.000Z',
|
|
success_count: 0,
|
|
redirect_count: 0,
|
|
client_err_count: 0,
|
|
server_err_count: 0,
|
|
avg_execution_time: 30,
|
|
max_execution_time: 45,
|
|
avg_cpu_time_used: 15,
|
|
max_cpu_time_used: 20,
|
|
avg_memory_used: 200,
|
|
avg_heap_memory_used: 150,
|
|
avg_external_memory_used: 50,
|
|
},
|
|
]
|
|
|
|
expect(getExecutionMetrics(stats)).toEqual({
|
|
averageExecutionTime: 20,
|
|
maxExecutionTime: 45,
|
|
})
|
|
|
|
expect(getUsageMetrics(stats)).toEqual({
|
|
averageCpuTime: 10,
|
|
maxCpuTime: 20,
|
|
averageMemoryUsage: 150,
|
|
totalHeapMemory: 225,
|
|
totalExternalMemory: 75,
|
|
totalMemoryByType: 300,
|
|
})
|
|
})
|
|
|
|
it.each([
|
|
['an ISO string', '2026-03-20T10:16:30.000Z'],
|
|
['a numeric', new Date('2026-03-20T10:16:30.000Z').valueOf()],
|
|
])(
|
|
'marks the nearest invocation bucket to a deployment recorded with %s timestamp',
|
|
(_, updatedAt) => {
|
|
const annotation = getInvocationUpdateAnnotation({
|
|
updatedAt,
|
|
invocationChartData: [
|
|
{ timestamp: '2026-03-20T10:00:00.000Z', ok_count: 3, warning_count: 0, error_count: 0 },
|
|
{ timestamp: '2026-03-20T10:15:00.000Z', ok_count: 5, warning_count: 1, error_count: 1 },
|
|
{ timestamp: '2026-03-20T10:30:00.000Z', ok_count: 2, warning_count: 0, error_count: 0 },
|
|
],
|
|
windowStart: new Date('2026-03-20T09:45:00.000Z'),
|
|
windowEnd: new Date('2026-03-20T10:45:00.000Z'),
|
|
})
|
|
|
|
expect(annotation?.timestamp).toBe('2026-03-20T10:15:00.000Z')
|
|
expect(annotation?.position).toBeCloseTo(50)
|
|
expect(annotation?.updatedAt.toISOString()).toBe('2026-03-20T10:16:30.000Z')
|
|
}
|
|
)
|
|
|
|
it('hides deployments outside the selected chart period', () => {
|
|
const annotation = getInvocationUpdateAnnotation({
|
|
updatedAt: '2026-03-20T11:05:00.000Z',
|
|
invocationChartData: [
|
|
{ timestamp: '2026-03-20T10:00:00.000Z', ok_count: 3, warning_count: 0, error_count: 0 },
|
|
],
|
|
windowStart: new Date('2026-03-20T09:45:00.000Z'),
|
|
windowEnd: new Date('2026-03-20T10:45:00.000Z'),
|
|
})
|
|
|
|
expect(annotation).toBeUndefined()
|
|
})
|
|
|
|
it('hides the deployment marker when its timestamp cannot be read', () => {
|
|
const annotation = getInvocationUpdateAnnotation({
|
|
updatedAt: 'invalid',
|
|
invocationChartData: [
|
|
{ timestamp: '2026-03-20T10:00:00.000Z', ok_count: 3, warning_count: 0, error_count: 0 },
|
|
],
|
|
windowStart: new Date('2026-03-20T09:45:00.000Z'),
|
|
windowEnd: new Date('2026-03-20T10:45:00.000Z'),
|
|
})
|
|
|
|
expect(annotation).toBeUndefined()
|
|
})
|
|
|
|
it.each([
|
|
{
|
|
updatedAt: undefined,
|
|
invocationChartData: [
|
|
{ timestamp: '2026-03-20T10:00:00.000Z', ok_count: 3, warning_count: 0, error_count: 0 },
|
|
],
|
|
},
|
|
{ updatedAt: '2026-03-20T10:00:00.000Z', invocationChartData: [] },
|
|
])(
|
|
'hides the deployment marker until its timestamp and invocation data are available',
|
|
({ updatedAt, invocationChartData }) => {
|
|
const annotation = getInvocationUpdateAnnotation({
|
|
updatedAt,
|
|
invocationChartData,
|
|
windowStart: new Date('2026-03-20T09:45:00.000Z'),
|
|
windowEnd: new Date('2026-03-20T10:45:00.000Z'),
|
|
})
|
|
|
|
expect(annotation).toBeUndefined()
|
|
}
|
|
)
|
|
|
|
it.each([
|
|
{ period: '1hr', start: '2026-03-20T09:37:00.000Z' },
|
|
{ period: '1day', start: '2026-03-19T10:37:00.000Z' },
|
|
])('opens the full past $period through the current minute', ({ period, start }) => {
|
|
const interval = EDGE_FUNCTION_CHART_INTERVALS.find((item) => item.key === period)
|
|
if (!interval) throw new Error(`Unknown function chart period: ${period}`)
|
|
|
|
const [rollingStart, rollingEnd] = getRollingTimeRange(
|
|
interval,
|
|
new Date('2026-03-20T10:37:00.000Z')
|
|
)
|
|
|
|
expect(rollingStart.toISOString()).toBe(start)
|
|
expect(rollingEnd.toISOString()).toBe('2026-03-20T10:37:00.000Z')
|
|
})
|
|
|
|
it.each([
|
|
{ isUnifiedLogsEnabled: true, destination: 'logs' },
|
|
{ isUnifiedLogsEnabled: false, destination: 'invocations' },
|
|
])(
|
|
'opens $destination for the time around the clicked invocation bucket',
|
|
({ isUnifiedLogsEnabled, destination }) => {
|
|
const url = getInvocationChartNavigationUrl({
|
|
projectRef: 'project-ref',
|
|
functionSlug: 'function-slug',
|
|
isUnifiedLogsEnabled,
|
|
rangeStart: '2026-03-20T10:00:00.000Z',
|
|
rangeEnd: '2026-03-20T11:00:00.000Z',
|
|
clickedTimestamp: '2026-03-20T10:30:00.000Z',
|
|
})
|
|
|
|
expect(url).toBe(
|
|
`/project/project-ref/functions/function-slug/${destination}?its=2026-03-20T10%3A27%3A30.000Z&ite=2026-03-20T10%3A32%3A30.000Z`
|
|
)
|
|
}
|
|
)
|
|
|
|
it('shows metric units, invocation percentages, and differences from the average', () => {
|
|
expect(formatMetric(12.34, 'MB')).toBe('12.3MB')
|
|
expect(formatMetric(1234, 'ms')).toBe('1,234ms')
|
|
expect(formatRate(1, 4)).toBe('25%')
|
|
expect(formatReferenceDelta(110, 100)).toBe('10% above average')
|
|
expect(formatReferenceDelta(90, 100)).toBe('10% below average')
|
|
expect(formatReferenceDelta(100, 100)).toBe('At average')
|
|
})
|
|
|
|
it('explains empty charts, query failures, and heap and external memory usage', () => {
|
|
expect(getChartEmptyStateCopy('invocations', false, 'boom')).toEqual({
|
|
title: 'No data to show',
|
|
description: undefined,
|
|
})
|
|
expect(getChartEmptyStateCopy('CPU time', true, 'Request failed')).toEqual({
|
|
title: 'Unable to load CPU time',
|
|
description: 'Request failed',
|
|
})
|
|
expect(getMemoryTooltipDetail(12.34, 5.67)).toBe('Heap 12.3MB • External 5.7MB')
|
|
})
|
|
})
|