The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add scaffolding for db and storage size charts
Joshen Lim72cbbc11a68e
diff --git a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsxindex 00834ccb337..d5759b8660b 100644--- a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx+++ b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx@@ -1,24 +1,41 @@import { useParams } from 'common'import ShimmeringLoader from 'components/ui/ShimmeringLoader'-import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'-import dayjs from 'dayjs'-import { DATE_FORMAT } from 'lib/constants'import BarChart from './BarChart'-import { generateUsageData } from './Usage.utils'+import { useDailyStatsQuery } from 'data/analytics/daily-stats-query'+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'+import { useProjectUsageQuery } from 'data/usage/project-usage-query'+import SparkBar from 'components/ui/SparkBar'+import { formatBytes } from 'lib/helpers'+import { Button } from 'ui'const SizeAndCounts = () => {const { ref } = useParams()+ const { data: usage } = useProjectUsageQuery({ projectRef: ref })+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef: ref })+ const { current_period_start, current_period_end } = subscription?.billing ?? {}+ const startDate = new Date((current_period_start ?? 0) * 1000).toISOString()+ const endDate = new Date((current_period_end ?? 0) * 1000).toISOString()- const currentDate = 1682669326710 / 1000- const startDate = dayjs.unix(currentDate).subtract(24, 'hour').format(DATE_FORMAT)- const endDate = dayjs.unix(currentDate).format(DATE_FORMAT)+ // [JOSHEN TODO] Attribute needs to change after confirming with team o11y if this is implemented+ const { db_size } = usage ?? {}+ const dbSizeExcess = (db_size?.usage ?? 0) - (db_size?.limit ?? 0)+ const { data: dbSizeData, isLoading: isLoadingDbSizeData } = useDailyStatsQuery({+ projectRef: ref,+ attribute: 'total_rest_egress',+ interval: '1d',+ startDate,+ endDate,+ })- const { data: ioBudgetData, isLoading: isLoadingIoBudgetData } = useInfraMonitoringQuery({+ // [JOSHEN TODO] Attribute needs to change after confirming with team o11y if this is implemented+ const { storage_size } = usage ?? {}+ const storageSizeExcess = (storage_size?.usage ?? 0) - (storage_size?.limit ?? 0)+ const { data: storageSizeData, isLoading: isLoadingStorageSizeData } = useDailyStatsQuery({projectRef: ref,- attribute: 'disk_io_budget',+ attribute: 'total_storage_egress',+ interval: '1d',startDate,endDate,- interval: '1h',})return (@@ -31,24 +48,123 @@ const SizeAndCounts = () => {</div></div></div>++ {/* DATABASE SIZE - need to fix if no value yet (API will return period_start as 0 in first data point) */}+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="grid grid-cols-12">+ <div className="col-span-5">+ <div className="sticky top-16">+ <p className="text-base">Database size</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ <div className="col-span-7 space-y-6">+ <div className="space-y-2">+ <div className="flex items-center justify-between">+ <p className="text-sm">Database size per day</p>+ <Button type="default" size="tiny" onClick={() => {}}>+ Upgrade project+ </Button>+ </div>+ <SparkBar+ type="horizontal"+ barClass="bg-scale-1200"+ value={db_size?.usage ?? 0}+ max={db_size?.limit ?? 0}+ />+ <div>+ <div className="flex items-center justify-between border-b py-1">+ <p className="text-xs text-scale-1000">+ Included in {subscription?.tier.name.toLowerCase()}+ </p>+ <p className="text-xs">{formatBytes(db_size?.limit ?? 0)}</p>+ </div>+ <div className="flex items-center justify-between border-b py-1">+ <p className="text-xs text-scale-1000">Used</p>+ <p className="text-xs">{formatBytes(db_size?.usage ?? 0)}</p>+ </div>+ <div className="flex items-center justify-between py-1">+ <p className="text-xs text-scale-1000">Extra volume used this month</p>+ <p className="text-xs">+ {dbSizeExcess < 0 ? formatBytes(0) : formatBytes(dbSizeExcess)}+ </p>+ </div>+ </div>+ </div>+ <div className="space-y-1">+ <p>Database egress over time</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ {isLoadingDbSizeData ? (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ ) : (+ <BarChart+ attribute="total_rest_egress"+ data={dbSizeData?.data ?? []}+ unit={undefined}+ yDomain={[0, 100]}+ />+ )}+ </div>+ </div>+ </div>+ </div>++ {/* STORAGE SIZE - need to fix if no value yet (API will return period_start as 0 in first data point) */}<div className="border-b"><div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16"><div className="grid grid-cols-12"><div className="col-span-5"><div className="sticky top-16">- <p className="text-base">IO Budget</p>+ <p className="text-base">Storage size</p><p className="text-sm text-scale-1000">Some description here</p></div></div><div className="col-span-7 space-y-6">+ <div className="space-y-2">+ <div className="flex items-center justify-between">+ <p className="text-sm">+ Storage {subscription?.tier.key.toLowerCase()} quota usage+ </p>+ <Button type="default" size="tiny" onClick={() => {}}>+ Upgrade project+ </Button>+ </div>+ <SparkBar+ type="horizontal"+ barClass="bg-scale-1200"+ value={storage_size?.usage ?? 0}+ max={storage_size?.limit ?? 0}+ />+ <div>+ <div className="flex items-center justify-between border-b py-1">+ <p className="text-xs text-scale-1000">+ Included in {subscription?.tier.name.toLowerCase()}+ </p>+ <p className="text-xs">{formatBytes(storage_size?.limit ?? 0)}</p>+ </div>+ <div className="flex items-center justify-between border-b py-1">+ <p className="text-xs text-scale-1000">Used</p>+ <p className="text-xs">{formatBytes(storage_size?.usage ?? 0)}</p>+ </div>+ <div className="flex items-center justify-between py-1">+ <p className="text-xs text-scale-1000">Extra volume used this month</p>+ <p className="text-xs">+ {storageSizeExcess < 0 ? formatBytes(0) : formatBytes(storageSizeExcess)}+ </p>+ </div>+ </div>+ </div><div className="space-y-1">- <p>IO budget per day</p>- <p className="text-sm text-scale-1000">- Just FYI for now its a percentage for IO budget, which is different from what the- figma designs are (in minutes). We will need o11y or infra to help update this- </p>+ <p>Storage size over time</p>+ <p className="text-sm text-scale-1000">Some description here</p></div>- {isLoadingIoBudgetData ? (+ {isLoadingStorageSizeData ? (<div className="space-y-2"><ShimmeringLoader /><ShimmeringLoader className="w-3/4" />@@ -56,16 +172,10 @@ const SizeAndCounts = () => {</div>) : (<BarChart- attribute="disk_io_budget"- data={generateUsageData('disk_io_budget', 30)}- reference={{- value: 65,- label: 'FREE QUOTA',- x: 60,- y: 49,- width: 200,- height: 24,- }}+ attribute="total_rest_egress"+ data={storageSizeData?.data ?? []}+ unit={undefined}+ yDomain={[0, 100]}/>)}</div>diff --git a/studio/components/interfaces/BillingV2/Usage/Usage.tsx b/studio/components/interfaces/BillingV2/Usage/Usage.tsxindex 6cbfa0815ba..4f37e49062c 100644--- a/studio/components/interfaces/BillingV2/Usage/Usage.tsx+++ b/studio/components/interfaces/BillingV2/Usage/Usage.tsx@@ -76,7 +76,7 @@ const Usage = () => {<Infrastructure /><Bandwidth />- {/* <SizeAndCounts /> */}+ <SizeAndCounts />{/* <Activity /> */}</>)