Home / Function/ ObservabilityOverview() — supabase Function Reference

ObservabilityOverview() — supabase Function Reference

Architecture documentation for the ObservabilityOverview() function in ObservabilityOverview.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  0009d41d_6f19_5684_073a_6abf433e87db["ObservabilityOverview()"]
  a633fd44_7a31_92c2_6573_d41313264107["useObservabilityOverviewData()"]
  0009d41d_6f19_5684_073a_6abf433e87db -->|calls| a633fd44_7a31_92c2_6573_d41313264107
  910ee264_3322_2086_f02e_8c5907515007["useSlowQueriesCount()"]
  0009d41d_6f19_5684_073a_6abf433e87db -->|calls| 910ee264_3322_2086_f02e_8c5907515007
  style 0009d41d_6f19_5684_073a_6abf433e87db fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/Observability/ObservabilityOverview.tsx lines 24–209

export const ObservabilityOverview = () => {
  const router = useRouter()
  const { ref: projectRef } = useParams()
  const { data: organization } = useSelectedOrganizationQuery()
  const { plan } = useCurrentOrgPlan()
  const queryClient = useQueryClient()

  const authReportEnabled = useFlag('authreportv2')
  const edgeFnReportEnabled = useFlag('edgefunctionreport')
  const realtimeReportEnabled = useFlag('realtimeReport')
  const storageReportEnabled = useFlag('storagereport')
  const postgrestReportEnabled = useFlag('postgrestreport')
  const { projectStorageAll: storageSupported } = useIsFeatureEnabled(['project_storage:all'])

  const DEFAULT_INTERVAL: ChartIntervalKey = '1day'
  const [interval, setInterval] = useState<ChartIntervalKey>(DEFAULT_INTERVAL)
  const [refreshKey, setRefreshKey] = useState(0)

  const selectedInterval = CHART_INTERVALS.find((i) => i.key === interval) || CHART_INTERVALS[1]

  const { datetimeFormat } = useMemo(() => {
    const format = selectedInterval.format || 'MMM D, ha'
    return { datetimeFormat: format }
  }, [selectedInterval])

  const overviewData = useObservabilityOverviewData(projectRef!, interval, refreshKey)

  const { slowQueriesCount, isLoading: slowQueriesLoading } = useSlowQueriesCount(
    projectRef,
    refreshKey
  )

  const handleRefresh = useCallback(() => {
    setRefreshKey((prev) => prev + 1)
    queryClient.invalidateQueries({ queryKey: ['project-metrics'] })
    queryClient.invalidateQueries({ queryKey: ['postgrest-overview-metrics'] })
    queryClient.invalidateQueries({ queryKey: ['infra-monitoring'] })
    queryClient.invalidateQueries({ queryKey: ['max-connections'] })
  }, [queryClient])

  const serviceBase = useMemo(
    () => [
      {
        key: 'db' as const,
        name: 'Database',
        reportUrl: `/project/${projectRef}/observability/database`,
        logsUrl: `/project/${projectRef}/logs/postgres-logs`,
        enabled: true,
        hasReport: true,
      },
      {
        key: 'auth' as const,
        name: 'Auth',
        reportUrl: `/project/${projectRef}/observability/auth`,
        logsUrl: `/project/${projectRef}/logs/auth-logs`,
        enabled: true,
        hasReport: authReportEnabled,
      },
      {
        key: 'functions' as const,
        name: 'Edge Functions',
        reportUrl: `/project/${projectRef}/observability/edge-functions`,
        logsUrl: `/project/${projectRef}/logs/edge-functions-logs`,
        enabled: true,
        hasReport: edgeFnReportEnabled,
      },
      {
        key: 'realtime' as const,
        name: 'Realtime',
        reportUrl: `/project/${projectRef}/observability/realtime`,
        logsUrl: `/project/${projectRef}/logs/realtime-logs`,
        enabled: true,
        hasReport: realtimeReportEnabled,
      },
      {
        key: 'storage' as const,
        name: 'Storage',
        reportUrl: `/project/${projectRef}/observability/storage`,
        logsUrl: `/project/${projectRef}/logs/storage-logs`,
        enabled: storageSupported,
        hasReport: storageReportEnabled,
      },
      {
        key: 'postgrest' as const,
        name: 'Data API',
        reportUrl: `/project/${projectRef}/observability/postgrest`,
        logsUrl: `/project/${projectRef}/logs/postgrest-logs`,
        enabled: true,
        hasReport: postgrestReportEnabled,
      },
    ],
    [
      projectRef,
      authReportEnabled,
      edgeFnReportEnabled,
      realtimeReportEnabled,
      storageReportEnabled,
      storageSupported,
      postgrestReportEnabled,
    ]
  )

  const enabledServices = serviceBase.filter((s) => s.enabled)

  const dbServiceData = overviewData.services.db

  // Creates a 1-hour time window for the clicked bar for log filtering
  const handleBarClick = useCallback(
    (serviceKey: string, logsUrl: string) => (datum: any) => {
      if (!datum?.timestamp) return

      const datumTimestamp = dayjs(datum.timestamp)
      // Round down to the start of the hour
      const start = datumTimestamp.startOf('hour').toISOString()
      // Add 1 hour to get the end of the hour
      const end = datumTimestamp.startOf('hour').add(1, 'hour').toISOString()

      const queryParams = new URLSearchParams({
        its: start,
        ite: end,
      })

      router.push(`${logsUrl}?${queryParams.toString()}`)
    },
    [router]
  )

  return (
    <ReportPadding>
      <div className="flex flex-row justify-between items-center">
        <div className="flex items-center gap-3">
          <ReportHeader title="Overview" />
          <Tooltip>
            <TooltipTrigger asChild>
              <Badge variant="warning">Beta</Badge>
            </TooltipTrigger>
            <TooltipContent>
              <p>This page is subject to change</p>
            </TooltipContent>
          </Tooltip>
        </div>
        <div className="flex items-center gap-3">
          <Button type="outline" icon={<RefreshCw size={14} />} onClick={handleRefresh}>
            Refresh
          </Button>
          <ChartIntervalDropdown
            value={interval}
            onChange={(interval) => setInterval(interval as ChartIntervalKey)}
            planId={plan?.id}
            planName={plan?.name}
            organizationSlug={organization?.slug}
            dropdownAlign="end"
            tooltipSide="left"
          />
        </div>
      </div>

      <div className="space-y-12 mt-8">
        <DatabaseInfrastructureSection
          interval={interval}
          refreshKey={refreshKey}
          dbErrorRate={dbServiceData.errorRate}
          isLoading={dbServiceData.isLoading}
          slowQueriesCount={slowQueriesCount}
          slowQueriesLoading={slowQueriesLoading}
        />

        <ServiceHealthTable
          services={enabledServices.map((service) => ({
            key: service.key,
            name: service.name,
            description: '',
            reportUrl: service.hasReport ? service.reportUrl : undefined,
            logsUrl: service.logsUrl,
          }))}
          serviceData={overviewData.services}
          onBarClick={handleBarClick}
          interval={interval}
          datetimeFormat={datetimeFormat}
        />
      </div>

      <ObservabilityOverviewFooter />
    </ReportPadding>
  )
}

Subdomains

Frequently Asked Questions

What does ObservabilityOverview() do?
ObservabilityOverview() is a function in the supabase codebase.
What does ObservabilityOverview() call?
ObservabilityOverview() calls 2 function(s): useObservabilityOverviewData, useSlowQueriesCount.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free