The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): add direct Upgrade compute CTA to exhaustion banners (#44675)
Jordi Enric169a8ff44bd0
diff --git a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.tsindex 287241c113a..a15e25f5877 100644--- a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts+++ b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts@@ -14,10 +14,13 @@ interface ResourceWarningMessage {}docsUrl?: stringbuttonText?: string+ aiPrompt?: stringmetric: string | null}-export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> = {+type ResourceWarningMessages = Record<string, ResourceWarningMessage>++export const RESOURCE_WARNING_MESSAGES: ResourceWarningMessages = {is_readonly_mode_enabled: {bannerContent: {warning: {@@ -44,7 +47,7 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =},},docsUrl: `${DOCS_URL}/guides/platform/database-size#disabling-read-only-mode`,- buttonText: 'Learn more',+ buttonText: 'Manage disk',metric: 'read_only',},disk_io_exhaustion: {@@ -53,12 +56,12 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =title:'Your project is about to deplete its Disk IO Budget, and may become unresponsive once fully exhausted',description:- 'You will need to optimize your performance or upgrade your compute. Check the usage page for more recent and detailed statistics.',+ 'Upgrade your compute or use the AI Assistant to identify and optimize disk-intensive queries.',},critical: {title: 'Your project has depleted its Disk IO Budget, and may become unresponsive',description:- 'You will need to optimize your performance or upgrade your compute. Check the usage page for more recent and detailed statistics.',+ 'Upgrade your compute or use the AI Assistant to identify and optimize disk-intensive queries.',},},cardContent: {@@ -72,7 +75,9 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =},},docsUrl: `${DOCS_URL}/guides/troubleshooting/exhaust-disk-io`,- buttonText: 'Learn more',+ buttonText: 'Upgrade compute',+ aiPrompt:+ 'My database is running out of Disk IO budget. Can you query pg_stat_statements to find the top queries by shared blocks read and written, identify which are causing the most disk I/O, and suggest specific optimizations to reduce disk usage?',metric: 'disk_io',},disk_space_exhaustion: {@@ -108,12 +113,12 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =warning: {title: 'Your project is currently facing high CPU usage, and its performance is affected',description:- 'You will need to optimize your performance or upgrade your compute. Check the usage page for more recent and detailed statistics.',+ 'Upgrade your compute or use the AI Assistant to identify and optimize CPU-intensive queries.',},critical: {title: "Your project's CPU usage is at 100% and its performance is affected",description:- 'You will need to optimize your performance or upgrade your compute. Check the usage page for more recent and detailed statistics.',+ 'Upgrade your compute or use the AI Assistant to identify and optimize CPU-intensive queries.',},},cardContent: {@@ -127,7 +132,9 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =},},docsUrl: `${DOCS_URL}/guides/troubleshooting/high-cpu-usage`,- buttonText: 'Learn more',+ buttonText: 'Upgrade compute',+ aiPrompt:+ 'My database is experiencing high CPU usage. Can you query pg_stat_statements to find the top queries by total execution time and mean execution time, identify which are most CPU-intensive, and suggest specific optimizations such as missing indexes or query rewrites to reduce CPU load?',metric: 'cpu',},memory_and_swap_exhaustion: {@@ -136,12 +143,12 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =title:'Your project is currently facing high memory usage, and its performance is affected',description:- 'You will need to optimize your performance or upgrade your compute. Check the usage page for more recent and detailed statistics.',+ 'Upgrade your compute or use the AI Assistant to identify and optimize memory-intensive queries.',},critical: {title: "Your project's memory usage is at 100%, and its performance is affected",description:- 'You will need to optimize your performance or upgrade your compute. Check the usage page for more recent and detailed statistics.',+ 'Upgrade your compute or use the AI Assistant to identify and optimize memory-intensive queries.',},},cardContent: {@@ -155,7 +162,9 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =},},docsUrl: `${DOCS_URL}/guides/troubleshooting/exhaust-ram`,- buttonText: 'Learn more',+ buttonText: 'Upgrade compute',+ aiPrompt:+ 'My database is experiencing high memory and swap usage. Can you query pg_stat_statements to find the top queries by shared buffer hits and rows returned, identify which queries are putting the most pressure on memory, and suggest optimizations to reduce memory consumption?',metric: 'ram',},auth_rate_limit_exhaustion: {@@ -192,12 +201,12 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =title:'Your project is currently exhausting multiple resources, and its performance is affected',description:- "Check which resources are reaching their threshold on your project's usage page.",+ 'Upgrade your compute or use the AI Assistant to identify and optimize the most expensive queries.',},critical: {title: 'Your project has exhausted multiple resources, and its performance is affected',description:- "Check which resources have reached their threshold on your project's usage page.",+ 'Upgrade your compute or use the AI Assistant to identify and optimize the most expensive queries.',},},cardContent: {@@ -212,6 +221,8 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =},docsUrl: undefined,buttonText: 'Check usage',+ aiPrompt:+ 'My database is exhausting multiple resources (CPU, memory, and/or disk IO). Can you query pg_stat_statements to identify the most expensive queries overall, and suggest which optimizations would have the biggest impact on reducing resource consumption?',metric: null,},}diff --git a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsxindex ac7826eff8e..2edcaa8b414 100644--- a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx+++ b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx@@ -1,16 +1,42 @@import { useParams } from 'common'-import { AlertTriangle, ExternalLink } from 'lucide-react'+import { AlertTriangle, BookOpen, ChevronDown, Sparkles, Wrench } from 'lucide-react'import Link from 'next/link'import { useRouter } from 'next/router'-import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, Button, cn } from 'ui'+import {+ Alert_Shadcn_,+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Button,+ cn,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from 'ui'import { RESOURCE_WARNING_MESSAGES } from './ResourceExhaustionWarningBanner.constants'import { getWarningContent } from './ResourceExhaustionWarningBanner.utils'+import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'import { useResourceWarningsQuery } from '@/data/usage/resource-warnings-query'+import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'+import { useTrack } from '@/lib/telemetry/track'+import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'+import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'++const COMPUTE_UPGRADE_METRICS = ['disk_io', 'cpu', 'ram']+const COMPUTE_UPGRADE_WARNING_TYPES = [+ 'disk_io_exhaustion',+ 'cpu_exhaustion',+ 'memory_and_swap_exhaustion',+]export const ResourceExhaustionWarningBanner = () => {const { ref } = useParams()const router = useRouter()+ const { data: organization, isLoading: isOrgLoading } = useSelectedOrganizationQuery()+ const { openSidebar } = useSidebarManagerSnapshot()+ const aiSnap = useAiAssistantStateSnapshot()+ const track = useTrack()const { data: resourceWarnings } = useResourceWarningsQuery({ ref: ref })// [Joshen Cleanup] JFYI this client side filtering can be cleaned up once BE changes are live which will only return the warnings based on the provided refconst projectResourceWarnings = (resourceWarnings ?? [])?.find(@@ -74,6 +100,9 @@ export const ResourceExhaustionWarningBanner = () => {null: '/project/[ref]/settings/[infra-path]',disk_space: '/project/[ref]/settings/compute-and-disk',read_only: '/project/[ref]/settings/compute-and-disk',+ disk_io: '/project/[ref]/settings/compute-and-disk',+ cpu: '/project/[ref]/settings/compute-and-disk',+ ram: '/project/[ref]/settings/compute-and-disk',auth_email_rate_limit: '/project/[ref]/auth/rate-limits',auth_restricted_email_sending: '/project/[ref]/auth/smtp',default: (metric: string) => `/project/[ref]/settings/[infra-path]#${metric}`,@@ -87,25 +116,65 @@ export const ResourceExhaustionWarningBanner = () => {return typeof url === 'function' ? url(metric as string) : url}- const correctionUrl = getCorrectionUrl(metric)- ?.replace('[ref]', ref ?? 'default')- ?.replace('[infra-path]', 'infrastructure')+ const isFreePlan = organization?.plan?.id === 'free'- const buttonText =- activeWarnings.length > 1+ // True for a single compute warning, or when all active warnings are compute-related+ const isComputeUpgradeMetric =+ (metric !== null && metric !== undefined && COMPUTE_UPGRADE_METRICS.includes(metric)) ||+ (activeWarnings.length > 1 &&+ activeWarnings.every((w) => COMPUTE_UPGRADE_WARNING_TYPES.includes(w)))++ const correctionUrl = (() => {+ if (isComputeUpgradeMetric && isFreePlan) {+ return `/org/${organization?.slug ?? '_'}/billing?panel=subscriptionPlan&source=resource_exhaustion_banner`+ }+ if (isComputeUpgradeMetric && activeWarnings.length > 1) {+ return `/project/${ref ?? 'default'}/settings/compute-and-disk`+ }+ return getCorrectionUrl(metric)+ ?.replace('[ref]', ref ?? 'default')+ ?.replace('[infra-path]', 'infrastructure')+ })()++ const buttonText = (() => {+ if (isComputeUpgradeMetric) return 'Upgrade compute'+ return activeWarnings.length > 1? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.buttonText: RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]?.buttonText+ })()++ const aiPrompt =+ activeWarnings.length > 1+ ? isComputeUpgradeMetric+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.aiPrompt+ : undefined+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]+ ?.aiPrompt++ const handleAskAI = () => {+ track('resource_exhaustion_banner_ai_assistant_clicked', {+ warningTypes: activeWarnings,+ })+ openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)+ aiSnap.newChat({ initialInput: aiPrompt })+ }const hasNoWarnings = activeWarnings.length === 0- const hasNoWarningContent = warningContent === undefined+ const hasNoWarningContent =+ warningContent === undefined || (!warningContent?.title && !warningContent?.description)const isUsageOrInfraPage =router.pathname.endsWith('/usage') || router.pathname.endsWith('/infrastructure')+ // Compute warnings now link to compute-and-disk, so they should remain visible on infrastructureconst onUsageOrInfraAndNotInReadOnlyMode =- isUsageOrInfraPage && !activeWarnings.includes('is_readonly_mode_enabled')+ isUsageOrInfraPage &&+ !activeWarnings.includes('is_readonly_mode_enabled') &&+ !isComputeUpgradeMetric+ // Suppress when already on the target page (no-op CTA). Paid-plan compute warnings link to+ // compute-and-disk; free-plan links to billing instead, so we keep the banner visible for them.const onDatabaseSettingsAndInReadOnlyMode =router.pathname.endsWith('settings/compute-and-disk') &&- activeWarnings.includes('is_readonly_mode_enabled')+ (activeWarnings.includes('is_readonly_mode_enabled') || (isComputeUpgradeMetric && !isFreePlan))// these take precedence over each other, so there's only one active warning to checkconst activeWarning =@@ -151,15 +220,61 @@ export const ResourceExhaustionWarningBanner = () => {<AlertDescription_Shadcn_>{description}</AlertDescription_Shadcn_></div><div className="flex items-center gap-x-2">- {learnMoreUrl !== undefined && (- <Button asChild type="default" icon={<ExternalLink />}>+ {learnMoreUrl !== undefined && aiPrompt !== undefined ? (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ type="default"+ icon={<Wrench size={14} />}+ iconRight={<ChevronDown size={14} />}+ >+ Troubleshoot+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem asChild>+ <a+ href={learnMoreUrl}+ target="_blank"+ rel="noreferrer"+ className="flex items-center gap-x-2 cursor-pointer"+ >+ <BookOpen size={14} />+ Documentation+ </a>+ </DropdownMenuItem>+ <DropdownMenuItem+ className="flex items-center gap-x-2 cursor-pointer"+ onClick={handleAskAI}+ >+ <Sparkles size={14} />+ Ask AI Assistant+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ ) : learnMoreUrl !== undefined ? (+ <Button asChild type="default" icon={<BookOpen size={14} />}><a href={learnMoreUrl} target="_blank" rel="noreferrer">Learn more</a></Button>- )}+ ) : aiPrompt !== undefined ? (+ <Button type="default" onClick={handleAskAI}>+ Ask AI Assistant+ </Button>+ ) : null}{correctionUrl !== undefined && (- <Button asChild type="default">+ <Button+ asChild+ type="primary"+ disabled={isComputeUpgradeMetric && isOrgLoading}+ onClick={() =>+ track('resource_exhaustion_banner_upgrade_clicked', {+ warningTypes: activeWarnings,+ destination: correctionUrl,+ })+ }+ ><Link href={correctionUrl}>{buttonText ?? 'Check'}</Link></Button>)}diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.tsindex ea75b1fb1c3..a480cf2269f 100644--- a/packages/common/telemetry-constants.ts+++ b/packages/common/telemetry-constants.ts@@ -3116,6 +3116,35 @@ export interface HeaderUpgradeCtaClickedEvent {groups: Omit<TelemetryGroups, 'project'>}+/**+ * User clicked the primary CTA on a resource exhaustion warning banner.+ *+ * @group Events+ * @source studio+ */+export interface ResourceExhaustionBannerUpgradeClickedEvent {+ action: 'resource_exhaustion_banner_upgrade_clicked'+ groups: TelemetryGroups+ properties: {+ warningTypes: string[]+ destination: string+ }+}++/**+ * User clicked "Ask AI Assistant" on a resource exhaustion warning banner.+ *+ * @group Events+ * @source studio+ */+export interface ResourceExhaustionBannerAiAssistantClickedEvent {+ action: 'resource_exhaustion_banner_ai_assistant_clicked'+ groups: TelemetryGroups+ properties: {+ warningTypes: string[]+ }+}+/*** @hidden*/@@ -3291,3 +3320,5 @@ export type TelemetryEvent =| HeaderUpgradeCtaClickedEvent| AccessTokenCreatedEvent| AccessTokenRemovedEvent+ | ResourceExhaustionBannerUpgradeClickedEvent+ | ResourceExhaustionBannerAiAssistantClickedEvent