mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The memory commitment chart presents the kernel commit limit as a hard failure threshold, even though committed memory can remain unused. Closes [FE-4467](https://linear.app/supabase/issue/FE-4467/update-memory-commitment-ui-with-risk-zones). ## Fix Show only the highest risk threshold exceeded anywhere in the selected time range: Acknowledgment (yellow), Problematic (orange), or Severe (red). Draw its dashed line and place a matching Warning badge in the card header with keyboard-accessible guidance. Show neither a warning line nor a badge when no threshold is exceeded; equality alone does not trigger a warning. Thresholds remain 50%, 80%, and 90% of estimated physical RAM plus 1 GiB of swap, using each timestamp's capacity. Missing readings stay unavailable. Remove in-chart labels and keep only Committed in the source legend. Keep the vertical range anchored at zero and full estimated capacity, expanding for observed overcommitment. A neutral dashed capacity line follows historical infrastructure changes. Dashed references render above the bars and area fills. The hover tooltip identifies Full commitment capacity at that timestamp and excludes it from Total. The developer toolbar includes a Metrics tab with a Memory commitment selector: Default (real data), Warn, Problematic, and Severe. Simulated states include a capacity change and apply only to the selected project’s memory chart. Overrides are in-memory, leave real query data untouched, and are enabled only in local/staging. Both Studio runtimes register the tab. ## Screenshots ### Capacity changes with connected dashed lines  ### Chart tooltip with full commitment capacity  ### Problematic warning and connected threshold lines  ## How to test 1. Open Observability > Database and inspect Memory commitment in bar and line views. 2. With no threshold exceeded, confirm no warning badge or threshold line appears. 3. In the developer toolbar, open Metrics and select Warn, Problematic, then Severe. Confirm the matching badge and only the highest crossed warning threshold appear. Close the toolbar to inspect the chart; the selected state remains active. 4. Hover or focus Warning to read the matching threshold and guidance. 5. Confirm the neutral capacity line steps down midway through each simulated range. 6. Select Default (real data) to restore live readings. Reloading also clears simulations. Validation: 168 affected tests passed with retries disabled and shuffled runs. Production-guard and incorrect-risk-level mutations failed as expected; tests passed after restoring the implementation. Formatting and code review passed.
63 lines
2.6 KiB
TypeScript
63 lines
2.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { memoryCommitmentThresholds } from '@/components/ui/Charts/Charts.test-fixtures'
|
|
import {
|
|
getHighestCrossedThresholdZone,
|
|
getThresholdZoneRuns,
|
|
} from '@/components/ui/Charts/ComposedChartThresholdZones.utils'
|
|
|
|
beforeEach(() => vi.resetModules())
|
|
afterEach(() => vi.unstubAllEnvs())
|
|
|
|
const START = '2026-10-16T10:00:00Z'
|
|
const END = '2026-10-16T11:00:00Z'
|
|
const GIB = 1024 ** 3
|
|
|
|
describe('memory commitment preview fixtures', () => {
|
|
it.each([
|
|
{ preview: 'warn', expectedBadge: 'Warning' },
|
|
{ preview: 'problematic', expectedBadge: 'Problematic' },
|
|
{ preview: 'severe', expectedBadge: 'Severe' },
|
|
] as const)(
|
|
'makes $preview trigger the expected warning even when infrastructure capacity changes',
|
|
async ({ preview, expectedBadge }) => {
|
|
vi.stubEnv('NEXT_PUBLIC_ENVIRONMENT', 'staging')
|
|
const { getMemoryCommitmentPreviewData } = await import('./MetricsTab.utils')
|
|
const data = getMemoryCommitmentPreviewData(preview, START, END)
|
|
expect(data).toBeDefined()
|
|
if (!data) throw new Error('Expected fixture data')
|
|
|
|
const zones = memoryCommitmentThresholds.map((zone) => ({
|
|
...zone,
|
|
runs: getThresholdZoneRuns(zone.getRanges(data)),
|
|
}))
|
|
const selectedIndex = getHighestCrossedThresholdZone(data, zones, 'ram_commit_used')
|
|
const selectedZone = selectedIndex === undefined ? undefined : zones[selectedIndex]
|
|
expect(selectedZone?.badgeLabel).toBe(expectedBadge)
|
|
expect(data[0].period_start).toBe(new Date(START).toISOString())
|
|
expect(data.at(-1)?.period_start).toBe(new Date(END).toISOString())
|
|
const capacityZone = memoryCommitmentThresholds.find((zone) => zone.isAlwaysVisible)
|
|
if (!capacityZone) throw new Error('Expected the full capacity threshold')
|
|
const capacity = capacityZone.getRanges(data)
|
|
expect(capacity[0]).toEqual([9 * GIB, 9 * GIB])
|
|
expect(capacity.at(-1)).toEqual([3 * GIB, 3 * GIB])
|
|
}
|
|
)
|
|
|
|
it('stops supplying simulated data when Default is selected', async () => {
|
|
vi.stubEnv('NEXT_PUBLIC_ENVIRONMENT', 'local')
|
|
const { getMemoryCommitmentPreviewData } = await import('./MetricsTab.utils')
|
|
|
|
expect(getMemoryCommitmentPreviewData('default', START, END)).toBeUndefined()
|
|
})
|
|
|
|
it.each(['prod', 'preview'])(
|
|
'prevents simulated metrics from replacing real data in %s',
|
|
async (environment) => {
|
|
vi.stubEnv('NEXT_PUBLIC_ENVIRONMENT', environment)
|
|
const { getMemoryCommitmentPreviewData } = await import('./MetricsTab.utils')
|
|
expect(getMemoryCommitmentPreviewData('severe', START, END)).toBeUndefined()
|
|
}
|
|
)
|
|
})
|