mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem On the edge functions report, the Edge Function Status Codes chart shows a single combined count in its header, which is hard to read when responses include errors. The count would be more intuitive if it were broken down by status code. Resolves FE-4025. ## Solution Add **Warnings** (4xx) and **Errors** (5xx) counts to the right of the total in the chart header. This matches the request cards on the project home page, and uses the same warning and error definitions as the Logs Explorer filters. Per-code detail stays in the legend and tooltip. - The counts show the period totals by default and follow the hovered point, like the total does. - Charts opt in through a new optional `getHeaderStats` on `ReportConfig`, passed through `ReportChartV2` and `ComposedChart` to `ChartHeader`. Only the status codes report sets it, so other reports are unchanged. - The counts are summed from the existing pivoted status code series (`getStatusClassCounts`), so the log queries are untouched and both the BigQuery and otel paths work. - The chart's info tooltip now explains what warnings and errors mean. <img width="756" height="305" alt="Image" src="https://github.com/user-attachments/assets/808085f5-abd9-43ec-903b-dfa0d5e4f598" /> ## Review instructions 1. Run Studio and open **Observability → Edge Functions** for a project that has edge function traffic. 2. On the **Edge Function Status Codes** chart, check that **Warnings** and **Errors** appear next to the total, and that they match the 4xx and 5xx rows in the legend. 3. Hover the chart. The total, Warnings and Errors should all follow the hovered point, then return to the period totals when you move away. 4. Check that **Total Edge Function Invocations**, **Execution Time** and **Invocations by Region** show no Warnings or Errors. 5. Try a narrow viewport to check the header doesn't crowd the buttons. Unit tests cover the counting and the header (period totals, hover, and charts without stats): `pnpm exec vitest run components/interfaces/Reports components/ui/Charts`. ## Checklist Check all before review: - [ ] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
125 lines
4.2 KiB
TypeScript
125 lines
4.2 KiB
TypeScript
import { act, fireEvent, render, renderHook, screen } from '@testing-library/react'
|
|
import { Button, TooltipProvider } from 'ui'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
|
|
import { ChartHeader } from './ChartHeader'
|
|
import { memoryCommitmentThresholds } from './Charts.test-fixtures'
|
|
import { useChartHoverState } from './useChartHoverState'
|
|
import { edgeFunctionReports } from '@/data/reports/v2/edge-functions.config'
|
|
|
|
it.each(['Warning', 'Problematic', 'Severe'])(
|
|
'shows %s so the commitment risk is readable without opening details',
|
|
(expectedLabel) => {
|
|
const threshold = memoryCommitmentThresholds.find((zone) => zone.badgeLabel === expectedLabel)
|
|
if (!threshold) throw new Error(`Missing memory commitment threshold: ${expectedLabel}`)
|
|
|
|
render(
|
|
<TooltipProvider>
|
|
<ChartHeader
|
|
title="Memory commitment"
|
|
hideChartType
|
|
highlightedValue="6 GB"
|
|
thresholdZoneWarning={threshold}
|
|
/>
|
|
</TooltipProvider>
|
|
)
|
|
|
|
const badge = screen.getByLabelText(`Warning: ${threshold.label}`)
|
|
expect(badge).toHaveTextContent(expectedLabel)
|
|
expect(badge).toHaveAttribute('tabindex', '0')
|
|
}
|
|
)
|
|
|
|
describe('header stats', () => {
|
|
const SYNC_ID = 'edge-functions-test'
|
|
const statusCodesReport = edgeFunctionReports({
|
|
projectRef: 'default',
|
|
functions: [],
|
|
startDate: '2026-07-28T09:00:00.000Z',
|
|
endDate: '2026-07-28T09:02:00.000Z',
|
|
interval: '1m',
|
|
filters: { status_code: null, region: [], execution_time: null, functions: [] },
|
|
}).find((report) => report.id === 'execution-status-codes')
|
|
if (!statusCodesReport) throw new Error('Missing edge function status codes report')
|
|
|
|
const data = [
|
|
{ timestamp: '2026-07-28T09:00:00.000Z', '200': 10, '404': 2, '500': 1 },
|
|
{ timestamp: '2026-07-28T09:01:00.000Z', '200': 5, '404': 1, '500': 0 },
|
|
{ timestamp: '2026-07-28T09:02:00.000Z', '200': 0, '404': 0, '500': 1200 },
|
|
]
|
|
|
|
const HoverButton = ({ index }: { index: number }) => {
|
|
const { setHover } = useChartHoverState(SYNC_ID)
|
|
return <Button onClick={() => setHover(index)}>Hover point {index}</Button>
|
|
}
|
|
|
|
const renderHeader = () =>
|
|
render(
|
|
<TooltipProvider>
|
|
<HoverButton index={0} />
|
|
<HoverButton index={2} />
|
|
<ChartHeader
|
|
title="Edge Function Status Codes"
|
|
syncId={SYNC_ID}
|
|
data={data}
|
|
getHeaderStats={statusCodesReport.getHeaderStats}
|
|
/>
|
|
</TooltipProvider>
|
|
)
|
|
|
|
const getStat = (label: string) => screen.getByText(label).parentElement?.parentElement
|
|
|
|
afterEach(() => {
|
|
// Hover state is module-level, so clear it between tests
|
|
const { result } = renderHook(() => useChartHoverState(SYNC_ID))
|
|
act(() => result.current.clearHover())
|
|
})
|
|
|
|
it('shows warning and error counts for the whole period by default', () => {
|
|
renderHeader()
|
|
|
|
expect(getStat('Warnings')).toHaveTextContent('3')
|
|
expect(getStat('Errors')).toHaveTextContent('1,201')
|
|
})
|
|
|
|
it('shows the counts for the hovered point only', () => {
|
|
renderHeader()
|
|
|
|
fireEvent.click(screen.getByText('Hover point 0'))
|
|
expect(getStat('Warnings')).toHaveTextContent('2')
|
|
expect(getStat('Errors')).toHaveTextContent('1')
|
|
|
|
fireEvent.click(screen.getByText('Hover point 2'))
|
|
expect(getStat('Warnings')).toHaveTextContent('0')
|
|
expect(getStat('Errors')).toHaveTextContent('1,200')
|
|
})
|
|
|
|
it('shows the counts for the locally hovered point when hover is not synced', () => {
|
|
render(
|
|
<TooltipProvider>
|
|
<ChartHeader
|
|
title="Edge Function Status Codes"
|
|
syncId={SYNC_ID}
|
|
data={data}
|
|
focusedIndex={2}
|
|
getHeaderStats={statusCodesReport.getHeaderStats}
|
|
/>
|
|
</TooltipProvider>
|
|
)
|
|
|
|
expect(getStat('Warnings')).toHaveTextContent('0')
|
|
expect(getStat('Errors')).toHaveTextContent('1,200')
|
|
})
|
|
|
|
it('does not show stats when the chart does not provide them', () => {
|
|
render(
|
|
<TooltipProvider>
|
|
<ChartHeader title="Edge Function Invocations" syncId={SYNC_ID} data={data} />
|
|
</TooltipProvider>
|
|
)
|
|
|
|
expect(screen.queryByText('Warnings')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('Errors')).not.toBeInTheDocument()
|
|
})
|
|
})
|