Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add error routes table

TzeYiing3e76fe3fd6e4
diff --git a/studio/components/interfaces/Reports/Reports.constants.ts b/studio/components/interfaces/Reports/Reports.constants.ts
index 8bf1ab102cf..7ae7bdfc717 100644
--- a/studio/components/interfaces/Reports/Reports.constants.ts
+++ b/studio/components/interfaces/Reports/Reports.constants.ts
@@ -116,6 +116,31 @@ export const PRESET_CONFIG: Record<Presets, PresetConfig> = {
timestamp ASC
`,
},
+ topErrorRoutes: {
+ queryType: "logs",
+ sql: (filters)=> `
+ select
+ request.path as path,
+ request.method as method,
+ request.search as search,
+ response.status_code as status_code,
+ count(t.id) as count
+ from edge_logs t
+ cross join unnest(metadata) as m
+ cross join unnest(m.response) as response
+ cross join unnest(m.request) as request
+ cross join unnest(request.headers) as headers
+ where
+ response.status_code >= 400
+ ${generateRexepWhere(filters, false)}
+ group by
+ request.path, request.method, request.search, response.status_code
+ order by
+ count desc
+ limit
+ 5
+ `
+ },
responseSpeed: {
queryType: 'logs',
sql: (filters) => `
diff --git a/studio/components/interfaces/Reports/renderers/ApiRenderers.tsx b/studio/components/interfaces/Reports/renderers/ApiRenderers.tsx
index 1d52fb86020..8f53e9b6a3f 100644
--- a/studio/components/interfaces/Reports/renderers/ApiRenderers.tsx
+++ b/studio/components/interfaces/Reports/renderers/ApiRenderers.tsx
@@ -3,10 +3,14 @@ import BarChart from 'components/ui/Charts/BarChart'
import Table from 'components/to-be-cleaned/Table'
import {
jsonSyntaxHighlight,
+ ResponseCodeFormatter,
TextFormatter,
} from 'components/interfaces/Settings/Logs/LogsFormatters'
import { Button, Collapsible, IconChevronRight } from 'ui'
import { queryParamsToObject } from '../Reports.utils'
+import Loading from 'components/ui/Loading'
+import { LoadingLine } from 'ui/src/components/Command/LoadingLine'
+import LoadingOpacity from 'components/ui/LoadingOpacity'
export const renderTotalRequests = (
props: ReportWidgetProps<{
@@ -34,40 +38,41 @@ export const renderTotalRequests = (
export const renderTopApiRoutes = (
props: ReportWidgetRendererProps<{
method: string
+ // shown for error table but not all requests table
+ status_code?: number
path: string
search: string
count: number
}>
) => {
+ if (props.data.length === 0) return null
const headerClasses = '!text-xs !py-2 p-0 font-bold !bg-scale-400'
- const cellClasses = '!text-xs !py-2 truncate'
+ const cellClasses = '!text-xs !py-2'
return (
- <>
- <Table
- head={
- <>
- <Table.th className={headerClasses}>Request</Table.th>
- <Table.th className={headerClasses + ' text-right'}>Count</Table.th>
- </>
- }
- body={
- <>
- {props.data.map((datum) => (
- <>
- <Table.tr className="p-0">
- <Table.td className={[cellClasses].join(' ')}>
- <RouteTdContent {...datum} />
- </Table.td>
- <Table.td className={[cellClasses, 'text-right align-top'].join(' ')}>
- {datum.count}
- </Table.td>
- </Table.tr>
- </>
- ))}
- </>
- }
- />
- </>
+ <Table
+ head={
+ <>
+ <Table.th className={headerClasses}>Request</Table.th>
+ <Table.th className={headerClasses + ' text-right'}>Count</Table.th>
+ </>
+ }
+ body={
+ <>
+ {props.data.map((datum) => (
+ <>
+ <Table.tr className="p-0">
+ <Table.td className={[cellClasses].join(' ')}>
+ <RouteTdContent {...datum} />
+ </Table.td>
+ <Table.td className={[cellClasses, 'text-right align-top'].join(' ')}>
+ {datum.count}
+ </Table.td>
+ </Table.tr>
+ </>
+ ))}
+ </>
+ }
+ />
)
}
@@ -124,6 +129,7 @@ export const renderResponseSpeed = (
interface RouteTdContentProps {
method: string
+ status_code?: number
path: string
search: string
}
@@ -138,10 +144,22 @@ const RouteTdContent = (datum: RouteTdContentProps) => (
/>
</Button>
<TextFormatter className="w-10 h-4 text-center rounded bg-scale-500" value={datum.method} />
- <div>
+ {datum.status_code && (
+ <TextFormatter
+ className={`w-10 h-4 text-center rounded ${
+ datum.status_code >= 400
+ ? 'bg-orange-500'
+ : datum.status_code >= 300
+ ? 'bg-yellow-500'
+ : 'bg-green-500'
+ }`}
+ value={String(datum.status_code)}
+ />
+ )}
+ <div className=" truncate max-w-sm lg:max-w-lg">
<TextFormatter className="text-scale-1100" value={datum.path} />
<TextFormatter
- className="max-w-sm text-scale-900"
+ className="max-w-sm text-scale-900 truncate "
value={decodeURIComponent(datum.search || '')}
/>
</div>
diff --git a/studio/pages/project/[ref]/reports/api-overview.tsx b/studio/pages/project/[ref]/reports/api-overview.tsx
index 3af36737286..256b78fd484 100644
--- a/studio/pages/project/[ref]/reports/api-overview.tsx
+++ b/studio/pages/project/[ref]/reports/api-overview.tsx
@@ -75,6 +75,8 @@ export const ApiReport: NextPageWithLayout = () => {
tooltip="Error responses with 4XX or 5XX status codes"
data={report.data.errorCounts || []}
renderer={renderErrorCounts}
+ appendProps={{data: report.data.topErrorRoutes || [] }}
+ append={renderTopApiRoutes}
/>
<ReportWidget
isLoading={report.isLoading}
@@ -99,6 +101,7 @@ const useApiReport = () => {
const totalRequests = queryHooks.totalRequests()
const topRoutes = queryHooks.topRoutes()
const errorCounts = queryHooks.errorCounts()
+ const topErrorRoutes = queryHooks.topErrorRoutes()
const responseSpeed = queryHooks.responseSpeed()
const activeHooks = [totalRequests, topRoutes, errorCounts, responseSpeed]
const [filters, setFilters] = useState<ReportFilterItem[]>([])
@@ -137,6 +140,10 @@ const useApiReport = () => {
if (errorCounts[1].changeQuery) {
errorCounts[1].changeQuery(PRESET_CONFIG.api.queries.errorCounts.sql(filters))
}
+
+ if (topErrorRoutes[1].changeQuery) {
+ topErrorRoutes[1].changeQuery(PRESET_CONFIG.api.queries.topErrorRoutes.sql(filters))
+ }
if (responseSpeed[1].changeQuery) {
responseSpeed[1].changeQuery(PRESET_CONFIG.api.queries.responseSpeed.sql(filters))
}
@@ -159,12 +166,14 @@ const useApiReport = () => {
errorCounts: errorCounts[0].logData,
responseSpeed: responseSpeed[0].logData,
topRoutes: topRoutes[0].logData,
+ topErrorRoutes: topErrorRoutes[0].logData,
},
params: {
totalRequests: totalRequests[0].params,
errorCounts: errorCounts[0].params,
responseSpeed: responseSpeed[0].params,
topRoutes: topRoutes[0].params,
+ topErrorRoutes: topErrorRoutes[0].params,
},
mergeParams: handleSetParams,
filters,