Skip to content

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

Refactor + include missing charts in usage page

Joshen Lim03f5f07deaf8
diff --git a/studio/components/interfaces/BillingV2/Usage/Activity.tsx b/studio/components/interfaces/BillingV2/Usage/Activity.tsx
index d5cc12fffc7..150cad37dcf 100644
--- a/studio/components/interfaces/BillingV2/Usage/Activity.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/Activity.tsx
@@ -27,36 +27,92 @@ const Activity = ({ projectRef }: ActivityProps) => {
const endDate = new Date((current_period_end ?? 0) * 1000).toISOString()
const categoryMeta = USAGE_CATEGORIES.find((category) => category.key === 'activity')
- const MAU_KEY = 'total_auth_billing_period_mau'
const { data: mauData, isLoading: isLoadingMauData } = useDailyStatsQuery({
projectRef,
- attribute: MAU_KEY,
+ attribute: 'total_auth_billing_period_mau',
+ interval: '1d',
+ startDate,
+ endDate,
+ })
+
+ const { data: mauSSOData, isLoading: isLoadingMauSSOData } = useDailyStatsQuery({
+ projectRef,
+ attribute: 'total_auth_billing_period_sso_mau',
interval: '1d',
startDate,
endDate,
})
- const ASSET_TRANSFORMATIONS_KEY = 'total_storage_image_render_count'
const { data: assetTransformationsData, isLoading: isLoadingAssetTransformationsData } =
useDailyStatsQuery({
projectRef,
- attribute: ASSET_TRANSFORMATIONS_KEY,
+ attribute: 'total_storage_image_render_count',
interval: '1d',
startDate,
endDate,
})
- const FUNC_INVOCATIONS_KEY = 'total_func_invocations'
const { data: funcInvocationsData, isLoading: isLoadingFuncInvocationsData } = useDailyStatsQuery(
{
projectRef,
- attribute: FUNC_INVOCATIONS_KEY,
+ attribute: 'total_func_invocations',
interval: '1d',
startDate,
endDate,
}
)
+ const { data: realtimeMessagesData, isLoading: isLoadingRealtimeMessagesData } =
+ useDailyStatsQuery({
+ projectRef,
+ attribute: 'total_realtime_message_count',
+ interval: '1d',
+ startDate,
+ endDate,
+ })
+
+ const { data: realtimeConnectionsData, isLoading: isLoadingRealtimeConnectionsData } =
+ useDailyStatsQuery({
+ projectRef,
+ attribute: 'total_realtime_peak_connection',
+ interval: '1d',
+ startDate,
+ endDate,
+ })
+
+ const chartMeta: any = {
+ monthly_active_users: {
+ isLoading: isLoadingMauData,
+ data: mauData?.data ?? [],
+ margin: 18,
+ },
+ monthly_active_sso_users: {
+ isLoading: isLoadingMauSSOData,
+ data: mauSSOData?.data ?? [],
+ margin: 20,
+ },
+ storage_image_render_count: {
+ isLoading: isLoadingAssetTransformationsData,
+ data: assetTransformationsData?.data ?? [],
+ margin: 0,
+ },
+ func_invocations: {
+ isLoading: isLoadingFuncInvocationsData,
+ data: funcInvocationsData?.data ?? [],
+ margin: 26,
+ },
+ realtime_message_count: {
+ isLoading: isLoadingRealtimeMessagesData,
+ data: realtimeMessagesData?.data ?? [],
+ margin: 38,
+ },
+ realtime_peak_connection: {
+ isLoading: isLoadingRealtimeConnectionsData,
+ data: realtimeConnectionsData?.data ?? [],
+ margin: 0,
+ },
+ }
+
if (categoryMeta === undefined) return null
return (
@@ -69,19 +125,6 @@ const Activity = ({ projectRef }: ActivityProps) => {
typeof usageMeta !== 'number' ? (usageMeta?.usage ?? 0) / (usageMeta?.limit ?? 0) : 0
const usageExcess = (usageMeta?.usage ?? 0) - (usageMeta?.limit ?? 0)
- const isLoadingData =
- attribute.key === 'monthly_active_users'
- ? isLoadingMauData
- : attribute.key === 'storage_image_render_count'
- ? isLoadingAssetTransformationsData
- : isLoadingFuncInvocationsData
- const usageData =
- attribute.key === 'monthly_active_users'
- ? mauData
- : attribute.key === 'storage_image_render_count'
- ? assetTransformationsData
- : funcInvocationsData
-
return (
<SectionContent
key={attribute.key}
@@ -154,7 +197,7 @@ const Activity = ({ projectRef }: ActivityProps) => {
<p>{attribute.name} over time</p>
<p className="text-sm text-scale-1000">{attribute.chartDescription}</p>
</div>
- {isLoadingData ? (
+ {chartMeta[attribute.key].isLoading ? (
<div className="space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" />
@@ -163,22 +206,10 @@ const Activity = ({ projectRef }: ActivityProps) => {
) : (
<BarChart
hasQuota
- attribute={
- attribute.key === 'monthly_active_users'
- ? MAU_KEY
- : attribute.key === 'storage_image_render_count'
- ? ASSET_TRANSFORMATIONS_KEY
- : FUNC_INVOCATIONS_KEY
- }
- data={usageData?.data ?? []}
+ attribute={attribute.attribute}
+ data={chartMeta[attribute.key]?.data ?? []}
yLimit={usageMeta?.limit ?? 0}
- yLeftMargin={
- attribute.key === 'monthly_active_users'
- ? 18
- : attribute.key === 'storage_image_render_count'
- ? undefined
- : 26
- }
+ yLeftMargin={chartMeta[attribute.key].margin}
yFormatter={(value) => value.toLocaleString()}
/>
)}
diff --git a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx
index f7a660c8d70..4296da6b307 100644
--- a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx
@@ -28,25 +28,27 @@ const Bandwidth = ({ projectRef }: BandwidthProps) => {
const endDate = new Date((current_period_end ?? 0) * 1000).toISOString()
const categoryMeta = USAGE_CATEGORIES.find((category) => category.key === 'bandwidth')
- // [JOSHEN TODO] Double check if this is the right attribute
- const DB_EGRESS_KEY = 'total_db_egress_bytes'
const { data: dbEgressData, isLoading: isLoadingDbEgressData } = useDailyStatsQuery({
projectRef,
- attribute: DB_EGRESS_KEY,
+ attribute: 'total_egress_modified',
interval: '1d',
startDate,
endDate,
})
- const STORAGE_EGRESS_KEY = 'total_storage_egress'
const { data: storageEgressData, isLoading: isLoadingStorageEgressData } = useDailyStatsQuery({
projectRef,
- attribute: STORAGE_EGRESS_KEY,
+ attribute: 'total_storage_egress',
interval: '1d',
startDate,
endDate,
})
+ const chartMeta: any = {
+ db_egress: { isLoading: isLoadingDbEgressData, data: dbEgressData?.data ?? [] },
+ storage_egress: { isLoading: isLoadingStorageEgressData, data: storageEgressData?.data ?? [] },
+ }
+
if (categoryMeta === undefined) return null
return (
@@ -59,10 +61,6 @@ const Bandwidth = ({ projectRef }: BandwidthProps) => {
typeof usageMeta !== 'number' ? (usageMeta?.usage ?? 0) / (usageMeta?.limit ?? 0) : 0
const usageExcess = (usageMeta?.usage ?? 0) - (usageMeta?.limit ?? 0)
- const isLoadingData =
- attribute.key === 'db_egress' ? isLoadingDbEgressData : isLoadingStorageEgressData
- const usageData = attribute.key === 'db_egress' ? dbEgressData : storageEgressData
-
return (
<SectionContent
key={attribute.key}
@@ -126,7 +124,7 @@ const Bandwidth = ({ projectRef }: BandwidthProps) => {
<p>{attribute.name} over time</p>
<p className="text-sm text-scale-1000">{attribute.chartDescription}</p>
</div>
- {isLoadingData ? (
+ {chartMeta[attribute.key]?.isLoading ? (
<div className="space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" />
@@ -135,8 +133,8 @@ const Bandwidth = ({ projectRef }: BandwidthProps) => {
) : (
<BarChart
hasQuota
- attribute={attribute.key === 'db_egress' ? DB_EGRESS_KEY : STORAGE_EGRESS_KEY}
- data={usageData?.data ?? []}
+ attribute={attribute.attribute}
+ data={chartMeta[attribute.key]?.data ?? []}
yLimit={usageMeta?.limit ?? 0}
yLeftMargin={14}
yFormatter={(value) => formatBytes(value, 1, 'GB').replace(/\s/g, '')}
diff --git a/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx b/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx
index a0b6a45dba1..7168b0b63cc 100644
--- a/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx
@@ -9,11 +9,15 @@ const SectionContent = ({ title, description, children }: PropsWithChildren<Sect
return (
<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="grid grid-cols-12 gap-x-6">
<div className="col-span-5">
- <div className="sticky top-16">
+ <div className="sticky top-16 space-y-1">
<p className="text-base capitalize">{title}</p>
- <p className="text-sm text-scale-1000">{description}</p>
+ {description.split('\n').map((value, idx) => (
+ <p key={`desc-${idx}`} className="text-sm text-scale-1000">
+ {value}
+ </p>
+ ))}
</div>
</div>
<div className="col-span-7 space-y-6">{children}</div>
diff --git a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx
index 37317e1d0a7..728bd1e070d 100644
--- a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx
@@ -8,22 +8,20 @@ import {
UsageMetric,
useProjectUsageQuery,
} from 'data/usage/project-usage-query'
+import { PRICING_TIER_PRODUCT_IDS } from 'lib/constants'
import { formatBytes } from 'lib/helpers'
+import Link from 'next/link'
import { Badge, Button, IconAlertTriangle, IconExternalLink } from 'ui'
import { USAGE_APPROACHING_THRESHOLD } from '../Billing.constants'
import BarChart from './BarChart'
import SectionContent from './SectionContent'
import SectionHeader from './SectionHeader'
import { USAGE_CATEGORIES } from './Usage.constants'
-import Link from 'next/link'
export interface SizeAndCountsProps {
projectRef: string
}
-// [Joshen TODO] If it's a paid tier, need to add information about disk size
-// Reference to ProjectUsageBars or reports/database.tsx
-
const SizeAndCounts = ({ projectRef }: SizeAndCountsProps) => {
const { data: usage } = useProjectUsageQuery({ projectRef })
const { data: subscription } = useProjectSubscriptionQuery({ projectRef })
@@ -32,27 +30,37 @@ const SizeAndCounts = ({ projectRef }: SizeAndCountsProps) => {
const endDate = new Date((current_period_end ?? 0) * 1000).toISOString()
const categoryMeta = USAGE_CATEGORIES.find((category) => category.key === 'sizeCount')
- const TOTAL_DB_SIZE_KEY = 'total_db_size_bytes'
const { data: dbSizeData, isLoading: isLoadingDbSizeData } = useDailyStatsQuery({
projectRef,
- attribute: TOTAL_DB_SIZE_KEY,
+ attribute: 'total_db_size_bytes',
interval: '1d',
startDate,
endDate,
})
- const TOTAL_STORAGE_SIZE_KEY = 'total_storage_size_bytes'
const { data: storageSizeData, isLoading: isLoadingStorageSizeData } = useDailyStatsQuery({
projectRef,
- attribute: TOTAL_STORAGE_SIZE_KEY,
+ attribute: 'total_storage_size_bytes',
interval: '1d',
startDate,
endDate,
})
- if (categoryMeta === undefined) return null
+ const { data: functionCountData, isLoading: isLoadingFunctionCountData } = useDailyStatsQuery({
+ projectRef,
+ attribute: 'total_func_count',
+ interval: '1d',
+ startDate,
+ endDate,
+ })
- console.log({ usage })
+ const chartMeta: any = {
+ db_size: { isLoading: isLoadingDbSizeData, data: dbSizeData?.data ?? [] },
+ storage_size: { isLoading: isLoadingStorageSizeData, data: storageSizeData?.data ?? [] },
+ func_count: { isLoading: isLoadingFunctionCountData, data: functionCountData?.data ?? [] },
+ }
+
+ if (categoryMeta === undefined) return null
return (
<>
@@ -64,10 +72,6 @@ const SizeAndCounts = ({ projectRef }: SizeAndCountsProps) => {
typeof usageMeta !== 'number' ? (usageMeta?.usage ?? 0) / (usageMeta?.limit ?? 0) : 0
const usageExcess = (usageMeta?.usage ?? 0) - (usageMeta?.limit ?? 0)
- const isLoadingData =
- attribute.key === 'db_size' ? isLoadingDbSizeData : isLoadingStorageSizeData
- const usageData = attribute.key === 'db_size' ? dbSizeData : storageSizeData
-
return (
<SectionContent
key={attribute.key}
@@ -113,45 +117,60 @@ const SizeAndCounts = ({ projectRef }: SizeAndCountsProps) => {
<p className="text-xs text-scale-1000">
Included in {subscription?.tier.name.toLowerCase()}
</p>
- <p className="text-xs">{formatBytes(usageMeta?.limit ?? 0)}</p>
+ <p className="text-xs">
+ {attribute.unit === 'bytes'
+ ? formatBytes(usageMeta?.limit ?? 0)
+ : (usageMeta?.limit ?? 0).toLocaleString()}
+ </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(usageMeta?.usage ?? 0)}</p>
+ <p className="text-xs">
+ {attribute.unit === 'bytes'
+ ? formatBytes(usageMeta?.usage ?? 0)
+ : (usageMeta?.usage ?? 0).toLocaleString()}
+ </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">
- {usageExcess < 0 ? formatBytes(0) : formatBytes(usageExcess)}
+ {usageExcess < 0
+ ? attribute.unit === 'bytes'
+ ? formatBytes(0)
+ : 0
+ : attribute.unit === 'bytes'
+ ? formatBytes(usageExcess)
+ : usageExcess.toLocaleString()}
</p>
</div>
</div>
</div>
- {attribute.key === 'db_size' && (
- <div className="flex items-center justify-between">
- <div className="flex items-center space-x-2">
- <p className="text-sm">Disk size:</p>
- <p className="text-sm">{usage?.disk_volume_size_gb} GB</p>
- <Badge color="green" size="small">
- Auto-scaling
- </Badge>
+ {attribute.key === 'db_size' &&
+ subscription?.tier.supabase_prod_id !== PRICING_TIER_PRODUCT_IDS.FREE && (
+ <div className="flex items-center justify-between">
+ <div className="flex items-center space-x-2">
+ <p className="text-sm">Disk size:</p>
+ <p className="text-sm">{usage?.disk_volume_size_gb} GB</p>
+ <Badge color="green" size="small">
+ Auto-scaling
+ </Badge>
+ </div>
+ <Link href="https://supabase.com/docs/guides/platform/database-usage#disk-management">
+ <a>
+ <Button size="tiny" type="default" icon={<IconExternalLink size={14} />}>
+ What is disk size?
+ </Button>
+ </a>
+ </Link>
</div>
- <Link href="https://supabase.com/docs/guides/platform/database-usage#disk-management">
- <a>
- <Button size="tiny" type="default" icon={<IconExternalLink size={14} />}>
- What is disk size?
- </Button>
- </a>
- </Link>
- </div>
- )}
+ )}
<div className="space-y-1">
<p>{attribute.name} over time</p>
<p className="text-sm text-scale-1000">{attribute.chartDescription}</p>
</div>
- {isLoadingData ? (
+ {chartMeta[attribute.key].isLoading ? (
<div className="space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" />
@@ -160,13 +179,15 @@ const SizeAndCounts = ({ projectRef }: SizeAndCountsProps) => {
) : (
<BarChart
hasQuota
- attribute={
- attribute.key === 'db_egress' ? TOTAL_DB_SIZE_KEY : TOTAL_STORAGE_SIZE_KEY
- }
- data={usageData?.data ?? []}
+ attribute={attribute.attribute}
+ data={chartMeta[attribute.key]?.data ?? []}
yLimit={usageMeta?.limit ?? 0}
yLeftMargin={14}
- yFormatter={(value) => formatBytes(value, 1, 'GB').replace(/\s/g, '')}
+ yFormatter={(value) =>
+ attribute.unit === 'bytes'
+ ? formatBytes(value, 1, 'GB').replace(/\s/g, '')
+ : value.toLocaleString()
+ }
/>
)}
</SectionContent>
diff --git a/studio/components/interfaces/BillingV2/Usage/Usage.constants.ts b/studio/components/interfaces/BillingV2/Usage/Usage.constants.ts
index 68ad0b6806e..b24866490ea 100644
--- a/studio/components/interfaces/BillingV2/Usage/Usage.constants.ts
+++ b/studio/components/interfaces/BillingV2/Usage/Usage.constants.ts
@@ -7,8 +7,11 @@ export const USAGE_STATUS = {
}
export interface CategoryAttribute {
- key: string
+ key: string // Property from project usage
+ attribute: string // For querying against stats-daily / infra-monitoring
name: string
+ unit: 'bytes' | 'absolute'
+ docsUrl?: string
description: string
chartDescription: string
}
@@ -23,19 +26,25 @@ export const USAGE_CATEGORIES: {
attributes: [
{
key: 'cpu_usage',
+ attribute: 'cpu_usage',
name: 'CPU usage',
+ unit: 'absolute',
description: 'Some description here',
chartDescription: 'Some description here',
},
{
key: 'ram_usage',
+ attribute: 'ram_usage',
name: 'Memory usage',
+ unit: 'absolute',
description: 'Some description here',
chartDescription: 'Some description here',
},
{
key: 'disk_io_budget',
+ attribute: 'disk_io_budget',
name: 'IO budget',
+ unit: 'absolute',
description: 'Some description here',
chartDescription: 'Some description here',
},
@@ -47,15 +56,22 @@ export const USAGE_CATEGORIES: {
attributes: [
{
key: 'db_egress',
+ attribute: 'total_egress_modified',
name: 'Database egress',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'bytes',
+ description: 'Contains any outgoing traffic (egress) from your database',
+ chartDescription:
+ 'Billing is based on the total sum of egress in GB throughout your billing period. The data shown here is refreshed over a period of 24 hours.',
},
{
key: 'storage_egress',
+ attribute: 'total_storage_egress',
name: 'Storage egress',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'bytes',
+ description:
+ 'Contains any outgoing traffic (egress) from your storage buckets (only download operations are counted). We currently do not differentiate between no-cache and cache hits.',
+ chartDescription:
+ 'Billing is based on the total amount of egress in GB throughout your billing period. The data shown here is refreshed over a period of 24 hours.',
},
],
},
@@ -65,15 +81,31 @@ export const USAGE_CATEGORIES: {
attributes: [
{
key: 'db_size',
+ attribute: 'total_db_size_bytes',
name: 'Database size',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'bytes',
+ description: "Size of your project's database",
+ docsUrl: 'https://supabase.com/docs/guides/platform/database-usage',
+ chartDescription:
+ 'Billing is based on the average daily database size in GB throughout the billing period. The data shown here is refreshed over a period of 24 hours.',
},
{
key: 'storage_size',
+ attribute: 'total_storage_size_bytes',
name: 'Storage size',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'bytes',
+ description: 'Sum of all objects in your storage buckets',
+ chartDescription:
+ 'Billing is based on the average size in GB throughout your billing period. The data shown here is refreshed over a period of 24 hours.',
+ },
+ {
+ key: 'func_count',
+ attribute: 'total_func_count',
+ name: 'Edge function count',
+ unit: 'absolute',
+ description: 'Number of serverless functions in your project',
+ chartDescription:
+ 'Billing is based on the maximum amount of functions at any point in time throughout your billing period. The data shown here is refreshed over a period of 24 hours.',
},
],
},
@@ -83,21 +115,58 @@ export const USAGE_CATEGORIES: {
attributes: [
{
key: 'monthly_active_users',
+ attribute: 'total_auth_billing_period_mau',
name: 'Monthly active users (MAU)',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'absolute',
+ description:
+ 'The amount of distinct users requesting your API throughout the billing period. Resets at the beginning of every billing period.',
+ chartDescription: 'The data shown here is refreshed over a period of 24 hours.',
+ },
+ {
+ key: 'monthly_active_sso_users',
+ attribute: 'total_auth_billing_period_sso_mau',
+ name: 'Monthly active single sign-on (SSO) users',
+ unit: 'absolute',
+ description:
+ 'The amount of distinct Single Sign-On users requesting your API throughout the billing period. Resets at the beginning of every billing period.',
+ chartDescription: 'The data shown here is refreshed over a period of 24 hours.',
},
{
key: 'storage_image_render_count',
+ attribute: 'total_storage_image_render_count',
name: 'Storage image transformations',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'absolute',
+ description:
+ 'We distinctly count all images that were transformed in the billing period, ignoring any transformations.\nIf you transform one image with different transformations, it only counts as one. We only count the unique (origin) images being transformed.',
+ chartDescription: 'The data shown here is refreshed over a period of 24 hours.',
},
{
key: 'func_invocations',
+ attribute: 'total_func_invocations',
name: 'Edge function invocations',
- description: 'Some description here',
- chartDescription: 'Some description here',
+ unit: 'absolute',
+ description:
+ 'Every single serverless function invocation independent of response status is counted. ',
+ chartDescription:
+ 'Billing is based on the sum of all invocations throughout your billing period. The data shown here is refreshed over a period of 24 hours.',
+ },
+ {
+ key: 'realtime_message_count',
+ attribute: 'total_realtime_message_count',
+ name: 'Realtime message count',
+ unit: 'absolute',
+ description: 'Total number of realtime messages sent',
+ chartDescription:
+ 'Billing is based on the total amount of messages throughout your billing period. The data shown here is refreshed over a period of 24 hours.',
+ },
+ {
+ key: 'realtime_peak_connection',
+ attribute: 'total_realtime_peak_connection',
+ name: 'Realtime peak connections',
+ unit: 'absolute',
+ description: 'Total number of successful connections (not connection attempts)',
+ chartDescription:
+ 'Billing is based on the maximum amount of concurrent peak connections throughout your billing period.',
},
],
},
diff --git a/studio/data/analytics/daily-stats-query.ts b/studio/data/analytics/daily-stats-query.ts
index d9f63c2e5db..b7283e76b8a 100644
--- a/studio/data/analytics/daily-stats-query.ts
+++ b/studio/data/analytics/daily-stats-query.ts
@@ -11,6 +11,7 @@ export type DailyStatsVariables = {
attribute:
| 'total_db_egress_bytes'
| 'total_db_size_bytes'
+ | 'total_egress_modified'
// Realtime
| 'total_realtime_ingress'