mirror of
https://github.com/supabase/supabase.git
synced 2026-06-11 06:19:22 +08:00
## Summary - Adds **Data API** (API Gateway / edge logs) as a new service row in the observability overview, positioned before PostgREST - Data API row is only shown when Data API is enabled for the project (gated on `useIsDataApiEnabled`) - Renames the existing PostgREST entry from "Data API" to "PostgREST" to correctly reflect the service - Adds the Data API description to `SERVICE_DESCRIPTIONS` ## Test plan - [ ] Enable Data API for a project — Data API row appears before PostgREST in the overview with chart data - [ ] Disable Data API for a project — Data API row is hidden, PostgREST row remains - [ ] PostgREST row label now reads "PostgREST" instead of "Data API" 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Observability dashboard can optionally show an “API Gateway” service when the Data API feature is enabled; it surfaces logs and health metrics. * The service health table now includes a description/tooltip for the API Gateway and aggregates its metrics. * **Bug Fixes** * Restored and relabeled the PostgREST entry so its observability report and reporting links appear correctly. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46266?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
91 lines
2.3 KiB
TypeScript
91 lines
2.3 KiB
TypeScript
import {
|
|
computeSuccessAndNonSuccessRates,
|
|
sumErrors,
|
|
sumTotal,
|
|
sumWarnings,
|
|
} from '../ProjectHome/ProjectUsage.metrics'
|
|
import type { LogsBarChartDatum } from '../ProjectHome/ProjectUsage.metrics'
|
|
import { useServiceHealthMetrics } from './useServiceHealthMetrics'
|
|
|
|
export type ServiceKey =
|
|
| 'db'
|
|
| 'functions'
|
|
| 'auth'
|
|
| 'storage'
|
|
| 'realtime'
|
|
| 'data_api'
|
|
| 'postgrest'
|
|
|
|
export type HealthStatus = 'healthy' | 'error' | 'unknown'
|
|
|
|
export type ServiceHealthData = {
|
|
total: number
|
|
errorRate: number
|
|
successRate: number
|
|
errorCount: number
|
|
warningCount: number
|
|
okCount: number
|
|
eventChartData: LogsBarChartDatum[]
|
|
isLoading: boolean
|
|
error: unknown | null
|
|
refresh: () => void
|
|
}
|
|
|
|
export type OverviewData = {
|
|
services: Record<ServiceKey, ServiceHealthData>
|
|
aggregated: {
|
|
totalRequests: number
|
|
totalErrors: number
|
|
totalWarnings: number
|
|
overallErrorRate: number
|
|
overallSuccessRate: number
|
|
}
|
|
isLoading: boolean
|
|
}
|
|
|
|
export const calculateErrorRate = (data: LogsBarChartDatum[]): number => {
|
|
const total = sumTotal(data)
|
|
const errors = sumErrors(data)
|
|
return total > 0 ? (errors / total) * 100 : 0
|
|
}
|
|
|
|
export const calculateSuccessRate = (data: LogsBarChartDatum[]): number => {
|
|
const total = sumTotal(data)
|
|
const warnings = sumWarnings(data)
|
|
const errors = sumErrors(data)
|
|
const { successRate } = computeSuccessAndNonSuccessRates(total, warnings, errors)
|
|
return successRate
|
|
}
|
|
|
|
/**
|
|
* Get health status and color based on error rate
|
|
* - Unknown: total_requests < 100 (insufficient data)
|
|
* - Healthy: error_rate < 1%
|
|
* - Unhealthy: error_rate ≥ 1%
|
|
*/
|
|
export const getHealthStatus = (
|
|
errorRate: number,
|
|
total: number
|
|
): { status: HealthStatus; color: string } => {
|
|
if (total < 100) {
|
|
return { status: 'unknown', color: 'muted' }
|
|
}
|
|
if (errorRate >= 1) {
|
|
return { status: 'error', color: 'destructive' }
|
|
}
|
|
return { status: 'healthy', color: 'brand' }
|
|
}
|
|
|
|
/**
|
|
* Hook to fetch and transform observability overview data for all services
|
|
* Uses the same reliable query logic as the logs pages
|
|
*/
|
|
export const useObservabilityOverviewData = (
|
|
projectRef: string,
|
|
interval: '1hr' | '1day' | '7day',
|
|
refreshKey: number
|
|
): OverviewData => {
|
|
// The new hook handles all services using logs page logic
|
|
return useServiceHealthMetrics(projectRef, interval, refreshKey)
|
|
}
|