Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

refactor(reports): use LazyComposedChartHandler for replication lag (#45748)

Jordi Enricf38872c7a6d0
diff --git a/apps/studio/components/ui/Charts/ComposedChart.tsx b/apps/studio/components/ui/Charts/ComposedChart.tsx
index 188e2c479cc..39f74ff414d 100644
--- a/apps/studio/components/ui/Charts/ComposedChart.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChart.tsx
@@ -233,7 +233,11 @@ export function ComposedChart({
return '<1'
}
- return numberFormatter(value, valuePrecision)
+ const formatted = numberFormatter(value, valuePrecision)
+ if (typeof format === 'string' && format) {
+ return `${formatted}${format}`
+ }
+ return formatted
}
function computeHighlightedValue() {
diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
index 288fe4033f3..4aa39274dcf 100644
--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
@@ -212,9 +212,20 @@ export const CustomTooltip = ({
const formatNumeric = (value: number) => {
if (!shouldFormatBytes && valuePrecision === 0 && value > 0 && value < 1) return '<1'
- return shouldFormatBytes
- ? formatBytes(isNetworkChart ? Math.abs(value) : value, valuePrecision)
- : numberFormatter(value, valuePrecision)
+ if (shouldFormatBytes) {
+ return formatBytes(isNetworkChart ? Math.abs(value) : value, valuePrecision)
+ }
+ const formatted = numberFormatter(value, valuePrecision)
+ if (
+ !isBytesFormat &&
+ format !== '%' &&
+ format !== 'ms' &&
+ typeof format === 'string' &&
+ format
+ ) {
+ return `${formatted}${format}`
+ }
+ return formatted
}
const LabelItem = ({ entry }: { entry: any }) => {
diff --git a/apps/studio/components/ui/Charts/ComposedChartHandler.tsx b/apps/studio/components/ui/Charts/ComposedChartHandler.tsx
index 8c0a57efadd..3f9edba6287 100644
--- a/apps/studio/components/ui/Charts/ComposedChartHandler.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChartHandler.tsx
@@ -44,6 +44,12 @@ export interface ComposedChartHandlerProps {
docsUrl?: string
hide?: boolean
syncId?: string
+ YAxisProps?: {
+ width?: number
+ tickFormatter?: (value: any) => string
+ domain?: [number | string, number | string]
+ allowDataOverflow?: boolean
+ }
}
/**
diff --git a/apps/studio/pages/project/[ref]/observability/database.tsx b/apps/studio/pages/project/[ref]/observability/database.tsx
index 1cff91b6689..0605f078531 100644
--- a/apps/studio/pages/project/[ref]/observability/database.tsx
+++ b/apps/studio/pages/project/[ref]/observability/database.tsx
@@ -22,12 +22,10 @@ import DefaultLayout from '@/components/layouts/DefaultLayout'
import ObservabilityLayout from '@/components/layouts/ObservabilityLayout/ObservabilityLayout'
import Table from '@/components/to-be-cleaned/Table'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
-import ChartHandler from '@/components/ui/Charts/ChartHandler'
import type { MultiAttribute } from '@/components/ui/Charts/ComposedChart.utils'
import { LazyComposedChartHandler } from '@/components/ui/Charts/ComposedChartHandler'
import { ReportSettings } from '@/components/ui/Charts/ReportSettings'
import { ObservabilityLink } from '@/components/ui/ObservabilityLink'
-import Panel from '@/components/ui/Panel'
import { analyticsKeys } from '@/data/analytics/keys'
import { useDiskAttributesQuery } from '@/data/config/disk-attributes-query'
import { useProjectDiskResizeMutation } from '@/data/config/project-disk-resize-mutation'
@@ -290,21 +288,32 @@ const DatabaseUsage = () => {
)
})}
{selectedDateRange && isReplicaSelected && (
- <Panel title="Replica Information">
- <Panel.Content>
- <div id="replication-lag">
- <ChartHandler
- startDate={selectedDateRange?.period_start?.date}
- endDate={selectedDateRange?.period_end?.date}
- attribute="physical_replication_lag_physical_replication_lag_seconds"
- label="Replication lag"
- interval={selectedDateRange.interval}
- provider="infra-monitoring"
- syncId="database-charts"
- />
- </div>
- </Panel.Content>
- </Panel>
+ <LazyComposedChartHandler
+ id="replication-lag"
+ label="Replication lag"
+ format="s"
+ valuePrecision={2}
+ showTooltip
+ YAxisProps={{
+ width: 50,
+ tickFormatter: (value: any) => `${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"
+ />
)}
</ReportStickyNav>
<section id="database-size-report">