mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The Database section of Observability displays raw infrastructure API errors in metric cards, making failures confusing and repetitive. ## Fix Show one friendly alert with refresh, support, and service-status guidance when the infrastructure request fails. Keep Slow Queries visible, and show “Unable to load” only on affected cards for partial failures while preserving healthy metrics. The Overview Refresh button now invalidates the active project’s connection-limit query. Previously it used a cache key that matched no active query, so Peak Connections could stay on “Unable to load” while the other cards refreshed. Consolidates and supersedes #47491 and #47495, adapted to the current batched metrics implementation. ## How to test - Open Observability and verify that successful database metrics still render. - Simulate a failed infrastructure request. Expect one friendly alert, no raw backend message, and Slow Queries still visible. - Simulate an individual metric or connection-limit failure. Expect only the affected card to show “Unable to load”. - With the connection-limit request failing, click **Refresh** and confirm that Peak Connections shows “Unable to load”. Restore the response and click **Refresh** again. The card should show the peak and limit without a browser reload. ## QA results - **Hosted Refresh recovery passed on `ee646999af`.** After the connection-limit request recovered, one click sent a new request and replaced “Unable to load” with `6/90`. The other five hosted cases passed on `dbf78487f5`. [Automated QA review](https://github.com/supabase/supabase/pull/52216#pullrequestreview-6169329677) - **Local Chromium recovery passed on the same commit.** With a simulated HTTP 500 followed by success, Refresh retried the query and displayed `12/100`. CPU, Memory, and Disk remained healthy. - All 52 focused tests passed with retries disabled and shuffled order. The recovery test failed with the original Refresh handler. Studio typecheck passed. GitHub reported 38 successful checks and six skipped checks. Fixes https://linear.app/supabase/issue/DEBUG-155/frontend-should-render-nice-error-message-on-infra-monitoring-api ## QA screenshots ### Peak Connections before and after the Refresh fix **Before · `dbf78487f5`.** Peak Connections still showed “Unable to load” after two Refresh clicks, even as the other metrics reloaded.  **After · `ee646999af`.** Once the connection-limit request could succeed, the next Refresh click restored Peak Connections to `6/90`.  ### Local browser with HTTP overrides Actual PR component at `dbf78487f5`, rendered in a local fixture harness at a 1440 × 900 viewport. Playwright intercepted the infrastructure API request; these are local simulated error states, not hosted-preview captures. **Full request failure:** one friendly alert; raw backend details are hidden and Slow Queries remains visible.  **Partial failure:** only Disk IO Budget shows “Unable to load”; healthy metrics and Slow Queries remain visible.  **Recovery:** after restoring a successful response and reloading, all metric cards render normally.  ### Verified hosted preview Studio staging deployment for `dbf78487f5`, 1440 × 900. All database metric cards and Slow Queries return after Refresh.  The CPU card opens the Database report and preserves Last 24 hours. 
118 lines
3.9 KiB
TypeScript
118 lines
3.9 KiB
TypeScript
import type { UseQueryResult } from '@tanstack/react-query'
|
|
import {
|
|
MetricCard,
|
|
MetricCardContent,
|
|
MetricCardHeader,
|
|
MetricCardLabel,
|
|
MetricCardValue,
|
|
} from 'ui-patterns/MetricCard'
|
|
|
|
import {
|
|
parseConnectionsData,
|
|
parseInfrastructureMetrics,
|
|
} from './DatabaseInfrastructureSection.utils'
|
|
import { DynamicLink } from '@/components/ui/DynamicLink'
|
|
import {
|
|
type InfraMonitoringAttribute,
|
|
type InfraMonitoringError,
|
|
type InfraMonitoringMultiData,
|
|
} from '@/data/analytics/infra-monitoring-query'
|
|
import type { MaxConnectionsData, MaxConnectionsError } from '@/data/database/max-connections-query'
|
|
|
|
const METRICS = {
|
|
connections: {
|
|
label: 'Peak Connections',
|
|
tooltip:
|
|
'Highest concurrent database connections observed in the selected window, against the connection limit. Monitor to avoid connection exhaustion.',
|
|
attributes: ['pg_stat_database_num_backends'],
|
|
},
|
|
disk: {
|
|
label: 'Disk Usage',
|
|
tooltip: 'Disk usage percentage of total disk space used',
|
|
attributes: ['disk_fs_used_system', 'disk_fs_used_wal', 'pg_database_size', 'disk_fs_size'],
|
|
},
|
|
diskIo: {
|
|
label: 'Disk IO balance',
|
|
tooltip:
|
|
'Average remaining disk IO burst balance in the selected window, using the lower of throughput and IOPS balances; 100% is full and 0% is exhausted.',
|
|
attributes: ['disk_io_budget'],
|
|
},
|
|
ram: {
|
|
label: 'Memory',
|
|
tooltip: 'RAM usage percentage. Sustained high usage may indicate memory pressure',
|
|
attributes: ['ram_usage'],
|
|
},
|
|
cpu: {
|
|
label: 'CPU',
|
|
tooltip: 'CPU usage percentage. High values may suggest CPU-intensive queries or workloads',
|
|
attributes: ['avg_cpu_usage'],
|
|
},
|
|
} satisfies Record<
|
|
string,
|
|
{ label: string; tooltip: string; attributes: InfraMonitoringAttribute[] }
|
|
>
|
|
|
|
export const INFRASTRUCTURE_METRIC_ATTRIBUTES = Object.values(METRICS).flatMap(
|
|
({ attributes }) => attributes
|
|
)
|
|
|
|
type DatabaseInfrastructureMetricProps = {
|
|
infraQuery: Pick<
|
|
UseQueryResult<InfraMonitoringMultiData, InfraMonitoringError>,
|
|
'data' | 'error' | 'isLoading'
|
|
>
|
|
metric: keyof typeof METRICS
|
|
href: string
|
|
maxConnectionsQuery: Pick<
|
|
UseQueryResult<MaxConnectionsData, MaxConnectionsError>,
|
|
'data' | 'error' | 'isLoading'
|
|
>
|
|
}
|
|
|
|
export const DatabaseInfrastructureMetric = ({
|
|
metric,
|
|
href,
|
|
maxConnectionsQuery,
|
|
infraQuery,
|
|
}: DatabaseInfrastructureMetricProps) => {
|
|
const { label, tooltip, attributes } = METRICS[metric]
|
|
const isConnections = metric === 'connections'
|
|
const isLoading = infraQuery.isLoading || (isConnections && maxConnectionsQuery.isLoading)
|
|
const data = infraQuery.data
|
|
const errors = data && 'errors' in data ? data.errors : undefined
|
|
const metricError = attributes.map((attribute) => errors?.[attribute]).find(Boolean)
|
|
const hasMissingSeries =
|
|
data && 'series' in data && attributes.some((attribute) => !data.series[attribute])
|
|
const error =
|
|
infraQuery.error ??
|
|
metricError ??
|
|
(isConnections ? maxConnectionsQuery.error : null) ??
|
|
(hasMissingSeries ? { message: 'Error loading data' } : null)
|
|
|
|
let value = '--'
|
|
if (data) {
|
|
if (isConnections) {
|
|
const connections = parseConnectionsData(data, maxConnectionsQuery.data)
|
|
if (connections.max > 0) value = `${connections.peak}/${connections.max}`
|
|
} else {
|
|
const metrics = parseInfrastructureMetrics(data)
|
|
const current = metrics?.[metric].current
|
|
if (current !== undefined) value = `${current.toFixed(0)}%`
|
|
}
|
|
}
|
|
|
|
return (
|
|
<DynamicLink href={href} className="block group">
|
|
<MetricCard isLoading={isLoading}>
|
|
<MetricCardHeader linkTooltip="Go to database report">
|
|
<MetricCardLabel tooltip={tooltip}>{label}</MetricCardLabel>
|
|
</MetricCardHeader>
|
|
<MetricCardContent>
|
|
{!!error && <div className="text-xs text-foreground-light">Unable to load</div>}
|
|
{!error && <MetricCardValue>{value}</MetricCardValue>}
|
|
</MetricCardContent>
|
|
</MetricCard>
|
|
</DynamicLink>
|
|
)
|
|
}
|