Files
supabase/apps/studio/hooks/misc/useProjectDiskLimits.ts
Lukas BernertandClaude Fable 5 f38928ad90 fix(studio): resolve disk limits from the project's instance configuration (#52367)
## Problem

Studio validates disk IOPS/throughput against one minimum value per
compute size. Projects whose hardware supports more get blocked below
their actual limits, charts and banners can show the wrong baseline, and
burst charts are gated by a hardcoded size list that is wrong for some
configs.

Fixes PROD-674

## What changed

- New per-configuration limits table:
`packages/shared-data/instance-disk-limits.ts` (values from the AWS
EBS-optimized tables).
- The size-wide floors in `compute-disk-limits.ts` are now derived from
that table as per-size minimums. Published values are unchanged and
pinned in tests.
- New `useProjectDiskLimits()` resolves a project's limits from its
primary database, falling back to the floors.
- Disk form validates against the project's actual limits (floors when a
different compute size is selected). New inline hint when provisioning
between baseline and max.
- Burst charts/tiles/metrics show only if baseline is below max.
- Chart reference lines and the disk IO banner use the resolved values.

## How to test

1. Settings → Database → Disk on a Large+ project: IOPS/throughput
accept values up to the project's actual limits, error above them, and
show the burst hint between baseline and max.
2. Reports: burst metrics are offered only for projects whose disk IO
bursts; a saved burst chart on a non-bursting project renders an
"unavailable" placeholder instead.
3. `pnpm --filter studio vitest run
components/interfaces/DiskManagement/DiskManagement.test.ts
data/reports/database-charts.test.ts`

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-11-11 17:58:26 +01:00

46 lines
1.7 KiB
TypeScript

import { useParams } from 'common'
import {
COMPUTE_DISK,
getInstanceDiskLimits,
hasBurstableDiskIO,
type InstanceDiskLimits,
} from 'shared-data'
import { mapComputeSizeNameToAddonVariantId } from '@/components/interfaces/DiskManagement/DiskManagement.utils'
import { usePrimaryDatabase } from '@/data/read-replicas/replicas-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
export type ProjectDiskLimits = {
/** Exact limits of the project's current instance when known, size-wide floors otherwise */
limits: InstanceDiskLimits | undefined
/** True when `limits` are the exact values for the current instance */
isPerInstance: boolean
/** Disk IO draws on a burst pool only when the baseline sits below the maximum */
isBurstable: boolean
isPending: boolean
}
/**
* Disk IOPS/throughput limits of the selected project, resolved from the
* primary database's instance configuration with the project's size-wide
* floors as fallback (loading states, configurations missing from the table).
*/
export const useProjectDiskLimits = (): ProjectDiskLimits => {
const { ref: projectRef } = useParams()
const { data: project, isPending: isPendingProject } = useSelectedProjectQuery()
const { database: primary, isLoading: isPendingDatabases } = usePrimaryDatabase({ projectRef })
const instanceLimits = getInstanceDiskLimits(primary?.size)
const floorLimits = project
? COMPUTE_DISK[mapComputeSizeNameToAddonVariantId(project.infra_compute_size)]
: undefined
const limits = instanceLimits ?? floorLimits
return {
limits,
isPerInstance: instanceLimits !== undefined,
isBurstable: hasBurstableDiskIO(limits),
isPending: isPendingProject || isPendingDatabases,
}
}