Skip to content

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

feat: add failed migration counts widget for auth report

TzeYiing608bb492240b
diff --git a/studio/components/interfaces/Reports/ReportWidget.tsx b/studio/components/interfaces/Reports/ReportWidget.tsx
index 09e03029f59..2594c10c646 100644
--- a/studio/components/interfaces/Reports/ReportWidget.tsx
+++ b/studio/components/interfaces/Reports/ReportWidget.tsx
@@ -4,11 +4,14 @@ import Panel from 'components/ui/Panel'
import { useRouter } from 'next/router'
import { BaseReportParams } from './Reports.types'
import { LogsEndpointParams } from '../Settings/Logs'
+import * as Tooltip from '@radix-ui/react-tooltip'
+import { IconHelpCircle } from '@supabase/ui'
export interface ReportWidgetProps<T = any> {
data: T[]
title: string
- description: string
+ description?: string
+ tooltip?: string
className?: string
renderer: (props: ReportWidgetProps) => React.ReactNode
params: BaseReportParams | LogsEndpointParams
@@ -19,11 +22,37 @@ const ReportWidget: React.FC<ReportWidgetProps> = (props) => {
const router = useRouter()
const { ref } = router.query
return (
- <Panel noMargin className={'pb-0 ' + props.className} bodyClassName="h-full" wrapWithLoading={false}>
+ <Panel
+ noMargin
+ className={'pb-0 ' + props.className}
+ bodyClassName="h-full"
+ wrapWithLoading={false}
+ >
<Panel.Content className="space-y-4">
<div className="flex flex-row items-start justify-between">
<div className="gap-2">
- <h3>{props.title}</h3>
+ <div className="flex flex-row gap-2">
+
+ <h3 className="w-full h-6">{props.title}</h3>{' '}
+ {props?.tooltip && (
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <IconHelpCircle className="text-scale-900" size="tiny" />
+ </Tooltip.Trigger>
+ <Tooltip.Content side="top">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 max-w-xs leading-none shadow',
+ 'border border-scale-200',
+ ].join(' ')}
+ >
+ <span className="text-xs text-scale-1200">{props.tooltip}</span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
+ )}
+ </div>
<p className="text-sm text-scale-1100">{props.description}</p>
</div>
<Dropdown
@@ -52,7 +81,7 @@ const ReportWidget: React.FC<ReportWidgetProps> = (props) => {
title="Actions..."
as="span"
type="text"
- icon={<IconMoreVertical className="text-scale-1100" size="small" />}
+ icon={<IconMoreVertical className="text-scale-1000" size="tiny" />}
></Button>
</Dropdown>
</div>
diff --git a/studio/components/interfaces/Reports/Reports.constants.ts b/studio/components/interfaces/Reports/Reports.constants.ts
index f4811451e16..bf67eb7c019 100644
--- a/studio/components/interfaces/Reports/Reports.constants.ts
+++ b/studio/components/interfaces/Reports/Reports.constants.ts
@@ -162,6 +162,16 @@ export const PRESET_CONFIG: Record<Presets, PresetConfig> = {
[Presets.AUTH]: {
title: 'Auth',
queries: {
+ failedMigrations: {
+ queryType: "logs",
+ sql: `
+select count(f.id)
+from auth_logs
+where json_value(f.event_message, "$.level") = "fatal"
+ and regexp_contains(f.event_message, "error executing migrations")
+limit 1
+`
+ },
dailyActiveUsers: {
queryType: 'logs',
sql: `
diff --git a/studio/components/interfaces/Reports/Statistic.tsx b/studio/components/interfaces/Reports/Statistic.tsx
new file mode 100644
index 00000000000..9f21c6feefc
--- /dev/null
+++ b/studio/components/interfaces/Reports/Statistic.tsx
@@ -0,0 +1,36 @@
+import React from 'react'
+
+interface Props {
+ value: string | number
+ startingValue?: string | number
+ prefix?: string
+ suffix?: string
+ valueFormatter?: (value: Props['value']) => string
+}
+
+const Statistic: React.FC<Props> = ({ prefix, suffix, value, startingValue }) => {
+ const isNumber = typeof value === 'number' && !Number.isNaN(value)
+ const percentageChange =
+ startingValue && isNumber ? Number(startingValue) / Number(value) - 1 : null
+ return (
+ <div className="w-full">
+ <div className="flex flex-row justify-center">
+ <span>{prefix}</span>
+ <span className="text-3xl text-scale-1200">{value}</span>
+ <span>{suffix}</span>
+ </div>
+ {startingValue && (
+ <div>
+ {isNumber && percentageChange !== null && (
+ <span>
+ {Number(percentageChange * 100).toFixed(1)}
+ {percentageChange > 0 ? 'increase' : 'decrease'}
+ </span>
+ )}
+ </div>
+ )}
+ </div>
+ )
+}
+
+export default Statistic
diff --git a/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx b/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx
index 7fe04969540..282e4e09bd6 100644
--- a/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx
+++ b/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx
@@ -1,7 +1,17 @@
import { BarChart } from 'components/to-be-cleaned/Charts/ChartRenderer'
import { DATETIME_FORMAT } from '../Reports.constants'
import { ReportWidgetProps } from '../ReportWidget'
-
+import Statistic from '../Statistic'
+export const renderFailedMigrations = (
+ props: ReportWidgetProps<{
+ timestamp: string
+ count: number
+ }>
+) => {
+ console.log(props.data)
+ const count = props.data.length === 0 ? 0: props?.data?.[0]?.count
+ return <Statistic value={count} />
+}
export const renderCumulativeUsers = (
props: ReportWidgetProps<{
count: number
@@ -15,6 +25,7 @@ export const renderCumulativeUsers = (
data={props.data}
attribute="count"
label=""
+ minimalHeader
highlightedValue={total}
customDateFormat={DATETIME_FORMAT}
noDataMessage={'No confirmed users yet'}
@@ -36,6 +47,7 @@ export const renderNewUsers = (
data={props.data}
attribute="count"
label=""
+ minimalHeader
highlightedValue={sum}
customDateFormat={DATETIME_FORMAT}
noDataMessage={'No new user signups during this time period'}
diff --git a/studio/pages/project/[ref]/reports/auth.tsx b/studio/pages/project/[ref]/reports/auth.tsx
index 5e6c6781a79..42e22d60ade 100644
--- a/studio/pages/project/[ref]/reports/auth.tsx
+++ b/studio/pages/project/[ref]/reports/auth.tsx
@@ -11,6 +11,7 @@ import {
renderDailyActiveUsers,
renderNewUsers,
renderCumulativeUsers,
+ renderFailedMigrations,
} from 'components/interfaces/Reports/renderers/AuthRenderers'
export const AuthReport: NextPageWithLayout = () => {
@@ -21,15 +22,25 @@ export const AuthReport: NextPageWithLayout = () => {
const dailyActiveUsers = hooks.dailyActiveUsers()
const newUsers = hooks.newUsers()
const cumulativeUsers = hooks.cumulativeUsers()
+ const failedMigrations = hooks.failedMigrations()
const { isLoading, Layout } = usePresetReport([dailyActiveUsers, newUsers, cumulativeUsers])
return (
<Layout title={config.title}>
- <div className="grid lg:grid-cols-4 gap-4">
+ <div className="grid lg:grid-cols-6 gap-4">
<ReportWidget
isLoading={isLoading}
- params={cumulativeUsers[0].params}
+ params={failedMigrations[0].params}
className="col-span-2 col-start-1"
+ title="Failed GoTrue Migrations"
+ tooltip="Failed migrations may cause issues with user authentication."
+ data={failedMigrations[0].logData!}
+ renderer={renderFailedMigrations}
+ />
+ <ReportWidget
+ isLoading={isLoading}
+ params={cumulativeUsers[0].params}
+ className="col-span-3 col-start-1"
title="Users Over Time"
description="Cumulative count of confirmed users"
data={cumulativeUsers[0].data!}
@@ -38,7 +49,7 @@ export const AuthReport: NextPageWithLayout = () => {
<ReportWidget
isLoading={isLoading}
params={newUsers[0].params}
- className="col-span-2 col-start-3"
+ className="col-span-3 col-start-4"
title="Daily New Users"
description="The daily count of new user signups"
data={newUsers[0].data!}
@@ -47,7 +58,7 @@ export const AuthReport: NextPageWithLayout = () => {
<ReportWidget
isLoading={isLoading}
params={dailyActiveUsers[0].params}
- className="col-span-4 col-start-1"
+ className="col-span-6 col-start-1"
title="Daily Active Users"
description="The daily count of active authenticated users"
data={dailyActiveUsers[0].logData!}