mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem Infrastructure and Observability label consumed disk IO burst credits as “Disk IO,” so a value of 1% appears inconsistent with a remaining balance of 99% in AWS or Grafana. Both surfaces request `disk_io_consumption`, which is the inverse of `disk_io_budget`. ## Fix Show `disk_io_budget` as “Disk IO balance” and explain that it represents the lower of the remaining throughput and IOPS burst balances. Infrastructure shows the lowest sampled balance over seven days; Observability shows the selected-window average. Keep Infrastructure's overall Compute score based on consumed credits, so a full balance stays healthy and a low balance still warns. Missing balance remains unavailable. Update the compute and disk guide and disk IO troubleshooting page to explain the remaining balance, its direction, and the different aggregation windows. ## How to test - Open Infrastructure settings for a project with burstable IO. Verify the balance headline and chart show remaining credits, with 100% full and 0% exhausted. - Open Observability and verify “Disk IO balance” shows the average remaining balance for the selected window. - Hover the labels to check the explanation and aggregation window. - Verify a high balance does not inflate Compute usage, a low balance raises the warning, and missing balance does not appear as 0% or 100%. - Focused unit and MSW component tests: 79 passed, including shuffled runs with retries disabled; regression mutations caught wrong metric selection, reversed pressure, and maximum-versus-minimum selection. ## Validation Studio typecheck, changed-file ESLint, and Prettier pass locally. Verified both surfaces on the deployed preview, including Observability refresh and the balance tooltip. Documentation formatting and review pass. The local markdown build is blocked by missing generated federated content and its GitHub credentials; docs CI validates the deployed build. ## Screenshots Same project on `supabase.green` (before) and the PR preview (after), captured October 20. Infrastructure uses the same seven-day window; Observability uses Last 24 hours. ### Infrastructure | Before | After | | --- | --- | |  |  | ### Observability | Before | After | | --- | --- | |  |  | Observability balance explanation:  Fixes FDBKPRI-2885
103 lines
3.0 KiB
TypeScript
103 lines
3.0 KiB
TypeScript
import type { InfraMonitoringResponse } from '@/data/analytics/infra-monitoring-query'
|
|
|
|
type NumericValue = string | number | undefined
|
|
|
|
/**
|
|
* Parses a numeric value that can be a number, string, or undefined.
|
|
* Returns 0 for invalid or missing values.
|
|
*/
|
|
export function parseNumericValue(val: NumericValue): number {
|
|
if (typeof val === 'number') return val
|
|
if (typeof val === 'string') return parseFloat(val) || 0
|
|
return 0
|
|
}
|
|
|
|
type MetricData = {
|
|
current: number
|
|
max: number
|
|
}
|
|
|
|
type InfrastructureMetrics = {
|
|
cpu: MetricData
|
|
ram: MetricData
|
|
disk: MetricData
|
|
diskIo: { current: number | undefined; max: number }
|
|
}
|
|
|
|
export function parseInfrastructureMetrics(
|
|
infraData: InfraMonitoringResponse | undefined
|
|
): InfrastructureMetrics | null {
|
|
if (!infraData) {
|
|
return null
|
|
}
|
|
|
|
const series = 'series' in infraData ? infraData.series : {}
|
|
|
|
const cpuValue = parseNumericValue(series.avg_cpu_usage?.totalAverage)
|
|
const ramValue = parseNumericValue(series.ram_usage?.totalAverage)
|
|
const diskSystemValue = parseNumericValue(series.disk_fs_used_system?.totalAverage)
|
|
const diskWalValue = parseNumericValue(series.disk_fs_used_wal?.totalAverage)
|
|
const diskDatabaseValue = parseNumericValue(series.pg_database_size?.totalAverage)
|
|
const diskSizeValue = parseNumericValue(series.disk_fs_size?.totalAverage)
|
|
const diskUsedValue = diskSystemValue + diskWalValue + diskDatabaseValue
|
|
const diskUsageValue = diskSizeValue > 0 ? (diskUsedValue / diskSizeValue) * 100 : 0
|
|
const diskIoAverage = series.disk_io_budget?.totalAverage
|
|
const parsedDiskIoAverage = Number(diskIoAverage)
|
|
const hasDiskIoBalance =
|
|
diskIoAverage !== undefined &&
|
|
String(diskIoAverage).trim() !== '' &&
|
|
Number.isFinite(parsedDiskIoAverage)
|
|
const diskIoValue = hasDiskIoBalance ? parsedDiskIoAverage : undefined
|
|
|
|
return {
|
|
cpu: {
|
|
current: cpuValue,
|
|
max: 100,
|
|
},
|
|
ram: {
|
|
current: ramValue,
|
|
max: 100,
|
|
},
|
|
disk: {
|
|
current: diskUsageValue,
|
|
max: 100,
|
|
},
|
|
diskIo: {
|
|
current: diskIoValue,
|
|
max: 100,
|
|
},
|
|
}
|
|
}
|
|
|
|
type ConnectionsData = {
|
|
peak: number
|
|
max: number
|
|
}
|
|
|
|
type MaxConnectionsData = {
|
|
maxConnections?: number
|
|
}
|
|
|
|
export function parseConnectionsData(
|
|
infraData: InfraMonitoringResponse | undefined,
|
|
maxConnectionsData: MaxConnectionsData | undefined
|
|
): ConnectionsData {
|
|
const max = maxConnectionsData?.maxConnections ?? 0
|
|
|
|
if (!infraData || !('series' in infraData)) {
|
|
return { peak: 0, max }
|
|
}
|
|
|
|
// Show the highest connection count observed in the selected window rather
|
|
// than the window's totalAverage. The average varies with bucket granularity
|
|
// (e.g. 1h vs 1m) and is hard to reason about; peak is interval-stable and
|
|
// the more actionable signal for headroom against the connection limit.
|
|
let peak = 0
|
|
for (const point of infraData.data ?? []) {
|
|
const n = parseNumericValue(point?.values?.pg_stat_database_num_backends)
|
|
if (n > peak) peak = n
|
|
}
|
|
|
|
return { peak: Math.round(peak), max }
|
|
}
|