Skip to content

Commit 9765a70

Browse files
authored
fix: disk attributes on compute down size (supabase#36788)
When downgrading from a larger compute size to <large while having provisioned IOPS or throughput, we would leave the disk as-is, even though the configuration is unsupported and then block any disk changes because the instance size is too small, essentially dead-locking the customer on the disk attributes, unless they bump back up to a higher instance size. PR addresses multiple issues: - Automatically reset disk attributes to default when customers downgrade to <large instances - Do not use the baseline compute IOPS/throughput for the fields, as this leads to accidentally over-provisioning by customers
1 parent e4c50ce commit 9765a70

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ import { IOPSField } from './fields/IOPSField'
5353
import { StorageTypeField } from './fields/StorageTypeField'
5454
import { ThroughputField } from './fields/ThroughputField'
5555
import { DiskCountdownRadial } from './ui/DiskCountdownRadial'
56-
import { DiskType, RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3 } from './ui/DiskManagement.constants'
56+
import {
57+
DISK_LIMITS,
58+
DiskType,
59+
RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3,
60+
} from './ui/DiskManagement.constants'
5761
import { NoticeBar } from './ui/NoticeBar'
5862
import { SpendCapDisabledSection } from './ui/SpendCapDisabledSection'
5963
import { useIsAwsCloudProvider, useIsAwsK8sCloudProvider } from 'hooks/misc/useSelectedProject'
@@ -142,6 +146,10 @@ export function DiskManagementForm() {
142146
/**
143147
* Handle default values
144148
*/
149+
const computeSize = project?.infra_compute_size
150+
? mapComputeSizeNameToAddonVariantId(project?.infra_compute_size)
151+
: undefined
152+
145153
// @ts-ignore
146154
const { type, iops, throughput_mbps, size_gb } = data?.attributes ?? { size_gb: 0, iops: 0 }
147155
const { growth_percent, max_size_gb, min_increment_gb } = diskAutoscaleConfig ?? {}
@@ -150,9 +158,7 @@ export function DiskManagementForm() {
150158
provisionedIOPS: iops,
151159
throughput: throughput_mbps,
152160
totalSize: size_gb,
153-
computeSize: project?.infra_compute_size
154-
? mapComputeSizeNameToAddonVariantId(project?.infra_compute_size)
155-
: undefined,
161+
computeSize,
156162
growthPercent: growth_percent,
157163
minIncrementGb: min_increment_gb,
158164
maxSizeGb: max_size_gb,
@@ -167,6 +173,20 @@ export function DiskManagementForm() {
167173
reValidateMode: 'onChange',
168174
})
169175

176+
const { computeSize: modifiedComputeSize } = form.watch()
177+
178+
// We only support disk configurations for >=Large instances
179+
// If a customer downgrades back to <Large, we should reset the storage settings to avoid incurring unnecessary costs
180+
useEffect(() => {
181+
if (modifiedComputeSize && project?.infra_compute_size && isDialogOpen) {
182+
if (RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3.includes(modifiedComputeSize)) {
183+
form.setValue('storageType', DiskType.GP3)
184+
form.setValue('throughput', DISK_LIMITS['gp3'].minThroughput)
185+
form.setValue('provisionedIOPS', DISK_LIMITS['gp3'].minIops)
186+
}
187+
}
188+
}, [modifiedComputeSize, isDialogOpen, project])
189+
170190
/**
171191
* State handling
172192
*/

apps/studio/components/interfaces/DiskManagement/fields/IOPSField.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import {
1313
} from '../DiskManagement.utils'
1414
import { BillingChangeBadge } from '../ui/BillingChangeBadge'
1515
import { ComputeSizeRecommendationSection } from '../ui/ComputeSizeRecommendationSection'
16-
import {
17-
COMPUTE_BASELINE_IOPS,
18-
DiskType,
19-
RESTRICTED_COMPUTE_FOR_IOPS_ON_GP3,
20-
} from '../ui/DiskManagement.constants'
16+
import { DiskType, RESTRICTED_COMPUTE_FOR_IOPS_ON_GP3 } from '../ui/DiskManagement.constants'
2117
import { DiskManagementIOPSReadReplicas } from '../ui/DiskManagementReadReplicas'
2218
import FormMessage from '../ui/FormMessage'
2319
import { InputPostTab } from '../ui/InputPostTab'
@@ -117,13 +113,7 @@ export function IOPSField({ form, disableInput }: IOPSFieldProps) {
117113
type="number"
118114
className="flex-grow font-mono rounded-r-none max-w-32"
119115
{...field}
120-
value={
121-
disableIopsInput
122-
? COMPUTE_BASELINE_IOPS[
123-
watchedComputeSize as keyof typeof COMPUTE_BASELINE_IOPS
124-
]
125-
: field.value
126-
}
116+
value={field.value}
127117
disabled={disableInput || disableIopsInput || isError}
128118
onChange={(e) => {
129119
setValue('provisionedIOPS', e.target.valueAsNumber, {

apps/studio/components/interfaces/DiskManagement/fields/ThroughputField.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { DiskStorageSchemaType } from '../DiskManagement.schema'
1111
import { calculateThroughputPrice } from '../DiskManagement.utils'
1212
import { BillingChangeBadge } from '../ui/BillingChangeBadge'
1313
import {
14-
COMPUTE_BASELINE_THROUGHPUT,
1514
DISK_LIMITS,
1615
DiskType,
1716
RESTRICTED_COMPUTE_FOR_IOPS_ON_GP3,
@@ -129,13 +128,7 @@ export function ThroughputField({ form, disableInput }: ThroughputFieldProps) {
129128
<Input_Shadcn_
130129
type="number"
131130
{...field}
132-
value={
133-
disableIopsInput
134-
? COMPUTE_BASELINE_THROUGHPUT[
135-
watchedComputeSize as keyof typeof COMPUTE_BASELINE_THROUGHPUT
136-
]
137-
: field.value
138-
}
131+
value={field.value}
139132
onChange={(e) => {
140133
setValue('throughput', e.target.valueAsNumber, {
141134
shouldDirty: true,

0 commit comments

Comments
 (0)