refactor: use database status from general health check endpoint (#34629)

This commit is contained in:
Kevin Grüneberg
2025-04-02 13:27:04 +08:00
committed by GitHub
parent fe8edf7d05
commit 8d48d5bfae
3 changed files with 5 additions and 75 deletions

View File

@@ -5,7 +5,6 @@ import { useEffect, useState } from 'react'
import { useParams } from 'common'
import { useEdgeFunctionServiceStatusQuery } from 'data/service-status/edge-functions-status-query'
import { usePostgresServiceStatusQuery } from 'data/service-status/postgres-service-status-query'
import {
ProjectServiceStatus,
useProjectServiceStatusQuery,
@@ -112,24 +111,12 @@ const ServiceStatus = () => {
refetchInterval: (data) => (!data?.healthy ? 5000 : false),
}
)
const {
isLoading: isLoadingPostgres,
isSuccess: isSuccessPostgres,
refetch: refetchPostgresServiceStatus,
} = usePostgresServiceStatusQuery(
{
projectRef: ref,
connectionString: project?.connectionString,
},
{
refetchInterval: (data) => (data === null ? 5000 : false),
}
)
const authStatus = status?.find((service) => service.name === 'auth')
const restStatus = status?.find((service) => service.name === 'rest')
const realtimeStatus = status?.find((service) => service.name === 'realtime')
const storageStatus = status?.find((service) => service.name === 'storage')
const dbStatus = status?.find((service) => service.name === 'db')
// [Joshen] Need individual troubleshooting docs for each service eventually for users to self serve
const services: {
@@ -145,8 +132,9 @@ const ServiceStatus = () => {
name: 'Database',
error: undefined,
docsUrl: undefined,
isLoading: isLoadingPostgres,
isSuccess: isSuccessPostgres,
isLoading: isLoading,
isSuccess: dbStatus?.healthy,
status: dbStatus?.status,
logsUrl: '/logs/postgres-logs',
},
{
@@ -230,7 +218,6 @@ const ServiceStatus = () => {
timer = setTimeout(() => {
refetchServiceStatus()
refetchPostgresServiceStatus()
refetchEdgeFunctionServiceStatus()
}, remainingTimeTillNextCheck * 1000)
}

View File

@@ -1,57 +0,0 @@
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
import { serviceStatusKeys } from './keys'
export type PostgresServiceStatusVariables = {
projectRef?: string
connectionString?: string
}
export async function getPostgresServiceStatus(
{ projectRef, connectionString }: PostgresServiceStatusVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
if (!connectionString) throw new Error('connectionString is required')
let headers = new Headers()
headers.set('x-connection-encrypted', connectionString)
const { error } = await post('/platform/pg-meta/{ref}/query', {
params: {
header: { 'x-connection-encrypted': connectionString! },
path: { ref: projectRef },
// @ts-expect-error Intentional key for easier reference of query in the network tab
query: { key: 'service_status' },
},
body: { query: 'select 1' },
headers,
signal,
})
if (error) handleError(error)
return error === undefined
}
export type PostgresServiceStatusData = Awaited<ReturnType<typeof getPostgresServiceStatus>>
export type PostgresServiceStatusError = ResponseError
export const usePostgresServiceStatusQuery = <TData = PostgresServiceStatusData>(
{ projectRef, connectionString }: PostgresServiceStatusVariables,
{
enabled = true,
...options
}: UseQueryOptions<PostgresServiceStatusData, PostgresServiceStatusError, TData> = {}
) =>
useQuery<PostgresServiceStatusData, PostgresServiceStatusError, TData>(
serviceStatusKeys.postgres(projectRef),
({ signal }) => getPostgresServiceStatus({ projectRef, connectionString }, signal),
{
enabled:
enabled && typeof projectRef !== 'undefined' && typeof connectionString !== 'undefined',
staleTime: 0,
...options,
}
)

View File

@@ -18,7 +18,7 @@ export async function getProjectServiceStatus(
params: {
path: { ref: projectRef },
query: {
services: ['auth', 'realtime', 'rest', 'storage'],
services: ['auth', 'realtime', 'rest', 'storage', 'db'],
},
},
signal,