mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 16:09:06 +00:00
## Problem Observability date labels ignore the timezone set in the profile. They always show the browser timezone or UTC. The header range label (for example "Nov 27, 12:40pm → 12:50pm") uses bare `dayjs()`. The Data API charts (Total Requests, Error Counts, Response Speed, Network Traffic) pass `displayDateInUtc`, so the first and last timestamps under each chart always show UTC. ## Solution - Format the header range label with `useFormatDateTime()` on the Database, Auth, Storage, Realtime, PostgREST and Edge Functions observability pages. - Remove `displayDateInUtc` from the four Data API charts in `ApiRenderers.tsx`. - Use `text-xs` for the date labels in `BarChart`, so they match `ComposedChart` and `StackedBarChart`. This is a separate commit. ## Review instructions 1. Open Observability, Database, and set a timezone in your profile that differs from your browser. 2. Check that the range label next to the date picker and the tooltip show the same timezone. 3. Open Observability, Data API. Check that the labels under each chart follow the profile timezone and use the same font size as the Database charts. <details> <summary>Screenshots</summary> <img width="1124" height="844" alt="CleanShot 2026-11-27 at 13 37 14@2x" src="https://github.com/user-attachments/assets/e3d29c77-317a-4489-aa4c-1fbf4783cb57" /> font in Data API <img width="318" height="72" alt="CleanShot 2026-11-27 at 13 40 19@2x" src="https://github.com/user-attachments/assets/06e4d12f-245f-4d4e-9dc9-b7f2f7879e52" /> font in Database <img width="342" height="66" alt="CleanShot 2026-11-27 at 13 41 08@2x" src="https://github.com/user-attachments/assets/de200eb2-4351-471d-a220-bacea142b0d9" /> </details> ## Checklist - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill (not applicable, no docs changes)
494 lines
20 KiB
TypeScript
494 lines
20 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query'
|
|
import { createFileRoute, Link } from '@tanstack/react-router'
|
|
import { useFlag, useParams } from 'common'
|
|
import { ArrowRightIcon, ExternalLinkIcon, RefreshCwIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Alert,
|
|
AlertDescription,
|
|
Button,
|
|
Card,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
|
|
import {
|
|
useDatabaseChartDeepLink,
|
|
useDatabaseSelectionFromUrl,
|
|
} from '@/components/interfaces/Observability/DatabaseReport.hooks'
|
|
import { OBSERVABILITY_DOCS_HREFS } from '@/components/interfaces/Observability/Observability.constants'
|
|
import { ReportHeader } from '@/components/interfaces/Reports/ReportHeader'
|
|
import { ReportPadding } from '@/components/interfaces/Reports/ReportPadding'
|
|
import { REPORT_DATERANGE_HELPER_LABELS } from '@/components/interfaces/Reports/Reports.constants'
|
|
import ReportStickyNav from '@/components/interfaces/Reports/ReportStickyNav'
|
|
import ReportWidget from '@/components/interfaces/Reports/ReportWidget'
|
|
import { ReportChartUpsell } from '@/components/interfaces/Reports/v2/ReportChartUpsell'
|
|
import { POOLING_OPTIMIZATIONS } from '@/components/interfaces/Settings/Database/ConnectionPooling/ConnectionPooling.constants'
|
|
import DiskSizeConfigurationModal from '@/components/interfaces/Settings/Database/DiskSizeConfigurationModal'
|
|
import { getInfrastructurePath } from '@/components/interfaces/Settings/Infrastructure/Infrastructure.utils'
|
|
import { LogsDatePicker } from '@/components/interfaces/Settings/Logs/Logs.DatePickers'
|
|
import UpgradePrompt from '@/components/interfaces/Settings/Logs/UpgradePrompt'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import type { MultiAttribute } from '@/components/ui/Charts/ComposedChart.utils'
|
|
import { LazyComposedChartHandler } from '@/components/ui/Charts/ComposedChartHandler'
|
|
import { ReportSettings } from '@/components/ui/Charts/ReportSettings'
|
|
import { getMemoryCommitmentPreviewData } from '@/components/ui/DevToolbar/MetricsTab.utils'
|
|
import { DocsButton } from '@/components/ui/DocsButton'
|
|
import { ObservabilityLink } from '@/components/ui/ObservabilityLink'
|
|
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
|
|
import { analyticsKeys } from '@/data/analytics/keys'
|
|
import { useDiskAttributesQuery } from '@/data/config/disk-attributes-query'
|
|
import { useProjectDiskResizeMutation } from '@/data/config/project-disk-resize-mutation'
|
|
import { useDatabaseSizeQuery } from '@/data/database/database-size-query'
|
|
import { useMaxConnectionsQuery } from '@/data/database/max-connections-query'
|
|
import { usePgbouncerConfigQuery } from '@/data/database/pgbouncer-config-query'
|
|
import { getReportAttributesV2 } from '@/data/reports/database-charts'
|
|
import { useDatabaseReport } from '@/data/reports/database-report-query'
|
|
import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'
|
|
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useProjectDiskLimits } from '@/hooks/misc/useProjectDiskLimits'
|
|
import { useRefreshHandler, useReportDateRange } from '@/hooks/misc/useReportDateRange'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { useIsHighAvailability, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
import { useFormatDateTime } from '@/lib/datetime'
|
|
import { formatBytes } from '@/lib/helpers'
|
|
import { useDatabaseSelectorStateSnapshot } from '@/state/database-selector'
|
|
import { useMemoryCommitmentPreview } from '@/state/metrics-preview'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
|
|
export const Route = createFileRoute('/project/$ref/observability/database')({
|
|
component: DatabaseReport,
|
|
staticData: {
|
|
observabilityLayoutTitle: 'Database',
|
|
},
|
|
})
|
|
|
|
function DatabaseReport() {
|
|
return (
|
|
<ReportPadding>
|
|
<DatabaseUsage />
|
|
</ReportPadding>
|
|
)
|
|
}
|
|
|
|
const REPORT_TITLE = 'Database'
|
|
|
|
const DatabaseUsage = () => {
|
|
const { db, chart, ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: org } = useSelectedOrganizationQuery()
|
|
const isHighAvailability = useIsHighAvailability()
|
|
|
|
const {
|
|
selectedDateRange,
|
|
updateDateRange,
|
|
datePickerValue,
|
|
datePickerHelpers,
|
|
showUpgradePrompt,
|
|
setShowUpgradePrompt,
|
|
handleDatePickerChange,
|
|
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
|
|
const formatDateTime = useFormatDateTime()
|
|
|
|
const state = useDatabaseSelectorStateSnapshot()
|
|
const queryClient = useQueryClient()
|
|
|
|
const [isRefreshing, setIsRefreshing] = useState(false)
|
|
const [showIncreaseDiskSizeModal, setshowIncreaseDiskSizeModal] = useState(false)
|
|
const [showDatePicker, setShowDatePicker] = useState(false)
|
|
|
|
const isReplicaSelected = state.selectedDatabaseId !== project?.ref
|
|
|
|
const report = useDatabaseReport()
|
|
const { data, params, largeObjectsSql, isPending: isLoading, refresh } = report
|
|
|
|
const { data: databaseSizeData } = useDatabaseSizeQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString || undefined,
|
|
})
|
|
const databaseSizeBytes = databaseSizeData ?? 0
|
|
const currentDiskSize = project?.volumeSizeGb ?? 0
|
|
|
|
const { data: diskConfig } = useDiskAttributesQuery({ projectRef: project?.ref })
|
|
const { data: maxConnections } = useMaxConnectionsQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
usePgbouncerConfigQuery({ projectRef: project?.ref })
|
|
|
|
// PGBouncer connections
|
|
const { data: addons } = useProjectAddonsQuery({ projectRef: project?.ref })
|
|
const computeInstance = addons?.selected_addons.find((addon) => addon.type === 'compute_instance')
|
|
const poolingOptimizations =
|
|
POOLING_OPTIMIZATIONS[
|
|
(computeInstance?.variant.identifier as keyof typeof POOLING_OPTIMIZATIONS) ??
|
|
(project?.infra_compute_size === 'nano' ? 'ci_nano' : 'ci_micro')
|
|
]
|
|
const defaultMaxClientConn = poolingOptimizations.maxClientConn ?? 200
|
|
|
|
const { can: canUpdateDiskSizeConfig } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.INFRA_DISK_CONFIG_WRITE
|
|
)
|
|
|
|
const { getEntitlementSetValues, isLoading: isEntitlementLoading } = useCheckEntitlements(
|
|
'observability.dashboard_advanced_metrics'
|
|
)
|
|
const entitledFeatures = getEntitlementSetValues()
|
|
|
|
const isSpendCapEnabled = entitledFeatures.includes('database') && !org?.usage_billing_enabled
|
|
|
|
const showDiskIOBurstBalanceChart = useFlag('showDiskIOBurstBalanceChart')
|
|
const { limits: projectDiskLimits } = useProjectDiskLimits()
|
|
const showMemoryCommitmentChart = useFlag('showMemoryCommitmentChart')
|
|
const showMemoryCommitmentRiskZones = useFlag('showMemoryCommitmentRiskZones')
|
|
const memoryCommitmentPreview = useMemoryCommitmentPreview(ref)
|
|
const memoryCommitmentPreviewData = getMemoryCommitmentPreviewData(
|
|
memoryCommitmentPreview,
|
|
selectedDateRange?.period_start?.date,
|
|
selectedDateRange?.period_end?.date
|
|
)
|
|
|
|
const REPORT_ATTRIBUTES = getReportAttributesV2(
|
|
entitledFeatures,
|
|
project!,
|
|
diskConfig,
|
|
maxConnections,
|
|
defaultMaxClientConn,
|
|
isSpendCapEnabled,
|
|
showDiskIOBurstBalanceChart,
|
|
showMemoryCommitmentChart,
|
|
showMemoryCommitmentRiskZones,
|
|
projectDiskLimits
|
|
)
|
|
|
|
const { isPending: isUpdatingDiskSize } = useProjectDiskResizeMutation({
|
|
onSuccess: (_, variables) => {
|
|
toast.success(`Successfully updated disk size to ${variables.volumeSize} GB`)
|
|
setshowIncreaseDiskSizeModal(false)
|
|
},
|
|
})
|
|
|
|
const onRefreshReport = useRefreshHandler(
|
|
datePickerValue,
|
|
datePickerHelpers,
|
|
handleDatePickerChange,
|
|
async () => {
|
|
if (!selectedDateRange) return
|
|
|
|
setIsRefreshing(true)
|
|
refresh()
|
|
const { period_start, period_end, interval } = selectedDateRange
|
|
|
|
REPORT_ATTRIBUTES.flatMap((chart) => chart.attributes || [])
|
|
.filter((attr): attr is MultiAttribute => attr !== false)
|
|
.forEach((attr) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: analyticsKeys.infraMonitoring(ref, {
|
|
attribute: attr.attribute,
|
|
startDate: period_start.date,
|
|
endDate: period_end.date,
|
|
interval,
|
|
databaseIdentifier: state.selectedDatabaseId,
|
|
}),
|
|
})
|
|
})
|
|
|
|
if (isReplicaSelected) {
|
|
queryClient.invalidateQueries({
|
|
queryKey: analyticsKeys.infraMonitoring(ref, {
|
|
attribute: 'physical_replication_lag_physical_replication_lag_seconds',
|
|
startDate: period_start.date,
|
|
endDate: period_end.date,
|
|
interval,
|
|
databaseIdentifier: state.selectedDatabaseId,
|
|
}),
|
|
})
|
|
}
|
|
setTimeout(() => setIsRefreshing(false), 1000)
|
|
}
|
|
)
|
|
|
|
useShortcut(SHORTCUT_IDS.OBSERVABILITY_REFRESH, onRefreshReport, {
|
|
enabled: !isRefreshing,
|
|
})
|
|
useShortcut(SHORTCUT_IDS.OBSERVABILITY_TOGGLE_DATE_PICKER, () => {
|
|
setShowDatePicker((open) => !open)
|
|
})
|
|
|
|
useDatabaseSelectionFromUrl(db, state.setSelectedDatabaseId)
|
|
|
|
// Loading charts above the target resize after the first scroll and can push it out of view.
|
|
useDatabaseChartDeepLink(chart)
|
|
|
|
return (
|
|
<>
|
|
<ReportHeader showDatabaseSelector title={REPORT_TITLE} />
|
|
<ReportStickyNav
|
|
content={
|
|
<div className="w-full flex items-center gap-2 flex-wrap">
|
|
<ShortcutTooltip
|
|
shortcutId={SHORTCUT_IDS.OBSERVABILITY_REFRESH}
|
|
label="Refresh report"
|
|
side="bottom"
|
|
>
|
|
<Button
|
|
aria-label="Refresh report"
|
|
disabled={isRefreshing}
|
|
icon={<RefreshCwIcon className={isRefreshing ? 'animate-spin' : ''} />}
|
|
className="w-7"
|
|
onClick={onRefreshReport}
|
|
/>
|
|
</ShortcutTooltip>
|
|
<ReportSettings chartId="database-charts" />
|
|
<div className="contents">
|
|
<LogsDatePicker
|
|
onSubmit={handleDatePickerChange}
|
|
value={datePickerValue}
|
|
helpers={datePickerHelpers}
|
|
open={showDatePicker}
|
|
onOpenChange={setShowDatePicker}
|
|
shortcutId={SHORTCUT_IDS.OBSERVABILITY_TOGGLE_DATE_PICKER}
|
|
/>
|
|
<UpgradePrompt
|
|
show={showUpgradePrompt}
|
|
setShowUpgradePrompt={setShowUpgradePrompt}
|
|
title="Report date range"
|
|
description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
|
|
source="databaseReportDateRange"
|
|
/>
|
|
{selectedDateRange && (
|
|
<div className="order-last flex w-full flex-wrap items-center gap-x-2 text-xs xl:order-none xl:w-auto">
|
|
<p className="text-foreground-light">
|
|
{formatDateTime(selectedDateRange.period_start.date, 'MMM D, h:mma')}
|
|
</p>
|
|
<p className="text-foreground-light">
|
|
<ArrowRightIcon size={12} />
|
|
</p>
|
|
<p className="text-foreground-light">
|
|
{formatDateTime(selectedDateRange.period_end.date, 'MMM D, h:mma')}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<DocsButton
|
|
href={OBSERVABILITY_DOCS_HREFS.database}
|
|
topic={REPORT_TITLE}
|
|
className="ml-auto"
|
|
/>
|
|
</div>
|
|
}
|
|
>
|
|
<div className="grid @6xl:grid-cols-2 gap-4">
|
|
{selectedDateRange &&
|
|
REPORT_ATTRIBUTES.filter((chart) => !chart.hide).map((chart) => {
|
|
const chartPreviewData =
|
|
chart.id === 'memory-commitment' ? memoryCommitmentPreviewData : undefined
|
|
const chartAvailable =
|
|
!chart.entitlement ||
|
|
isEntitlementLoading ||
|
|
entitledFeatures.includes(chart.entitlement)
|
|
return chartAvailable ? (
|
|
<LazyComposedChartHandler
|
|
key={chart.id}
|
|
{...chart}
|
|
data={chartPreviewData}
|
|
highlightedValue={chartPreviewData?.at(-1)?.ram_commit_used}
|
|
attributes={chart.attributes as MultiAttribute[]}
|
|
interval={selectedDateRange.interval}
|
|
startDate={selectedDateRange?.period_start?.date}
|
|
endDate={selectedDateRange?.period_end?.date}
|
|
updateDateRange={updateDateRange}
|
|
defaultChartStyle={chart.defaultChartStyle as 'line' | 'bar' | 'stackedAreaLine'}
|
|
syncId="database-charts"
|
|
showMaxValue={
|
|
chart.id === 'client-connections' ||
|
|
chart.id === 'client-connections-basic' ||
|
|
chart.id === 'pgbouncer-connections'
|
|
? true
|
|
: chart.showMaxValue
|
|
}
|
|
/>
|
|
) : (
|
|
<ReportChartUpsell
|
|
key={chart.id}
|
|
report={{ label: chart.label, requiredPlan: chart.requiredPlan }}
|
|
orgSlug={org?.slug ?? ''}
|
|
/>
|
|
)
|
|
})}
|
|
{selectedDateRange && isReplicaSelected && (
|
|
<LazyComposedChartHandler
|
|
id="replication-lag"
|
|
label="Replication lag"
|
|
format="s"
|
|
valuePrecision={2}
|
|
showTooltip
|
|
YAxisProps={{
|
|
width: 50,
|
|
tickFormatter: (value: number) => `${value}s`,
|
|
}}
|
|
attributes={[
|
|
{
|
|
attribute: 'physical_replication_lag_physical_replication_lag_seconds',
|
|
provider: 'infra-monitoring',
|
|
label: 'Replication lag',
|
|
tooltip:
|
|
'Seconds the read replica is behind its primary. Sustained or growing lag may indicate the replica cannot keep up with write throughput',
|
|
},
|
|
]}
|
|
interval={selectedDateRange.interval}
|
|
startDate={selectedDateRange?.period_start?.date}
|
|
endDate={selectedDateRange?.period_end?.date}
|
|
updateDateRange={updateDateRange}
|
|
defaultChartStyle="line"
|
|
syncId="database-charts"
|
|
/>
|
|
)}
|
|
</div>
|
|
</ReportStickyNav>
|
|
<section id="database-size-report">
|
|
<ReportWidget
|
|
isLoading={isLoading}
|
|
params={params.largeObjects}
|
|
title="Database Size"
|
|
data={data.largeObjects || []}
|
|
queryType={'db'}
|
|
resolvedSql={largeObjectsSql}
|
|
renderer={(props) => {
|
|
return (
|
|
<div>
|
|
<div className="flex flex-wrap items-center gap-8 mt-5">
|
|
<div className="flex flex-col gap-1">
|
|
<p className="text-sm text-foreground-light">Space used</p>
|
|
<span className="text-lg font-semibold text-foreground">
|
|
{formatBytes(databaseSizeBytes, 2, 'GB')}
|
|
</span>
|
|
</div>
|
|
<div className="flex flex-col gap-1">
|
|
<p className="text-sm text-foreground-light">Provisioned disk size</p>
|
|
<span className="text-lg font-semibold text-foreground">
|
|
{currentDiskSize} GB
|
|
</span>
|
|
</div>
|
|
|
|
<div className="ml-auto">
|
|
{/*
|
|
[Joshen] TODO: Check if this check is still relevant
|
|
The DiskSizeConfigurationModal is old and might be obsolete
|
|
*/}
|
|
{project?.cloud_provider === 'AWS' && !isHighAvailability ? (
|
|
<Button asChild>
|
|
<Link to={getInfrastructurePath(ref)}>Increase disk size</Link>
|
|
</Button>
|
|
) : (
|
|
<ButtonTooltip
|
|
disabled={!canUpdateDiskSizeConfig || isHighAvailability}
|
|
onClick={() => setshowIncreaseDiskSizeModal(true)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canUpdateDiskSizeConfig
|
|
? 'You need additional permissions to increase the disk size'
|
|
: isHighAvailability
|
|
? 'Disk size management is unavailable for High Availability projects'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
Increase disk size
|
|
</ButtonTooltip>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<p className="mt-8 text-sm font-medium text-foreground-light">Large Objects</p>
|
|
{!props.isLoading && props.data.length === 0 && (
|
|
<span className="text-sm text-foreground-light mt-2 block">
|
|
No large objects found
|
|
</span>
|
|
)}
|
|
{!props.isLoading && props.data.length > 0 && (
|
|
<Card className="mt-4">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead key="object">Object</TableHead>
|
|
<TableHead key="size">Size</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{props.data.map((object) => {
|
|
const percentage = (
|
|
((object.table_size as number) / databaseSizeBytes) *
|
|
100
|
|
).toFixed(2)
|
|
|
|
return (
|
|
<TableRow key={`${object.schema_name}.${object.relname}`}>
|
|
<TableCell>
|
|
{object.schema_name}.{object.relname}
|
|
</TableCell>
|
|
<TableCell>
|
|
{formatBytes(object.table_size)} ({percentage}%)
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
})}
|
|
</TableBody>
|
|
</Table>
|
|
</Card>
|
|
)}
|
|
</div>
|
|
)
|
|
}}
|
|
append={renderDatabaseSizeAdditionalInfo}
|
|
/>
|
|
<DiskSizeConfigurationModal
|
|
visible={showIncreaseDiskSizeModal}
|
|
loading={isUpdatingDiskSize}
|
|
hideModal={setshowIncreaseDiskSizeModal}
|
|
/>
|
|
</section>
|
|
<div className="py-8">
|
|
<ObservabilityLink />
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const renderDatabaseSizeAdditionalInfo = () => {
|
|
return (
|
|
<div className="px-6 pb-6">
|
|
<Alert variant="default" className="mt-4">
|
|
<AlertDescription>
|
|
<div className="flex flex-col gap-y-2">
|
|
<p>
|
|
New Supabase projects have a database size of ~40-60mb. This space includes
|
|
pre-installed extensions, schemas, and default Postgres data. Additional database size
|
|
is used when installing extensions, even if those extensions are inactive.
|
|
</p>
|
|
|
|
<Button asChild icon={<ExternalLinkIcon />} className="w-min">
|
|
<a
|
|
href={`${DOCS_URL}/guides/platform/database-size#disk-space-usage`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
Read about database size
|
|
</a>
|
|
</Button>
|
|
</div>
|
|
</AlertDescription>
|
|
</Alert>
|
|
</div>
|
|
)
|
|
}
|