Skip to content

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

Update usage warning banner

Joshen Lim7115c8168171
diff --git a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx
index fdb0948c26c..f4314f551be 100644
--- a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx
@@ -246,6 +246,7 @@ const Infrastructure = ({
</div>
</>
)}
+ {/* [Joshen TODO] Add the necessary alert warnings for CPU and RAM here as well */}
<div className="space-y-1">
<div className="flex flex-row justify-between">
{attribute.key === 'disk_io_consumption' ? (
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
index ec8f4af8e43..887230179ed 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
@@ -39,6 +39,7 @@ export default function ProjectCardWarnings({ resourceWarnings }: ProjectCardWar
(property) => resourceWarnings[property as keyof typeof resourceWarnings] === true
)
const hasHighPriorityWarning = activeWarnings.includes('is_readonly_mode_enabled')
+ // [Joshen] We should probably read readonly mode separately for multiple resource warnings, read only mode needs to take highest precedence
return (
<div>
diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 586022bfbec..37ad6281554 100644
--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -4,8 +4,10 @@ import { Fragment, PropsWithChildren, ReactNode } from 'react'
import { useParams } from 'common/hooks'
import Connecting from 'components/ui/Loading'
+import UsageWarningBanner from 'components/ui/UsageWarnings/UsageWarningBanner'
import { useFlag, useSelectedOrganization, useSelectedProject, withAuth } from 'hooks'
-import { PROJECT_STATUS, IS_PLATFORM } from 'lib/constants'
+import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
+import AppLayout from '../AppLayout/AppLayout'
import BuildingState from './BuildingState'
import ConnectingState from './ConnectingState'
import LayoutHeader from './LayoutHeader'
@@ -16,9 +18,6 @@ import { ProjectContextProvider } from './ProjectContext'
import ProjectPausedState from './ProjectPausedState'
import RestoringState from './RestoringState'
import UpgradingState from './UpgradingState'
-import AppLayout from '../AppLayout/AppLayout'
-import UsageWarningBanner from 'components/ui/UsageWarnings/UsageWarningBanner'
-import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query'
// [Joshen] This is temporary while we unblock users from managing their project
// if their project is not responding well for any reason. Eventually needs a bit of an overhaul
@@ -179,8 +178,6 @@ const ContentWrapper = ({ isLoading, children }: ContentWrapperProps) => {
selectedProject?.status === PROJECT_STATUS.PAUSING
const isProjectOffline = selectedProject?.postgrestStatus === 'OFFLINE'
- const { data: resourceWarnings } = useResourceWarningsQuery()
- console.log(resourceWarnings)
return (
<>
{isLoading || (requiresProjectDetails && selectedProject === undefined) ? (
diff --git a/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx b/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
index ea70a140856..48656d4a197 100644
--- a/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
+++ b/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
@@ -1,16 +1,145 @@
import Link from 'next/link'
-import React from 'react'
-
import { useParams } from 'common'
-import { useSelectedOrganization } from 'hooks'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ IconAlertTriangle,
+ IconExternalLink,
+} from 'ui'
+
+import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query'
-export default function UsageWarningBanner() {
+// [TODO] Just double check if the docs url and correction urls are all correct
+const RESOURCE_WARNING_MESSAGES = {
+ is_readonly_mode_enabled: {
+ title: 'Your project is currently in readonly mode and is no longer accepting write requests',
+ description:
+ 'You will need to manually override read-only mode and reduce the disk size to below 95%.',
+ docsUrl: 'https://supabase.com/docs/guides/platform/database-size#disabling-read-only-mode',
+ correctionUrl: undefined,
+ buttonText: undefined,
+ },
+ is_disk_io_budget_below_threshold: {
+ title:
+ 'Your project is about to deplete its Disk IO Budget, and your instance may become unresponsive once fully exhausted',
+ description:
+ 'You will need to either optimize your performance, or upgrade your compute to a larger instance.',
+ docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-disk-io',
+ correctionUrl: '/project/[ref]/settings/billing/usage#disk_io',
+ buttonText: 'Check usage',
+ },
+ is_disk_space_usage_beyond_threshold: {
+ title:
+ 'Your project is about to exhaust its disk space budget, and your instance may become unresponsive once fully exhausted',
+ description: 'Some CTA description here',
+ docsUrl: undefined,
+ correctionUrl: undefined,
+ buttonText: undefined,
+ },
+ is_cpu_load_beyond_threshold: {
+ title:
+ "Your project is currently facing high CPU usage, and your instance's performance is affected",
+ description:
+ 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-cpu',
+ correctionUrl: '/project/[ref]/settings/billing/usage#cpu',
+ buttonText: 'Check usage',
+ },
+ is_memory_and_swap_usage_beyond_threshold: {
+ title:
+ "Your project is currently facing high memory usage, and your instance's performance is affected",
+ description:
+ 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-ram',
+ correctionUrl: '/project/[ref]/settings/billing/usage#ram',
+ buttonText: 'Check usage',
+ },
+ multiple_resource_warnings: {
+ title:
+ "Your project is currently exhausting multiple resources, and your instance's performance is affected",
+ description: "Check which resources are reaching their threshold on your project's usage page.",
+ docsUrl: undefined,
+ correctionUrl: '/project/[ref]/settings/billing/usage',
+ buttonText: 'Check usage',
+ },
+}
+
+const UsageWarningBanner = () => {
const { ref } = useParams()
- const organization = useSelectedOrganization()
+ const { data: resourceWarnings } = useResourceWarningsQuery()
+ const projectResourceWarnings = (resourceWarnings ?? [])?.find(
+ (warning) => warning.project === ref
+ )
+
+ const activeWarnings =
+ projectResourceWarnings !== undefined
+ ? Object.keys(projectResourceWarnings).filter(
+ (property) =>
+ projectResourceWarnings[property as keyof typeof projectResourceWarnings] === true
+ )
+ : []
+
+ const hasHighPriorityWarning = activeWarnings.includes('is_readonly_mode_enabled')
+
+ const title =
+ activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.title
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
+ ?.title
+ const description =
+ activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.description
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
+ ?.description
+ const learnMoreUrl =
+ activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.docsUrl
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
+ ?.docsUrl
+ const correctionUrl = (
+ activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.correctionUrl
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
+ ?.correctionUrl
+ )?.replace('[ref]', ref ?? 'default')
+ const buttonText =
+ activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.buttonText
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
+ ?.buttonText
+
+ if (activeWarnings.length === 0) return null
return (
- <div className="w-full bg-orange-500">
- Project is experiencing high [product] usage. <Link href="#">Learn more</Link>
- </div>
+ <Alert_Shadcn_
+ variant={hasHighPriorityWarning ? 'destructive' : 'warning'}
+ className="border-l-0 border-r-0 rounded-none"
+ >
+ <IconAlertTriangle />
+ <AlertTitle_Shadcn_>{title}</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{description}</AlertDescription_Shadcn_>
+ <div className="absolute top-5 right-4 flex items-center space-x-2">
+ {learnMoreUrl !== undefined && (
+ <Link passHref href={learnMoreUrl}>
+ <a>
+ <Button type="default" icon={<IconExternalLink />}>
+ Learn more
+ </Button>
+ </a>
+ </Link>
+ )}
+ {correctionUrl !== undefined && (
+ <Link passHref href={correctionUrl}>
+ <a>
+ <Button type="default">{buttonText}</Button>
+ </a>
+ </Link>
+ )}
+ </div>
+ </Alert_Shadcn_>
)
}
+
+export default UsageWarningBanner
diff --git a/studio/data/usage/resource-warnings-query.ts b/studio/data/usage/resource-warnings-query.ts
index 19a92acbe8d..d7ecd7c350e 100644
--- a/studio/data/usage/resource-warnings-query.ts
+++ b/studio/data/usage/resource-warnings-query.ts
@@ -22,5 +22,9 @@ export const useResourceWarningsQuery = <TData = ResourceWarningsData>({
useQuery<ResourceWarningsData, ResourceWarningsError, TData>(
usageKeys.resourceWarnings(),
({ signal }) => getResourceWarnings(signal),
- { enabled, ...options }
+ {
+ enabled,
+ staleTime: 1000 * 60 * 30, // default 30 minutes
+ ...options,
+ }
)