mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 4 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | **4** | **#54307 ← this PR** | **Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute** | | 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.) | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates `components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
124 lines
4.1 KiB
TypeScript
124 lines
4.1 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)
|
|
const errorMessage =
|
|
error && typeof error === 'object' && 'message' in error
|
|
? String(error.message)
|
|
: 'Error loading data'
|
|
|
|
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-destructive wrap-break-word">{errorMessage}</div>
|
|
)}
|
|
{!error && <MetricCardValue>{value}</MetricCardValue>}
|
|
</MetricCardContent>
|
|
</MetricCard>
|
|
</DynamicLink>
|
|
)
|
|
}
|