The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix db charts (#36803)
Francesco Sansalvadorec508348b07be
diff --git a/apps/studio/components/ui/Charts/ComposedChart.tsx b/apps/studio/components/ui/Charts/ComposedChart.tsxindex a1d501fd655..8401878a8e3 100644--- a/apps/studio/components/ui/Charts/ComposedChart.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.tsx@@ -163,33 +163,6 @@ export default function ComposedChart({color: CHART_COLORS.REFERENCE_LINE,}- const chartData =- data && !!data[0]- ? Object.entries(data[0])- ?.map(([key, value]) => ({- name: key,- value: value,- }))- .filter(- (att) =>- att.name !== 'timestamp' &&- att.name !== 'period_start' &&- att.name !== maxAttribute?.attribute &&- attributes.some((attr) => attr.attribute === att.name && attr.enabled !== false)- )- .map((att, index) => {- const attribute = attributes.find((attr) => attr.attribute === att.name)- return {- ...att,- color: attribute?.color- ? resolvedTheme?.includes('dark')- ? attribute.color.dark- : attribute.color.light- : STACKED_CHART_COLORS[index % STACKED_CHART_COLORS.length],- }- })- : []-const lastDataPoint = !!data[data.length - 1]? Object.entries(data[data.length - 1]).map(([key, value]) => ({@@ -230,6 +203,34 @@ export default function ComposedChart({chartHighlight?.coordinates.right &&chartHighlight?.coordinates.left !== chartHighlight?.coordinates.right+ const chartData =+ data && !!data[0]+ ? Object.entries(data[0])+ ?.map(([key, value]) => ({+ name: key,+ value: value,+ }))+ .filter(+ (att) =>+ att.name !== 'timestamp' &&+ att.name !== 'period_start' &&+ att.name !== maxAttribute?.attribute &&+ !referenceLines.map((a) => a.attribute).includes(att.name) &&+ attributes.some((attr) => attr.attribute === att.name && attr.enabled !== false)+ )+ .map((att, index) => {+ const attribute = attributes.find((attr) => attr.attribute === att.name)+ return {+ ...att,+ color: attribute?.color+ ? resolvedTheme?.includes('dark')+ ? attribute.color.dark+ : attribute.color.light+ : STACKED_CHART_COLORS[index % STACKED_CHART_COLORS.length],+ }+ })+ : []+const stackedAttributes = chartData.filter((att) => !att.name.includes('max'))const isPercentage = format === '%'const isRamChart = chartData?.some((att: any) => att.name.toLowerCase().includes('ram_'))diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsxindex 831f4b6153a..62c1c11f7ad 100644--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx@@ -141,12 +141,11 @@ const CustomTooltip = ({maxValueAttribute && payload?.find((p: any) => p.dataKey === maxValueAttribute.attribute)const maxValue = maxValueData?.valueconst isRamChart = payload?.some((p: any) => p.dataKey.toLowerCase().includes('ram_'))- const isDiskSpaceChart = payload?.some((p: any) =>- p.dataKey.toLowerCase().includes('disk_space_')- )- const isDBSizeChart = payload?.some((p: any) => p.dataKey.toLowerCase().includes('disk_fs_'))+ const isDBSizeChart =+ payload?.some((p: any) => p.dataKey.toLowerCase().includes('disk_fs_')) ||+ payload?.some((p: any) => p.dataKey.toLowerCase().includes('pg_database_size'))const isNetworkChart = payload?.some((p: any) => p.dataKey.toLowerCase().includes('network_'))- const shouldFormatBytes = isRamChart || isDiskSpaceChart || isDBSizeChart || isNetworkChart+ const shouldFormatBytes = isRamChart || isDBSizeChart || isNetworkChartconst attributesToIgnore =attributes?.filter((a) => a.omitFromTotal)?.map((a) => a.attribute) ?? []@@ -168,7 +167,7 @@ const CustomTooltip = ({const LabelItem = ({ entry }: { entry: any }) => {const attribute = attributes?.find((a: MultiAttribute) => a?.attribute === entry.name)- const percentage = ((entry.value / maxValue) * 100).toFixed(1)+ const percentage = ((entry.value / maxValue) * 100).toFixed(valuePrecision)const isMax = entry.dataKey === maxValueAttribute?.attributereturn (@@ -213,10 +212,7 @@ const CustomTooltip = ({<div className="flex items-end gap-1"><span className="text-base">{shouldFormatBytes- ? formatBytes(- isDBSizeChart ? (total as number) * 1024 * 1024 : (total as number),- valuePrecision- )+ ? formatBytes(total as number, valuePrecision): numberFormatter(total as number, valuePrecision)}{isPercentage ? '%' : ''}</span>diff --git a/apps/studio/data/reports/database-charts.ts b/apps/studio/data/reports/database-charts.tsindex 0d3be727670..addcce7073a 100644--- a/apps/studio/data/reports/database-charts.ts+++ b/apps/studio/data/reports/database-charts.ts@@ -214,83 +214,6 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep},],},- {- id: 'disk-size',- label: 'Disk Size',- syncId: 'database-reports',- valuePrecision: 2,- hide: false,- showTooltip: true,- showLegend: true,- showMaxValue: true,- showGrid: true,- YAxisProps: {- width: 65,- tickFormatter: (value: any) => formatBytes(value, 1),- },- hideChartType: false,- defaultChartStyle: 'line',- docsUrl: 'https://supabase.com/docs/guides/platform/database-size',- attributes: [- {- attribute: 'disk_fs_used_system',- provider: 'infra-monitoring',- format: 'bytes',- label: 'System',- tooltip: 'Reserved space for the system to ensure your database runs smoothly',- },- {- attribute: 'disk_fs_used_wal',- provider: 'infra-monitoring',- format: 'bytes',- label: 'WAL',- tooltip:- 'Disk usage by the write-ahead log. The usage depends on your WAL settings and the amount of data being written to the database',- },-- {- attribute: 'pg_database_size',- provider: 'infra-monitoring',- format: 'bytes',- label: 'Database',- tooltip: 'Disk usage by your database (tables, indexes, data, ...)',- },- {- attribute: 'disk_fs_size',- provider: 'infra-monitoring',- isMaxValue: true,- format: 'bytes',- label: 'Disk Size',- tooltip: 'Disk Size refers to the total space your project occupies on disk',- },- !isFreePlan &&- (isSpendCapEnabled- ? {- attribute: 'pg_database_size_percent_paid_spendCap',- provider: 'reference-line',- isReferenceLine: true,- strokeDasharray: '4 2',- label: 'Spend cap enabled',- value:- (project?.volumeSizeGb || getRecommendedDbSize(computeSize)) * 1024 * 1024 * 1024,- className: '[&_line]:!stroke-yellow-800 [&_line]:!opacity-100',- opacity: 1,- }- : {- attribute: 'pg_database_size_percent_paid',- provider: 'reference-line',- isReferenceLine: true,- label: '90% - Disk resize threshold',- className: '[&_line]:!stroke-yellow-800',- value:- (project?.volumeSizeGb || getRecommendedDbSize(computeSize)) *- 1024 *- 1024 *- 1024 *- 0.9, // reaching 90% of the disk size will trigger a disk resize https://supabase.com/docs/guides/platform/database-size- }),- ],- },{id: 'client-connections',label: 'Database client connections',@@ -405,6 +328,83 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep},],},+ {+ id: 'disk-size',+ label: 'Disk Usage',+ syncId: 'database-reports',+ valuePrecision: 2,+ hide: false,+ showTooltip: true,+ showLegend: true,+ showMaxValue: true,+ showGrid: true,+ YAxisProps: {+ width: 65,+ tickFormatter: (value: any) => formatBytes(value, 1),+ },+ hideChartType: false,+ defaultChartStyle: 'line',+ docsUrl: 'https://supabase.com/docs/guides/platform/database-size',+ attributes: [+ {+ attribute: 'disk_fs_used_system',+ provider: 'infra-monitoring',+ format: 'bytes',+ label: 'System',+ tooltip: 'Reserved space for the system to ensure your database runs smoothly',+ },+ {+ attribute: 'disk_fs_used_wal',+ provider: 'infra-monitoring',+ format: 'bytes',+ label: 'WAL',+ tooltip:+ 'Disk usage by the write-ahead log. The usage depends on your WAL settings and the amount of data being written to the database',+ },++ {+ attribute: 'pg_database_size',+ provider: 'infra-monitoring',+ format: 'bytes',+ label: 'Database',+ tooltip: 'Disk usage by your database (tables, indexes, data, ...)',+ },+ {+ attribute: 'disk_fs_size',+ provider: 'infra-monitoring',+ isMaxValue: true,+ format: 'bytes',+ label: 'Disk Size',+ tooltip: 'Disk Size refers to the total space your project occupies on disk',+ },+ !isFreePlan &&+ (isSpendCapEnabled+ ? {+ attribute: 'pg_database_size_percent_paid_spendCap',+ provider: 'reference-line',+ isReferenceLine: true,+ strokeDasharray: '4 2',+ label: 'Spend cap enabled',+ value:+ (project?.volumeSizeGb || getRecommendedDbSize(computeSize)) * 1024 * 1024 * 1024,+ className: '[&_line]:!stroke-yellow-800 [&_line]:!opacity-100',+ opacity: 1,+ }+ : {+ attribute: 'pg_database_size_percent_paid',+ provider: 'reference-line',+ isReferenceLine: true,+ label: '90% - Disk resize threshold',+ className: '[&_line]:!stroke-yellow-800',+ value:+ (project?.volumeSizeGb || getRecommendedDbSize(computeSize)) *+ 1024 *+ 1024 *+ 1024 *+ 0.9, // reaching 90% of the disk size will trigger a disk resize https://supabase.com/docs/guides/platform/database-size+ }),+ ],+ },]}