Files
supabase/apps/studio/components/interfaces/Observability/ServiceHealthTable.tsx
Jordi Enric c39e284641 Observability: remove healthy/unhealthy badge from Service Health (#44771)
## Problem

The "Healthy / Unhealthy" badge on the Observability overview was
alarming — showing **UNHEALTHY** even when every bar in the chart looked
fine. Two root causes:

1. **The threshold is aggressive.** Any period where the aggregate error
rate is ≥ 1% flips the badge to "Unhealthy", even if that 1% came from a
short burst that is visually indistinguishable in the chart.
2. **Period-wide aggregation hides spikes.** The badge status is
computed over the entire selected time window (e.g. 24 h). A 5-minute
spike at 20% errors diluted across 24 h of mostly-clean traffic can push
the aggregate just over 1%, triggering "Unhealthy" while all chart bars
look green.

The badge wording ("Unhealthy") also implies a current service problem,
whereas the underlying metric is a historical aggregate — making it easy
to misread.

## Change

Remove the badge entirely. The per-row error/warning rate indicator
(e.g. `● 1.34% errors`) already surfaces the key signal without the
alarming label, and the bar chart lets users see the actual shape of
traffic over time.

## On spike visibility in charts

The charts already use **COUNT per time bucket** (not averages), so
individual bars faithfully represent event volume. The bucket
granularity does compress spikes for longer windows (hourly buckets for
1–3 day views, daily for 7-day), but that's a separate concern from the
badge. If we want to surface burst detection in the future, a better
approach would be per-bucket threshold highlighting rather than a single
period-wide badge.

https://claude.ai/code/session_01E1ejWyuR9BV4qcTyiGGVVY

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Removed the service health status indicator from the Service Health
Table.

* **New Features**
* Replaced per-row bar charts with a line chart showing error/warning
rates alongside OK series.
* Added a centered "No data" placeholder when chart data is empty and
preserved click interactions on chart points.
  * Y-axis values now display as percentages.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-15 16:33:29 +02:00

168 lines
5.2 KiB
TypeScript

import { ChevronRight, HelpCircle } from 'lucide-react'
import Link from 'next/link'
import { Card, CardContent, Loading, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { LogsBarChart } from 'ui-patterns/LogsBarChart'
import { ButtonTooltip } from '../../ui/ButtonTooltip'
import type { LogsBarChartDatum } from '../ProjectHome/ProjectUsage.metrics'
import type { ServiceKey } from './ObservabilityOverview.utils'
type ServiceConfig = {
key: ServiceKey
name: string
description: string
reportUrl?: string
logsUrl: string
}
type ServiceData = {
total: number
errorRate: number
errorCount: number
warningCount: number
eventChartData: LogsBarChartDatum[]
isLoading: boolean
}
export type ServiceHealthTableProps = {
services: ServiceConfig[]
serviceData: Record<string, ServiceData>
onBarClick: (logsUrl: string) => (datum: LogsBarChartDatum) => void
datetimeFormat: string
}
const SERVICE_DESCRIPTIONS: Record<ServiceKey, string> = {
db: 'PostgreSQL database health and performance',
auth: 'Authentication and user management',
functions: 'Serverless Edge Functions execution',
storage: 'Object storage for files and assets',
realtime: 'WebSocket connections and broadcasts',
postgrest: 'Auto-generated REST API for your database',
}
type ServiceRowProps = {
service: ServiceConfig
data: ServiceData
onBarClick: (datum: LogsBarChartDatum) => void
datetimeFormat: string
}
const ServiceRow = ({ service, data, onBarClick, datetimeFormat }: ServiceRowProps) => {
const errorRate = data.total > 0 ? data.errorRate : 0
const warningRate = data.total > 0 ? (data.warningCount / data.total) * 100 : 0
const reportUrl = service.reportUrl || service.logsUrl
return (
<Link
href={reportUrl}
className="block group py-4 px-card border-b border-default last:border-b-0 hover:bg-surface-200 transition-colors cursor-pointer"
>
<div className="flex items-center justify-between mb-3">
<div className="flex items-center gap-2">
<span className="text-foreground font-medium">{service.name}</span>
<Tooltip>
<TooltipTrigger asChild>
<button
onClick={(e) => e.preventDefault()}
className="text-foreground-lighter hover:text-foreground-light transition-colors"
>
<HelpCircle size={14} />
</button>
</TooltipTrigger>
<TooltipContent side="right" className="max-w-xs">
<p>{SERVICE_DESCRIPTIONS[service.key as ServiceKey] || service.description}</p>
</TooltipContent>
</Tooltip>
</div>
<div className="flex items-center gap-2">
<ButtonTooltip
type="text"
size="tiny"
className="p-1.5"
tooltip={{ content: { text: `Go to ${service.name} report` } }}
>
<ChevronRight
size={14}
className="text-foreground-lighter group-hover:text-foreground"
/>
</ButtonTooltip>
</div>
</div>
<div className="h-16" onClick={(e) => e.preventDefault()}>
<Loading active={data.isLoading}>
{data.isLoading ? (
<div />
) : (
<LogsBarChart
data={data.eventChartData}
DateTimeFormat={datetimeFormat}
onBarClick={onBarClick}
EmptyState={
<div className="flex items-center justify-center h-full text-xs text-foreground-lighter">
No data
</div>
}
/>
)}
</Loading>
</div>
{data.total > 0 && (
<div className="flex items-center justify-center mt-2 text-xs text-foreground-lighter gap-4 font-mono tabular-nums tracking-tight">
{errorRate > 0 && (
<span className="flex items-center gap-1.5">
<div className="w-1.5 h-1.5 rounded-full bg-destructive" />
{errorRate.toFixed(2)}% errors
</span>
)}
{warningRate > 0 && (
<span className="flex items-center gap-1.5">
<div className="w-1.5 h-1.5 rounded-full bg-warning" />
{warningRate.toFixed(2)}% warnings
</span>
)}
{errorRate === 0 && warningRate === 0 && (
<span className="flex items-center gap-1.5">
<div className="w-1.5 h-1.5 rounded-full bg-brand" />
0% errors
</span>
)}
</div>
)}
</Link>
)
}
export const ServiceHealthTable = ({
services,
serviceData,
onBarClick,
datetimeFormat,
}: ServiceHealthTableProps) => {
return (
<div>
<h2 className="heading-section mb-4">Service Health</h2>
<Card>
<CardContent className="p-0">
{services.map((service) => {
const data = serviceData[service.key]
if (!data) return null
return (
<ServiceRow
key={service.key}
service={service}
data={data}
onBarClick={onBarClick(service.logsUrl)}
datetimeFormat={datetimeFormat}
/>
)
})}
</CardContent>
</Card>
</div>
)
}