mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The Warehouse integration overview shows replication status but gives no view of query activity. ## Solution Add last-hour query rate and p95 duration charts, with refresh and a link to Observability. Metrics failures appear beside the replication information. | Before | After | | --- | --- | | <img width="1292" height="1288" alt="CleanShot 2026-11-18 at 13 44 48@2x" src="https://github.com/user-attachments/assets/f06314bb-8322-448b-a86b-6821a3427a52" /> | <img width="1314" height="1930" alt="CleanShot 2026-11-18 at 13 45 10@2x" src="https://github.com/user-attachments/assets/0cbaab85-b7bb-445d-8547-3c772010a0d1" /> | | _No “Workload” section._ | _A new “Workload” section._ | Depends on #53574. ## Review instructions 1. Open the [Studio staging preview](https://studio-staging-git-dnywh-warehouse-overview-workload-supabase.vercel.app) with a staging project that has Warehouse configured. 2. Go to **Integrations > Warehouse > Overview**. Check the **Workload** charts below replication status. 3. Refresh the charts, then use **Observability** to open the full report. 4. Check a period without query activity. The empty message should name the last 60 minutes. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
138 lines
4.3 KiB
TypeScript
138 lines
4.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { ArrowUpRightIcon, RefreshCwIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { Button } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import {
|
|
PageSection,
|
|
PageSectionContent,
|
|
PageSectionDescription,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import {
|
|
getWorkloadStatus,
|
|
getWorkloadView,
|
|
type WorkloadView,
|
|
} from './WarehouseWorkloadSection.utils'
|
|
import { WarehouseMetricChart } from '@/components/interfaces/Observability/Warehouse/WarehouseMetricChart'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { warehouseMetricsQueryOptions } from '@/data/warehouse/warehouse-metrics-query'
|
|
|
|
const getRange = () => {
|
|
const end = dayjs().startOf('minute')
|
|
return { startDate: end.subtract(1, 'hour').toISOString(), endDate: end.toISOString() }
|
|
}
|
|
|
|
export const WarehouseWorkloadSection = () => {
|
|
const { ref } = useParams()
|
|
const [range, setRange] = useState(getRange)
|
|
|
|
const query = useQuery(
|
|
warehouseMetricsQueryOptions({
|
|
projectRef: ref,
|
|
attributes: ['query_rate', 'query_duration_p95'],
|
|
...range,
|
|
interval: '1m',
|
|
})
|
|
)
|
|
const view = getWorkloadView(query)
|
|
|
|
const handleRefresh = () => {
|
|
const nextRange = getRange()
|
|
setRange(nextRange)
|
|
if (nextRange.endDate === range.endDate) query.refetch()
|
|
}
|
|
|
|
return (
|
|
<PageSection>
|
|
<PageSectionMeta className="flex-row items-end @xl:items-end justify-between gap-3">
|
|
<PageSectionSummary>
|
|
<PageSectionTitle>Workload</PageSectionTitle>
|
|
<PageSectionDescription>Query activity in the last 60 minutes.</PageSectionDescription>
|
|
</PageSectionSummary>
|
|
<div
|
|
role="group"
|
|
aria-label="Workload actions"
|
|
className="flex shrink-0 items-center gap-2"
|
|
>
|
|
<Button
|
|
variant="text"
|
|
aria-label="Refresh report"
|
|
title="Refresh report"
|
|
icon={<RefreshCwIcon size={14} />}
|
|
disabled={query.isFetching}
|
|
onClick={handleRefresh}
|
|
/>
|
|
<Button asChild variant="default" iconRight={<ArrowUpRightIcon size={14} />}>
|
|
<InlineLink className="no-underline" href={`/project/${ref}/observability/warehouse`}>
|
|
Observability
|
|
</InlineLink>
|
|
</Button>
|
|
</div>
|
|
</PageSectionMeta>
|
|
<PageSectionContent className="relative">
|
|
<p role="status" aria-label="Workload status" className="sr-only">
|
|
{getWorkloadStatus(view)}
|
|
</p>
|
|
<WarehouseWorkloadBody view={view} projectRef={ref} />
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
)
|
|
}
|
|
|
|
const WarehouseWorkloadBody = ({
|
|
view,
|
|
projectRef,
|
|
}: {
|
|
view: WorkloadView
|
|
projectRef?: string
|
|
}) => {
|
|
switch (view.kind) {
|
|
case 'loading':
|
|
return <GenericSkeletonLoader aria-label="Loading workload metrics" />
|
|
case 'error':
|
|
return (
|
|
<AlertError
|
|
subject="Failed to load Warehouse metrics"
|
|
error={view.error}
|
|
projectRef={projectRef}
|
|
/>
|
|
)
|
|
case 'unavailable':
|
|
return (
|
|
<Admonition
|
|
layout="responsive"
|
|
title="Warehouse metrics are unavailable"
|
|
description="Replication status is shown above."
|
|
/>
|
|
)
|
|
case 'ready':
|
|
return (
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<WarehouseMetricChart
|
|
title="Query duration (p95)"
|
|
description="Includes worker waits and result streaming."
|
|
metric={view.data.metrics.find((item) => item.metric === 'query_duration_p95')}
|
|
unit="ms"
|
|
scale={1000}
|
|
emptyMessage="No data in the last 60 minutes"
|
|
/>
|
|
<WarehouseMetricChart
|
|
title="Query rate"
|
|
description="Queries started per second. Not a count of SQL statements."
|
|
metric={view.data.metrics.find((item) => item.metric === 'query_rate')}
|
|
unit="/s"
|
|
emptyMessage="No data in the last 60 minutes"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
}
|