mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem
We don't want to mention raw AWS instance type names. Instead only
display the actual instance size name (e.g. "Small", "Medium", ...).
Fixes PROD-673
## Solution
Add a `getComputeSizeLabel` helper (`apps/studio/lib/compute-labels.ts`)
that maps `infra_compute_size` to its display label (`medium` →
"Medium", `2xlarge` → "2XL", …) and returns `undefined` for unknown
values so callers render nothing instead of a raw value.
Studio elements changed:
- Read replica details: "Compute Size" field
(`/project/<project_id>/settings/infrastructure/replica/<replica_id>`)
- Infrastructure diagram: primary and replica node cards
(`generateNodes` now receives the label; replicas always match the
primary's compute size) (`/project/_/settings/infrastructure`)
- Map view: "AWS • {size}" line in the region popup
(`/project/<project_id>`)
- HA pooler node cards (`useHaPoolerCard`)
Also removes the `size` field from the create-replica request (API
ignores it).
Unit tests cover the new helper, including the unknown-value case. The
existing `project_homepage:show_instance_size` feature flag keeps gating
the label as before.
## Review instructions
1. Open a project's Infrastructure settings page
(`/project/_/settings/infrastructure`).
2. Check the diagram node cards and (for projects with replicas) the map
view popup: compute shows as "Small"/"Medium"-style labels matching the
project's compute badge.
3. Open a read replica's details page: the "Compute Size" field shows
the same label.
4. Open the add-replica dialog and submit: the request body contains
only `read_replica_region`.
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { getComputeCpuLabel, getComputeSizeLabel, isSharedComputeSize } from './compute-labels'
|
|
|
|
describe('isSharedComputeSize', () => {
|
|
it('treats sizes below Large as shared', () => {
|
|
expect(isSharedComputeSize('pico')).toBe(true)
|
|
expect(isSharedComputeSize('nano')).toBe(true)
|
|
expect(isSharedComputeSize('micro')).toBe(true)
|
|
expect(isSharedComputeSize('small')).toBe(true)
|
|
expect(isSharedComputeSize('medium')).toBe(true)
|
|
})
|
|
|
|
it('treats Large and up as dedicated', () => {
|
|
expect(isSharedComputeSize('large')).toBe(false)
|
|
expect(isSharedComputeSize('xlarge')).toBe(false)
|
|
expect(isSharedComputeSize('16xlarge')).toBe(false)
|
|
expect(isSharedComputeSize('48xlarge_high_memory')).toBe(false)
|
|
})
|
|
|
|
it('accepts addon variant identifiers and mixed case', () => {
|
|
expect(isSharedComputeSize('ci_micro')).toBe(true)
|
|
expect(isSharedComputeSize('ci_large')).toBe(false)
|
|
expect(isSharedComputeSize('Medium')).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('getComputeCpuLabel', () => {
|
|
it('labels shared sizes without a count', () => {
|
|
expect(getComputeCpuLabel('micro', 2)).toBe('Shared compute')
|
|
expect(getComputeCpuLabel('medium')).toBe('Shared compute')
|
|
})
|
|
|
|
it('labels dedicated sizes with a vCPU count', () => {
|
|
expect(getComputeCpuLabel('large', 2)).toBe('Dedicated · 2 vCPUs')
|
|
expect(getComputeCpuLabel('16xlarge', 64)).toBe('Dedicated · 64 vCPUs')
|
|
})
|
|
|
|
it('falls back to a generic dedicated label without a count', () => {
|
|
expect(getComputeCpuLabel('large')).toBe('Dedicated compute')
|
|
})
|
|
})
|
|
|
|
describe('getComputeSizeLabel', () => {
|
|
it.each([
|
|
['pico', 'Pico'],
|
|
['nano', 'Nano'],
|
|
['micro', 'Micro'],
|
|
['small', 'Small'],
|
|
['medium', 'Medium'],
|
|
['large', 'Large'],
|
|
['xlarge', 'XL'],
|
|
['2xlarge', '2XL'],
|
|
['4xlarge', '4XL'],
|
|
['8xlarge', '8XL'],
|
|
['12xlarge', '12XL'],
|
|
['16xlarge', '16XL'],
|
|
['24xlarge', '24XL'],
|
|
['24xlarge_optimized_memory', '24XL - Optimized Memory'],
|
|
['24xlarge_optimized_cpu', '24XL - Optimized CPU'],
|
|
['24xlarge_high_memory', '24XL - High Memory'],
|
|
['48xlarge', '48XL'],
|
|
['48xlarge_optimized_memory', '48XL - Optimized Memory'],
|
|
['48xlarge_optimized_cpu', '48XL - Optimized CPU'],
|
|
['48xlarge_high_memory', '48XL - High Memory'],
|
|
])('maps %s to %s', (size, label) => {
|
|
expect(getComputeSizeLabel(size)).toBe(label)
|
|
})
|
|
|
|
it('accepts addon variant identifiers and mixed case', () => {
|
|
expect(getComputeSizeLabel('ci_micro')).toBe('Micro')
|
|
expect(getComputeSizeLabel('Medium')).toBe('Medium')
|
|
})
|
|
|
|
it('returns undefined for unknown or missing values instead of leaking them', () => {
|
|
expect(getComputeSizeLabel('t4g.small')).toBeUndefined()
|
|
expect(getComputeSizeLabel('')).toBeUndefined()
|
|
expect(getComputeSizeLabel(undefined)).toBeUndefined()
|
|
expect(getComputeSizeLabel(null)).toBeUndefined()
|
|
})
|
|
})
|