mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
The Overview's "Errors in the last 24h" section now uses the Logs tab's queries (#50954) and the read-only `EmbeddedLogsTable` (#50953) instead of its own SQL and table. It previews the latest five errors since the last deploy, capped at 24h, shows "+N more" when there are more and links to the rest. It's behind the `edgeFunctionsOverview` flag, like the rest of the new Overview. - Rows have no multi-select checkbox. Clicking one opens it in the Logs tab with the same range and error filter, and "View logs" and "+N more" open the filtered list. - With the unified logs preview off, those links open the pre-unified Invocations tab (for invocation rows) or Logs tab (for runtime rows), using those tabs' own `its`/`ite`/`log` params. - "Explain with AI" and "Copy summary" send the previewed errors to the Assistant with the same prompt as selected logs on the Logs page. The prompt also notes how many errors were left out. - One count query, scoped to the function and unfiltered, gives both the error count behind "+N more" and the invocations since the deploy, from its level and log type facets. It replaces the hand-built invocation count SQL, so the section runs two queries instead of three. - The row query fetches only the five errors shown, through a new `pageSize` option on `useUnifiedLogsInfiniteQuery`. - The section uses the edge function preset from #50957, so it runs the Logs tab's scoped queries and shares its saved columns. - The custom error grouping and its SQL are removed. Net, the PR removes about 390 lines. ### How to test 1. With `edgeFunctionsOverview` on, open a function that has recent errors. You should see up to five rows without checkboxes, and "+N more" when there are more. 2. Click a row with the unified logs preview on. It opens the Logs tab with that log selected. Turn the preview off and click an invocation row and a runtime row. They open Invocations and Logs respectively. 3. Use Explain with AI and Copy summary and check the prompt. 4. For a function with no errors since the last deploy, the section shows the invocation count instead. ### Validation - MSW component tests: preview rows and "+N more", no checkboxes, the summary prompt, row links with the preview on and off, and the no-errors state. They also check the row query asks for five rows and that a single unfiltered count runs. `pageSize` and the facet count helper have unit tests. - Studio typecheck, lint ratchet, Prettier and knip pass on this layer. ### 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>
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import type { AlertErrorProps } from '@/components/ui/AlertError'
|
|
|
|
const NUMERIC_TIMESTAMP_PATTERN = /^\d+(?:\.\d+)?$/
|
|
|
|
export const toAlertError = (error: unknown): AlertErrorProps['error'] | undefined => {
|
|
if (typeof error === 'string') return { message: error }
|
|
|
|
if (error && typeof error === 'object') {
|
|
const message = (error as { message?: unknown }).message
|
|
if (typeof message === 'string') return { message }
|
|
}
|
|
|
|
return undefined
|
|
}
|
|
|
|
export const toIsoTimestamp = (value?: string | number) => {
|
|
if (value === undefined) return undefined
|
|
|
|
const normalizedValue = typeof value === 'string' ? value.trim() : value
|
|
if (normalizedValue === '') return undefined
|
|
|
|
const stringValue = String(normalizedValue)
|
|
const isNumericTimestamp = NUMERIC_TIMESTAMP_PATTERN.test(stringValue)
|
|
const date = (() => {
|
|
if (!isNumericTimestamp) return new Date(stringValue)
|
|
|
|
const numericValue = Number(stringValue)
|
|
if (!Number.isFinite(numericValue)) return new Date(NaN)
|
|
|
|
if (stringValue.length >= 16) return new Date(numericValue / 1000)
|
|
if (stringValue.length <= 10) return new Date(numericValue * 1000)
|
|
return new Date(numericValue)
|
|
})()
|
|
|
|
return Number.isNaN(date.valueOf()) ? undefined : date.toISOString()
|
|
}
|
|
|
|
export const SINCE_LAST_DEPLOY_MAX_RANGE_MS = 24 * 60 * 60 * 1000
|
|
|
|
export const getSinceLastDeployLogRange = (updatedAt?: string | number, now: Date = new Date()) => {
|
|
const isoTimestampStart = toIsoTimestamp(updatedAt)
|
|
if (!isoTimestampStart) return {}
|
|
|
|
const startDate = new Date(isoTimestampStart)
|
|
const normalizedNow = new Date(now)
|
|
const nowDate = Number.isNaN(normalizedNow.valueOf()) ? new Date() : normalizedNow
|
|
const endDate = new Date(Math.max(startDate.valueOf(), nowDate.valueOf()))
|
|
const earliestAllowedStart = endDate.valueOf() - SINCE_LAST_DEPLOY_MAX_RANGE_MS
|
|
|
|
return {
|
|
isoTimestampStart: new Date(Math.max(startDate.valueOf(), earliestAllowedStart)).toISOString(),
|
|
isoTimestampEnd: endDate.toISOString(),
|
|
}
|
|
}
|
|
|
|
export const getSinceLastDeployInvocationPhrase = (invocationCount: number) => {
|
|
const formattedCount = invocationCount.toLocaleString('en-US')
|
|
const invocationLabel = invocationCount === 1 ? 'invocation' : 'invocations'
|
|
|
|
return `${formattedCount} ${invocationLabel}`
|
|
}
|