mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem The Warehouse report does not show available worker capacity or why requests are rejected. ## Solution Add worker-slot usage alongside the slot limit, plus rejected requests split by reason. Labelled measurements keep separate lines and missing values stay visible as gaps. | After | | --- | | <img width="1694" height="1842" alt="CleanShot 2026-11-18 at 13 38 04@2x" src="https://github.com/user-attachments/assets/e480b83c-6c93-4b18-85e6-9a37caf304b0" /> | | _The new “Capacity” section._ | ## Review instructions 1. Open the [Studio staging preview](https://studio-staging-git-dnywh-warehouse-report-capacity-supabase.vercel.app) with a project that has Warehouse access, then go to **Observability > Warehouse**. 2. Under **Capacity**, compare **In use**, **Active grants** and **Pending grants** with **Limit**. 3. Check **Rejected requests** for labelled rejection reasons. Change the period and refresh to check both charts update. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import type { WarehouseMetric } from '@/data/warehouse/warehouse-metrics-api-types'
|
|
|
|
export type WarehouseChartSeries = { metric?: WarehouseMetric; label: string }
|
|
|
|
const getLabelKey = (labels: Record<string, string>) =>
|
|
Object.keys(labels)
|
|
.sort()
|
|
.map((key) => `${key}=${labels[key]}`)
|
|
.join('|')
|
|
|
|
export const expandWarehouseChartSeries = (series: WarehouseChartSeries[]) =>
|
|
series.flatMap(({ metric, label }) => {
|
|
if (!metric || metric.series.length === 0) return [{ metric, label }]
|
|
return [...metric.series]
|
|
.sort((a, b) => getLabelKey(a.labels).localeCompare(getLabelKey(b.labels)))
|
|
.map((item) => ({
|
|
metric: { ...metric, series: [item] },
|
|
label: [
|
|
label,
|
|
...Object.keys(item.labels)
|
|
.sort()
|
|
.map((key) => item.labels[key]),
|
|
]
|
|
.filter(Boolean)
|
|
.join(' · '),
|
|
}))
|
|
})
|
|
|
|
export const getWarehouseSeriesRank = ({ metric }: WarehouseChartSeries) => {
|
|
const points = metric?.series.flatMap((series) => series.points) ?? []
|
|
const measuredPoints = points.filter(
|
|
(point) => point.value !== null && Number.isFinite(point.value)
|
|
)
|
|
if (measuredPoints.some((point) => point.value !== 0)) return 2
|
|
return measuredPoints.length > 0 ? 1 : 0
|
|
}
|
|
|
|
export const getWarehouseChartPoints = (series: WarehouseChartSeries[], scale: number) => {
|
|
const rows = new Map<number, Record<string, string | number>>()
|
|
series.forEach(({ metric }, index) => {
|
|
if (metric?.series.length !== 1) return
|
|
metric.series[0].points.forEach(({ timestamp, value }) => {
|
|
const row = rows.get(timestamp) ?? { timestamp: new Date(timestamp * 1000).toISOString() }
|
|
if (value !== null && Number.isFinite(value)) row[`value${index}`] = value * scale
|
|
rows.set(timestamp, row)
|
|
})
|
|
})
|
|
return [...rows.entries()].sort(([a], [b]) => a - b).map(([, row]) => row)
|
|
}
|