import { HelpCircle } from 'lucide-react' import { ChevronRight } from 'lucide-react' import Link from 'next/link' import { Card, CardContent } from 'ui' import { Badge, Loading, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { LogsBarChart } from 'ui-patterns/LogsBarChart' import { ButtonTooltip } from '../../ui/ButtonTooltip' import type { LogsBarChartDatum } from '../HomeNew/ProjectUsage.metrics' import { type ServiceKey, getHealthStatus } 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 } type IntervalKey = '1hr' | '1day' | '7day' export type ServiceHealthTableProps = { services: ServiceConfig[] serviceData: Record onBarClick: (serviceKey: string, logsUrl: string) => (datum: LogsBarChartDatum) => void interval: IntervalKey datetimeFormat: string } const SERVICE_DESCRIPTIONS: Record = { 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', } const getStatusLabel = (status: 'healthy' | 'error' | 'unknown'): string => { switch (status) { case 'healthy': return 'Healthy' case 'error': return 'Unhealthy' case 'unknown': return 'Unknown' } } const getStatusTooltip = (status: 'healthy' | 'error' | 'unknown'): string => { switch (status) { case 'healthy': return 'Error rate is below 1%' case 'error': return 'Error rate is 1% or higher' case 'unknown': return 'Insufficient data (fewer than 100 requests)' } } const getStatusVariant = ( status: 'healthy' | 'error' | 'unknown' ): 'success' | 'warning' | 'destructive' | 'default' => { switch (status) { case 'healthy': return 'success' case 'error': return 'destructive' case 'unknown': return 'default' } } type ServiceRowProps = { service: ServiceConfig data: ServiceData onBarClick: (datum: LogsBarChartDatum) => void datetimeFormat: string } const ServiceRow = ({ service, data, onBarClick, datetimeFormat }: ServiceRowProps) => { const { status } = getHealthStatus(data.errorRate, data.total) const statusLabel = getStatusLabel(status) const statusVariant = getStatusVariant(status) const statusTooltip = getStatusTooltip(status) 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 (
{service.name}

{SERVICE_DESCRIPTIONS[service.key as ServiceKey] || service.description}

{statusLabel}

{statusTooltip}

e.preventDefault()}> {data.isLoading ? (
) : ( No data
} /> )}
{data.total > 0 && (
{errorRate > 0 && (
{errorRate.toFixed(2)}% errors )} {warningRate > 0 && (
{warningRate.toFixed(2)}% warnings )} {errorRate === 0 && warningRate === 0 && (
0% errors )}
)} ) } export const ServiceHealthTable = ({ services, serviceData, onBarClick, datetimeFormat, }: ServiceHealthTableProps) => { return (

Service Health

{services.map((service) => { const data = serviceData[service.key] if (!data) return null return ( ) })}
) }