The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
standardize db report (#37198)
Francesco Sansalvadore097ded6906aa
diff --git a/apps/studio/components/interfaces/Reports/ReportChart.tsx b/apps/studio/components/interfaces/Reports/ReportChart.tsxindex 5b9a4b38cdc..bce4f874d2c 100644--- a/apps/studio/components/interfaces/Reports/ReportChart.tsx+++ b/apps/studio/components/interfaces/Reports/ReportChart.tsx@@ -14,7 +14,7 @@ import type { UpdateDateRange } from 'pages/project/[ref]/reports/database'import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'import Link from 'next/link'-import { Button } from 'ui'+import { Button, cn } from 'ui'import Panel from 'components/ui/Panel'import { useRef, useState } from 'react'@@ -27,6 +27,8 @@ const ReportChart = ({functionIds,orgPlanId,isLoading,+ availableIn,+ className,}: {chart: anystartDate: string@@ -36,6 +38,8 @@ const ReportChart = ({functionIds?: string[]orgPlanId?: stringisLoading?: boolean+ availableIn?: string[]+ className?: string}) => {const org = useSelectedOrganization()const [isHoveringUpgrade, setIsHoveringUpgrade] = useState(false)@@ -105,11 +109,16 @@ const ReportChart = ({if (!isAvailable && !isLoading) {return (- <Panel title={<h2 className="text-sm">{chart.label}</h2>} className="h-[260px] relative">+ <Panel+ title={<h2 className="text-sm">{chart.label}</h2>}+ className={cn('h-[260px] relative', className)}+ ><div className="z-10 flex flex-col items-center justify-center space-y-2 h-full absolute top-0 left-0 w-full bg-surface-100/70 backdrop-blur-md"><h2 className="">{chart.label}</h2><p className="text-sm text-foreground-light">- This chart is available from Pro plan and above+ This chart is available from{' '}+ <span className="capitalize">{!!availableIn?.length ? availableIn[0] : 'Pro'}</span>{' '}+ plan and above</p><ButtonasChild@@ -118,7 +127,8 @@ const ReportChart = ({onMouseLeave={() => setIsHoveringUpgrade(false)}><Link href={`/org/${org?.slug}/billing?panel=subscriptionPlan&source=reports`}>- Upgrade to Pro+ Upgrade to{' '}+ <span className="capitalize">{!!availableIn?.length ? availableIn[0] : 'Pro'}</span></Link></Button></div>diff --git a/apps/studio/components/ui/Charts/ComposedChart.tsx b/apps/studio/components/ui/Charts/ComposedChart.tsxindex 4c5fad6520a..3dd9ae6aa3b 100644--- a/apps/studio/components/ui/Charts/ComposedChart.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.tsx@@ -233,7 +233,9 @@ export default function ComposedChart({const stackedAttributes = chartData.filter((att) => !att.name.includes('max'))const isPercentage = format === '%'- const isRamChart = chartData?.some((att: any) => att.name.toLowerCase().includes('ram_'))+ const isRamChart =+ !chartData?.some((att: any) => att.name.toLowerCase() === 'ram_usage') &&+ chartData?.some((att: any) => att.name.toLowerCase().includes('ram_'))const isDiskSpaceChart = chartData?.some((att: any) =>att.name.toLowerCase().includes('disk_space_'))diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsxindex d22f69fed6a..09aaaef44a4 100644--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx@@ -144,7 +144,9 @@ const CustomTooltip = ({const maxValueData =maxValueAttribute && payload?.find((p: any) => p.dataKey === maxValueAttribute.attribute)const maxValue = maxValueData?.value- const isRamChart = payload?.some((p: any) => p.dataKey.toLowerCase().includes('ram_'))+ const isRamChart =+ !payload?.some((p: any) => p.dataKey.toLowerCase() === 'ram_usage') &&+ payload?.some((p: any) => p.dataKey.toLowerCase().includes('ram_'))const isDBSizeChart =payload?.some((p: any) => p.dataKey.toLowerCase().includes('disk_fs_')) ||payload?.some((p: any) => p.dataKey.toLowerCase().includes('pg_database_size'))diff --git a/apps/studio/data/reports/database-charts.ts b/apps/studio/data/reports/database-charts.tsindex e8e91cdc375..33a5fff2ed6 100644--- a/apps/studio/data/reports/database-charts.ts+++ b/apps/studio/data/reports/database-charts.ts@@ -4,28 +4,187 @@ import { Organization } from 'types'import { Project } from '../projects/project-detail-query'import { ReportAttributes } from 'components/ui/Charts/ComposedChart.utils'-export const getReportAttributes = (isFreePlan: boolean) => [- { id: 'ram_usage', label: 'Memory usage', hide: false },- { id: 'avg_cpu_usage', label: 'Average CPU usage', hide: false },- { id: 'max_cpu_usage', label: 'Max CPU usage', hide: false },- { id: 'disk_iops_write', label: 'Disk IOps write', hide: false },- { id: 'disk_iops_read', label: 'Disk IOps read', hide: false },- {- id: 'pg_stat_database_num_backends',- label: 'Pooler to database connections',- hide: false,- },- {- id: 'supavisor_connections_active',- label: 'Client to Shared Pooler connections',- hide: false,- },- {- id: 'client_connections_pgbouncer',- label: 'Client to Dedicated Pooler connections',- hide: isFreePlan,- },-]+export const getReportAttributes = (org: Organization, project: Project): ReportAttributes[] => {+ const isFreePlan = org?.plan?.id === 'free'+ const computeSize = project?.infra_compute_size || 'medium'++ return [+ {+ id: 'ram-usage',+ label: 'Memory usage',+ availableIn: ['free', 'pro'],+ hide: false,+ showTooltip: false,+ showLegend: false,+ hideChartType: false,+ defaultChartStyle: 'bar',+ showMaxValue: false,+ showGrid: false,+ syncId: 'database-reports',+ valuePrecision: 0,+ format: '%',+ attributes: [+ {+ attribute: 'ram_usage',+ provider: 'infra-monitoring',+ label: 'Memory usage',+ format: '%',+ tooltip: 'RAM usage by the database',+ },+ ],+ },+ {+ id: 'avg_cpu_usage',+ label: 'CPU usage',+ syncId: 'database-reports',+ format: '%',+ valuePrecision: 2,+ availableIn: ['free', 'pro'],+ hide: false,+ showTooltip: false,+ showLegend: false,+ showMaxValue: false,+ showGrid: false,+ hideChartType: false,+ defaultChartStyle: 'bar',+ attributes: [+ {+ attribute: 'avg_cpu_usage',+ provider: 'infra-monitoring',+ label: 'Average CPU usage',+ format: '%',+ tooltip: 'Average CPU usage',+ },+ ],+ },+ {+ id: 'disk-iops',+ label: 'Disk Input/Output operations per second (IOPS)',+ syncId: 'database-reports',+ availableIn: ['free', 'pro'],+ hide: false,+ showTooltip: true,+ valuePrecision: 2,+ showLegend: true,+ hideChartType: false,+ showGrid: true,+ showMaxValue: false,+ YAxisProps: {+ width: 35,+ tickFormatter: (value: any) => numberFormatter(value, 2),+ },+ defaultChartStyle: 'line',+ docsUrl: 'https://supabase.com/docs/guides/platform/compute-and-disk#compute-size',+ attributes: [+ {+ attribute: 'disk_iops_write',+ provider: 'infra-monitoring',+ label: 'write IOPS',+ tooltip:+ 'Number of write operations per second. High values indicate frequent data writes, logging, or transaction activity',+ },+ {+ attribute: 'disk_iops_read',+ provider: 'infra-monitoring',+ label: 'read IOPS',+ tooltip:+ 'Number of read operations per second. High values suggest frequent disk reads due to queries or poor caching',+ },+ {+ attribute: 'disk_iops_max',+ provider: 'reference-line',+ label: 'Max IOPS',+ value: getIOPSLimits(computeSize),+ tooltip:+ 'Maximum IOPS (Input/Output Operations Per Second) for your current compute size',+ isMaxValue: true,+ },+ ],+ },+ {+ id: 'disk-io-usage',+ label: 'Disk IO Usage',+ syncId: 'database-reports',+ availableIn: ['team', 'enterprise'],+ hide: false,+ format: '%',+ attributes: [],+ },+ {+ id: 'database-connections',+ label: 'Database connections',+ valuePrecision: 0,+ availableIn: ['free', 'pro'],+ hide: false,+ showTooltip: false,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ showGrid: false,+ defaultChartStyle: 'bar',+ attributes: [+ {+ attribute: 'pg_stat_database_num_backends',+ provider: 'infra-monitoring',+ label: 'Pooler to database connections',+ tooltip: 'Number of pooler connections to the database',+ },+ ],+ },+ {+ id: 'supavisor-connections',+ label: 'Shared Pooler connections',+ syncId: 'database-reports',+ valuePrecision: 0,+ availableIn: ['free', 'pro'],+ hide: false,+ showTooltip: false,+ showLegend: false,+ showMaxValue: false,+ showGrid: false,+ hideChartType: false,+ defaultChartStyle: 'bar',+ attributes: [+ {+ attribute: 'supavisor_connections_active',+ provider: 'infra-monitoring',+ label: 'Client to Shared Pooler connections',+ tooltip: 'Active connections from clients to the shared pooler',+ },+ ],+ },+ {+ id: 'pgbouncer-connections',+ label: 'Dedicated Pooler connections',+ syncId: 'database-reports',+ valuePrecision: 0,+ availableIn: ['pro', 'team'],+ hide: false,+ showTooltip: false,+ showLegend: false,+ showMaxValue: false,+ showGrid: false,+ hideChartType: false,+ defaultChartStyle: 'bar',+ attributes: [+ {+ attribute: 'client_connections_pgbouncer',+ provider: 'infra-monitoring',+ label: 'Client to Dedicated Pooler connections',+ tooltip: 'PgBouncer connections',+ },+ ],+ },+ {+ id: 'disk-size',+ label: 'Disk Usage',+ syncId: 'database-reports',+ availableIn: ['team', 'enterprise'],+ hide: false,+ attributes: [],+ },+ ]+}export const getReportAttributesV2: (org: Organization, project: Project) => ReportAttributes[] = (org,@@ -40,7 +199,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep{id: 'ram-usage',label: 'Memory usage',- availableIn: ['free', 'pro', 'team'],+ availableIn: ['team', 'enterprise'],hide: false,showTooltip: true,showLegend: true,@@ -84,7 +243,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => RepsyncId: 'database-reports',format: '%',valuePrecision: 2,- availableIn: ['free', 'pro', 'team'],+ availableIn: ['team', 'enterprise'],hide: false,showTooltip: true,showLegend: true,@@ -150,7 +309,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repid: 'disk-iops',label: 'Disk Input/Output operations per second (IOPS)',syncId: 'database-reports',- availableIn: ['free', 'pro', 'team'],+ availableIn: ['team', 'enterprise'],hide: false,showTooltip: true,valuePrecision: 2,@@ -194,7 +353,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repid: 'disk-io-usage',label: 'Disk IO Usage',syncId: 'database-reports',- availableIn: ['pro', 'team'],+ availableIn: ['team', 'enterprise'],hide: false,showTooltip: true,format: '%',@@ -222,7 +381,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repid: 'client-connections',label: 'Database connections',valuePrecision: 0,- availableIn: ['free', 'pro', 'team'],+ availableIn: ['team', 'enterprise'],hide: !isFreePlan, // [Jordi] Paid plans can see grouped client connections instead, so this chart is not needed for them. See below.showTooltip: true,showLegend: false,@@ -252,7 +411,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repid: 'client-connections',label: 'Direct Database Client Connections Grouped',valuePrecision: 0,- availableIn: ['pro', 'team'],+ availableIn: ['team', 'enterprise'],hide: isFreePlan, // [Jordi] Paid plans can see grouped client connections instead, so this chart is not needed for them. See above.showTooltip: true,showLegend: true,diff --git a/apps/studio/pages/project/[ref]/reports/database.tsx b/apps/studio/pages/project/[ref]/reports/database.tsxindex e0a4c9faffd..cabcd5d2d49 100644--- a/apps/studio/pages/project/[ref]/reports/database.tsx+++ b/apps/studio/pages/project/[ref]/reports/database.tsx@@ -43,6 +43,7 @@ import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'import type { NextPageWithLayout } from 'types'import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'+import ReportChart from '../../../../components/interfaces/Reports/ReportChart'const DatabaseReport: NextPageWithLayout = () => {return (@@ -79,10 +80,9 @@ const DatabaseUsage = () => {handleDatePickerChange,} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)- const isFreePlan = !isOrgPlanLoading && orgPlan?.id === 'free'const isTeamsOrEnterprisePlan =!isOrgPlanLoading && (orgPlan?.id === 'team' || orgPlan?.id === 'enterprise')- const showChartsV2 = isReportsV2 || isTeamsOrEnterprisePlan+ const showChartsV2 = false || isTeamsOrEnterprisePlanconst state = useDatabaseSelectorStateSnapshot()const queryClient = useQueryClient()@@ -108,7 +108,7 @@ const DatabaseUsage = () => {},})- const REPORT_ATTRIBUTES = getReportAttributes(isFreePlan)+ const REPORT_ATTRIBUTES = getReportAttributes(org!, project!)const REPORT_ATTRIBUTES_V2 = getReportAttributesV2(org!, project!)const { isLoading: isUpdatingDiskSize } = useProjectDiskResizeMutation({@@ -151,6 +151,20 @@ const DatabaseUsage = () => {)})})+ } else {+ REPORT_ATTRIBUTES.forEach((chart: any) => {+ chart.attributes.forEach((attr: any) => {+ queryClient.invalidateQueries(+ analyticsKeys.infraMonitoring(ref, {+ attribute: attr.attribute,+ startDate: period_start.date,+ endDate: period_end.date,+ interval,+ databaseIdentifier: state.selectedDatabaseId,+ })+ )+ })+ })}if (isReplicaSelected) {queryClient.invalidateQueries(@@ -229,44 +243,59 @@ const DatabaseUsage = () => {</>}>- {showChartsV2 ? (- selectedDateRange &&- REPORT_ATTRIBUTES_V2.filter((chart) => !chart.hide).map((chart) => (- <ComposedChartHandler- key={chart.id}- {...chart}- attributes={chart.attributes as MultiAttribute[]}- interval={selectedDateRange.interval}- startDate={selectedDateRange?.period_start?.date}- endDate={selectedDateRange?.period_end?.date}- updateDateRange={updateDateRange}- defaultChartStyle={chart.defaultChartStyle as 'line' | 'bar' | 'stackedAreaLine'}- showMaxValue={- chart.id === 'client-connections' || chart.id === 'pgbouncer-connections'- ? true- : chart.showMaxValue- }- />- ))- ) : (- <Panel title={<h2>Database health</h2>}>- <Panel.Content className="grid grid-cols-1 gap-4">- {selectedDateRange &&- REPORT_ATTRIBUTES.filter((attr) => !attr.hide).map((attr) => (- <ChartHandler- key={attr.id}- {...attr}- provider="infra-monitoring"- attribute={attr.id}- label={attr.label}+ {selectedDateRange &&+ orgPlan?.id &&+ (showChartsV2+ ? REPORT_ATTRIBUTES_V2.filter((chart) => !chart.hide).map((chart) => (+ <ComposedChartHandler+ key={chart.id}+ {...chart}+ attributes={chart.attributes as MultiAttribute[]}+ interval={selectedDateRange.interval}+ startDate={selectedDateRange?.period_start?.date}+ endDate={selectedDateRange?.period_end?.date}+ updateDateRange={updateDateRange}+ defaultChartStyle={chart.defaultChartStyle as 'line' | 'bar' | 'stackedAreaLine'}+ showMaxValue={+ chart.id === 'client-connections' || chart.id === 'pgbouncer-connections'+ ? true+ : chart.showMaxValue+ }+ />+ ))+ : REPORT_ATTRIBUTES.filter((chart) => !chart.hide).map((chart, i) =>+ chart.availableIn?.includes(orgPlan?.id) ? (+ <ComposedChartHandler+ key={chart.id}+ {...chart}+ attributes={chart.attributes as MultiAttribute[]}interval={selectedDateRange.interval}startDate={selectedDateRange?.period_start?.date}endDate={selectedDateRange?.period_end?.date}+ updateDateRange={updateDateRange}+ defaultChartStyle={+ chart.defaultChartStyle as 'line' | 'bar' | 'stackedAreaLine'+ }+ showMaxValue={+ chart.id === 'client-connections' || chart.id === 'pgbouncer-connections'+ ? true+ : chart.showMaxValue+ }/>- ))}- </Panel.Content>- </Panel>- )}+ ) : (+ <ReportChart+ key={`${chart.id}-${i}`}+ chart={chart}+ className="!mb-0"+ interval={selectedDateRange.interval}+ startDate={selectedDateRange?.period_start?.date}+ endDate={selectedDateRange?.period_end?.date}+ updateDateRange={updateDateRange}+ orgPlanId={orgPlan?.id}+ availableIn={chart.availableIn}+ />+ )+ ))}{selectedDateRange && isReplicaSelected && (<Panel title="Replica Information"><Panel.Content>