Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/service status indications (#17693)

Joshen Lim0bd81110f245
diff --git a/studio/components/interfaces/Home/ServiceStatus.tsx b/studio/components/interfaces/Home/ServiceStatus.tsx
new file mode 100644
index 00000000000..3f04756666d
--- /dev/null
+++ b/studio/components/interfaces/Home/ServiceStatus.tsx
@@ -0,0 +1,115 @@
+import { useParams } from 'common'
+import { AlertTriangle, CheckCircle2 } from 'lucide-react'
+import { useState } from 'react'
+import {
+ Button,
+ IconLoader,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+} from 'ui'
+
+import { usePostgresServiceStatusQuery } from 'data/service-status/postgres-service-status-query'
+import { useProjectServiceStatusQuery } from 'data/service-status/service-status-query'
+import { useSelectedProject } from 'hooks'
+import { useEdgeFunctionServiceStatusQuery } from 'data/service-status/edge-functions-status-query'
+
+const ServiceStatus = () => {
+ const { ref } = useParams()
+ const project = useSelectedProject()
+ const [open, setOpen] = useState(false)
+
+ const isBranch = project?.parentRef !== project?.ref
+
+ // [Joshen] Need pooler service check eventually
+ const { data: status, isLoading } = useProjectServiceStatusQuery({ projectRef: ref })
+ const { data: edgeFunctionsStatus, isLoading: isLoadingEdgeFunctions } =
+ useEdgeFunctionServiceStatusQuery({ projectRef: ref })
+ const { isLoading: isLoadingPostgres, isSuccess: isSuccessPostgres } =
+ usePostgresServiceStatusQuery({
+ projectRef: ref,
+ connectionString: project?.connectionString,
+ })
+
+ 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')
+
+ // [Joshen] Need individual troubleshooting docs for each service eventually for users to self serve
+ const services = [
+ {
+ name: 'Database',
+ docsUrls: undefined,
+ isLoading: isLoadingPostgres,
+ isSuccess: isSuccessPostgres,
+ },
+ { name: 'PostgREST', docsUrls: undefined, isLoading, isSuccess: restStatus?.healthy },
+ { name: 'Auth', docsUrls: undefined, isLoading, isSuccess: authStatus?.healthy },
+ { name: 'Realtime', docsUrls: undefined, isLoading, isSuccess: realtimeStatus?.healthy },
+ { name: 'Storage', docsUrls: undefined, isLoading, isSuccess: storageStatus?.healthy },
+ {
+ name: 'Edge Functions',
+ docsUrl: 'https://supabase.com/docs/guides/functions/troubleshooting',
+ isLoading,
+ isSuccess: edgeFunctionsStatus?.healthy,
+ },
+ ]
+
+ const isLoadingChecks = services.some((service) => service.isLoading)
+ const allServicesOperational = services.every((service) => service.isSuccess)
+
+ return (
+ <Popover_Shadcn_ modal={false} open={open} onOpenChange={setOpen}>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
+ type="default"
+ icon={
+ isLoadingChecks ? (
+ <IconLoader className="animate-spin" />
+ ) : allServicesOperational ? (
+ <div className="w-2 h-2 rounded-full bg-brand" />
+ ) : (
+ <div className="w-2 h-2 rounded-full bg-amber-900" />
+ )
+ }
+ >
+ {isBranch ? 'Preview Branch' : 'Project'} Status
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_
+ className="p-0 w-56"
+ side="bottom"
+ align="end"
+ style={{ marginLeft: '-247px' }}
+ >
+ {services.map((service) => (
+ <div
+ key={service.name}
+ className="px-4 py-2 text-xs flex items-center justify-between border-b"
+ >
+ <div>
+ <p>{service.name}</p>
+ <p className="text-light">
+ {service.isLoading
+ ? 'Checking status'
+ : service.isSuccess
+ ? 'No issues'
+ : 'Unable to connect'}
+ </p>
+ </div>
+ {service.isLoading ? (
+ <IconLoader className="animate-spin" size="tiny" />
+ ) : service.isSuccess ? (
+ <CheckCircle2 className="text-brand" size={18} strokeWidth={1.5} />
+ ) : (
+ <AlertTriangle className="text-amber-900" size={18} strokeWidth={1.5} />
+ )}
+ </div>
+ ))}
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )
+}
+
+export default ServiceStatus
diff --git a/studio/data/api.d.ts b/studio/data/api.d.ts
index afea4ae331c..d7d3d185f28 100644
--- a/studio/data/api.d.ts
+++ b/studio/data/api.d.ts
@@ -829,6 +829,10 @@ export interface paths {
/** Updates a project's health status. */
put: operations["HealthReportingController_updateStatus"];
};
+ "/system/projects/{ref}/ha-events": {
+ /** Records an HA event */
+ put: operations["HaEventsController_updateStatus"];
+ };
"/system/projects/{ref}/credentials/aws": {
/** Allows a project to obtain temporary credentials. */
post: operations["AwsCredentialsController_getTemporaryCredentials"];
@@ -853,10 +857,22 @@ export interface paths {
/** Previews the migration of the organization to the new org level billing. */
post: operations["BillingMigrationController_preview"];
};
+ "/system/billing/migrate/org-level-billing-attach": {
+ /** Attaches subscription id to org and projects. */
+ put: operations["BillingMigrationController_attachSubscriptionId"];
+ };
"/system/projects/{ref}/config/update-jwt/complete": {
/** Handle update project jwt on completion */
post: operations["ProjectUpdateJwtController_completeUpdateJwt"];
};
+ "/system/projects": {
+ /** Create a project */
+ post: operations["ProjectsController_createProject"];
+ };
+ "/system/organizations/{slug}/usage": {
+ /** Gets usage stats */
+ get: operations["OrgUsageSystemController_getDailyStats"];
+ };
"/system/integrations/vercel/webhooks": {
/** Processes Vercel event */
post: operations["VercelWebhooksController_processEvent"];
@@ -1498,6 +1514,10 @@ export interface paths {
/** Disables project's readonly mode for the next 15 minutes */
post: operations["ReadOnlyController_temporarilyDisableReadonlyMode"];
};
+ "/v1/projects/{ref}/health": {
+ /** Gets project's service health status */
+ get: operations["ServiceHealthController_checkServiceHealth"];
+ };
"/v1/projects/{ref}/config/database/postgres": {
/** Gets project's Postgres config */
get: operations["AuthPostgresConfigController_getConfig"];
@@ -1536,6 +1556,10 @@ export interface paths {
/** Enables Database Webhooks on the project */
post: operations["V1DatabaseWebhooksController_v1EnableDatabaseWebhooks"];
};
+ "/v1/projects/{ref}/database/backups/restore-pitr": {
+ /** Restores a PITR backup for a database */
+ post: operations["V1RestorePitrController_v1RestorePitr"];
+ };
"/v1/projects/{ref}/functions": {
/**
* List all functions
@@ -1601,6 +1625,26 @@ export interface paths {
/** Gets a specific SQL snippet */
get: operations["SnippetsController_getSnippet"];
};
+ "/partners/flyio/callback": {
+ /** Redirects to Supabase dashboard after Fly sso with Gotrue */
+ get: operations["CallbackController_redirectToDashboardFlyioExtensionScreen"];
+ };
+ "/partners/flyio/extensions/{extension_id}": {
+ /** Gets database status */
+ get: operations["ExtensionController_getResourceStatus"];
+ };
+ "/partners/flyio/extensions/{extension_id}/sso": {
+ /** Starts Flyio single sign on */
+ get: operations["ExtensionController_startFlyioSSO"];
+ };
+ "/partners/flyio/extensions/{extension_id}/billing": {
+ /** Gets resource billing */
+ get: operations["ExtensionController_getResourceBilling"];
+ };
+ "/partners/flyio/extensions": {
+ /** Creates a database */
+ post: operations["ExtensionsController_provisionResource"];
+ };
}
export type webhooks = Record<string, never>;
@@ -1736,6 +1780,8 @@ export interface components {
SMS_VONAGE_API_SECRET: string;
SMS_VONAGE_FROM: string;
SMS_TEMPLATE: string;
+ SMS_TEST_OTP: string;
+ SMS_TEST_OTP_VALID_UNTIL: string;
EXTERNAL_APPLE_ENABLED: boolean;
EXTERNAL_APPLE_CLIENT_ID: string;
EXTERNAL_APPLE_SECRET: string;
@@ -1852,6 +1898,7 @@ export interface components {
SMS_TEXTLOCAL_SENDER?: string;
SMS_TWILIO_ACCOUNT_SID?: string;
SMS_TWILIO_AUTH_TOKEN?: string;
+ SMS_TWILIO_CONTENT_SID?: string;
SMS_TWILIO_MESSAGE_SERVICE_SID?: string;
SMS_TWILIO_VERIFY_ACCOUNT_SID?: string;
SMS_TWILIO_VERIFY_AUTH_TOKEN?: string;
@@ -1982,6 +2029,8 @@ export interface components {
SMS_VONAGE_API_SECRET: string;
SMS_VONAGE_FROM: string;
SMS_TEMPLATE: string;
+ SMS_TEST_OTP: string;
+ SMS_TEST_OTP_VALID_UNTIL: string;
EXTERNAL_APPLE_ENABLED: boolean;
EXTERNAL_APPLE_CLIENT_ID: string;
EXTERNAL_APPLE_SECRET: string;
@@ -3070,6 +3119,7 @@ export interface components {
is_alpha_user: boolean;
gotrue_id: string;
free_project_limit: number;
+ disabled_features: ("organizations:create" | "organizations:delete" | "organization_members:create" | "organization_members:delete" | "projects:create" | "projects:transfer" | "project_auth:all" | "project_storage:all" | "project_edge_function:all" | "profile:update" | "billing:all")[];
};
UpdateProfileBody: {
first_name: string;
@@ -3114,6 +3164,7 @@ export interface components {
* @enum {string}
*/
region: "us-east-1" | "us-west-1" | "us-west-2" | "ap-southeast-1" | "ap-northeast-1" | "ap-northeast-2" | "ap-southeast-2" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "eu-central-1" | "ca-central-1" | "ap-south-1" | "sa-east-1";
+ /** @deprecated */
kps_enabled?: boolean;
};
CreateProjectResponse: {
@@ -3245,9 +3296,6 @@ export interface components {
UpdateProjectBody: {
name: string;
};
- RestoreProjectBody: {
- kps_enabled?: boolean;
- };
BackupId: {
id: number;
};
@@ -3997,6 +4045,10 @@ export interface components {
value: string;
};
CreateSecretBody: {
+ /**
+ * @description Secret name must not start with the SUPABASE_ prefix.
+ * @example string
+ */
name: string;
value: string;
};
@@ -4005,6 +4057,11 @@ export interface components {
status: "ACTIVE_HEALTHY" | "ACTIVE_UNHEALTHY" | "COMING_UP" | "GOING_DOWN" | "INACTIVE" | "INIT_FAILED" | "REMOVED" | "RESTORING" | "UNKNOWN" | "UPGRADING" | "PAUSING";
reportingToken: string;
};
+ EventBody: {
+ reportingToken: string;
+ eventType: string;
+ message: string;
+ };
CredentialsRequestBody: {
projectToken: string;
};
@@ -4036,6 +4093,18 @@ export interface components {
payment_method_id?: string;
existing_org_subscription_id?: string;
dryRun?: boolean;
+ force?: boolean;
+ billing_cycle_anchor?: string;
+ };
+ AttachSubscriptionIdBody: {
+ org_slug: string;
+ subscription_id: string;
+ };
+ DatabaseResponse: {
+ /** @description Database host */
+ host: string;
+ /** @description Database version */
+ version: string;
};
GetMetricsBody: {
/** @enum {string} */
@@ -4078,12 +4147,6 @@ export interface components {
created_at: string;
updated_at: string;
};
- DatabaseResponse: {
- /** @description Database host */
- host: string;
- /** @description Database version */
- version: string;
- };
ApiKeyResponse: {
name: string;
api_key: string;
@@ -4191,6 +4254,28 @@ export interface components {
override_enabled: boolean;
override_active_until: string;
};
+ AuthHealthResponse: {
+ name: string;
+ version: string;
+ description: string;
+ };
+ RestHealthResponse: {
+ title: string;
+ version: string;
+ description: string;
+ };
+ RealtimeHealthResponse: {
+ healthy: boolean;
+ db_connected: boolean;
+ connected_cluster: number;
+ };
+ ServiceHealthResponse: {
+ info?: components["schemas"]["AuthHealthResponse"] | components["schemas"]["RestHealthResponse"] | components["schemas"]["RealtimeHealthResponse"];
+ /** @enum {string} */
+ name: "auth" | "realtime" | "rest" | "storage";
+ healthy: boolean;
+ error?: string;
+ };
V1PgbouncerConfigResponse: {
/** @enum {string} */
pool_mode?: "transaction" | "session" | "statement";
@@ -4296,6 +4381,9 @@ export interface components {
created_at?: string;
updated_at?: string;
};
+ V1RestorePitrBody: {
+ recovery_time_target_unix: number;
+ };
FunctionSlugResponse: {
id: string;
slug: string;
@@ -4378,6 +4466,71 @@ export interface components {
updated_by: components["schemas"]["SnippetUser"];
content: components["schemas"]["SnippetContent"];
};
+ ResourceStatusResponse: {
+ /**
+ * @description Supabase project status
+ * @example ACTIVE_HEALTHY
+ * @enum {string}
+ */
+ status: "REMOVED" | "COMING_UP" | "INACTIVE" | "ACTIVE_HEALTHY" | "ACTIVE_UNHEALTHY" | "UNKNOWN" | "GOING_DOWN" | "INIT_FAILED" | "RESTORING" | "UPGRADING" | "PAUSING";
+ };
+ ResourceProvisioningBody: {
+ /** @description A UNIX epoch timestamp value */
+ timestamp: number;
+ /** @description A random unique string identifying the individual request */
+ nonce: string;
+ /** @description The full request target URL */
+ url: string;
+ /** @description Name of the extension */
+ name: string;
+ /** @description Unique ID representing the extension */
+ id: string;
+ /** @description Unique ID representing an organization */
+ organization_id: string;
+ /** @description Display name for an organization */
+ organization_name: string;
+ /** @description Obfuscated email that routes to all organization admins */
+ organization_email: string;
+ /** @description Obfuscated email that routes to the provisioning user */
+ user_email: string;
+ /** @description Unique ID representing an user */
+ user_id: string;
+ /** @description The three-letter, primary Fly.io region where the target app intends to write from */
+ primary_region: string;
+ /** @description An IPv6 address on the customer network assigned to this extension */
+ ip_address: string;
+ /**
+ * @description An array of Fly.io region codes where read replicas should be provisioned
+ * @default []
+ */
+ read_regions: (string)[];
+ /** @description Database password (Optional, don't send to generate one) */
+ db_pass?: string;
+ user_name: string;
+ };
+ ResourceProvisioningConfigResponse: {
+ /**
+ * @description PSQL connection string
+ * @example postgresql://postgres:[email protected]:5432/postgres
+ */
+ POSTGRES_URL: string;
+ };
+ ResourceProvisioningResponse: {
+ /** @description Supabase envs config */
+ config: components["schemas"]["ResourceProvisioningConfigResponse"];
+ /**
+ * @description The target Fly application for internal traffic
+ * @example ext-db-pgshhamktpsgnptvcadw
+ */
+ fly_app_name: string;
+ /**
+ * @description Supabase project id
+ * @example pgshhamktpsgnptvcadw
+ */
+ id: string;
+ /** @description Welcome message */
+ message: string;
+ };
};
responses: never;
parameters: never;
@@ -4811,11 +4964,7 @@ export interface operations {
};
};
responses: {
- 201: {
- content: {
- "application/json": Record<string, never>;
- };
- };
+ 201: never;
/** @description Failed to restore project backup */
500: never;
};
@@ -4834,11 +4983,7 @@ export interface operations {
};
};
responses: {
- 201: {
- content: {
- "application/json": Record<string, never>;
- };
- };
+ 201: never;
/** @description Failed to restore project with physical backup */
500: never;
};
@@ -4857,11 +5002,7 @@ export interface operations {
};
};
responses: {
- 201: {
- content: {
- "application/json": Record<string, never>;
- };
- };
+ 201: never;
/** @description Failed to restore project to a previous point in time */
500: never;
};
@@ -7476,11 +7617,7 @@ export interface operations {
};
};
responses: {
- 201: {
- content: {
- "application/json": Record<string, never>;
- };
- };
+ 201: never;
/** @description Failed to pause the project */
500: never;
};
@@ -7584,11 +7721,6 @@ export interface operations {
ref: string;
};
};
- requestBody: {
- content: {
- "application/json": components["schemas"]["RestoreProjectBody"];
- };
- };
responses: {
201: {
content: {
@@ -9179,6 +9311,25 @@ export interface operations {
500: never;
};
};
+ /** Records an HA event */
+ HaEventsController_updateStatus: {
+ parameters: {
+ path: {
+ /** @description Project ref */
+ ref: string;
+ };
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["EventBody"];
+ };
+ };
+ responses: {
+ 200: never;
+ /** @description Failed to record HA event. */
+ 500: never;
+ };
+ };
/** Allows a project to obtain temporary credentials. */
AwsCredentialsController_getTemporaryCredentials: {
parameters: {
@@ -9262,6 +9413,19 @@ export interface operations {
500: never;
};
};
+ /** Attaches subscription id to org and projects. */
+ BillingMigrationController_attachSubscriptionId: {
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["AttachSubscriptionIdBody"];
+ };
+ };
+ responses: {
+ 200: never;
+ /** @description Failed to preview org billing organization */
+ 500: never;
+ };
+ };
/** Handle update project jwt on completion */
ProjectUpdateJwtController_completeUpdateJwt: {
parameters: {
@@ -9274,6 +9438,24 @@ export interface operations {
201: never;
};
};
+ /** Gets usage stats */
+ OrgUsageSystemController_getDailyStats: {
+ parameters: {
+ path: {
+ /** @description Organization slug */
+ slug: string;
+ };
+ };
+ responses: {
+ 200: {
+ content: {
+ "application/json": components["schemas"]["OrgUsageResponse"];
+ };
+ };
+ /** @description Failed to get usage stats */
+ 500: never;
+ };
+ };
/** Processes Vercel event */
VercelWebhooksController_processEvent: {
parameters: {
@@ -9365,7 +9547,7 @@ export interface operations {
"application/json": components["schemas"]["BranchDetailResponse"];
};
};
- /** @description Failed to update database branch */
+ /** @description Failed to retrieve database branch */
500: never;
};
};
@@ -10025,6 +10207,28 @@ export interface operations {
500: never;
};
};
+ /** Gets project's service health status */
+ ServiceHealthController_checkServiceHealth: {
+ parameters: {
+ query: {
+ timeout_ms?: number;
+ services: ("auth" | "realtime" | "rest" | "storage")[];
+ };
+ path: {
+ /** @description Project ref */
+ ref: string;
+ };
+ };
+ responses: {
+ 200: {
+ content: {
+ "application/json": (components["schemas"]["ServiceHealthResponse"])[];
+ };
+ };
+ /** @description Failed to retrieve project's service health status */
+ 500: never;
+ };
+ };
/** Gets project's Postgres config */
AuthPostgresConfigController_getConfig: {
parameters: {
@@ -10274,6 +10478,23 @@ export interface operations {
500: never;
};
};
+ /** Restores a PITR backup for a database */
+ V1RestorePitrController_v1RestorePitr: {
+ parameters: {
+ path: {
+ /** @description Project ref */
+ ref: string;
+ };
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["V1RestorePitrBody"];
+ };
+ };
+ responses: {
+ 201: never;
+ };
+ };
/**
* Retrieve a function
* @description Retrieves a function with the specified slug and project.
@@ -10475,4 +10696,66 @@ export interface operations {
500: never;
};
};
+ /** Redirects to Supabase dashboard after Fly sso with Gotrue */
+ CallbackController_redirectToDashboardFlyioExtensionScreen: {
+ responses: {
+ 200: never;
+ };
+ };
+ /** Gets database status */
+ ExtensionController_getResourceStatus: {
+ parameters: {
+ path: {
+ extension_id: string;
+ };
+ };
+ responses: {
+ 200: {
+ content: {
+ "application/json": components["schemas"]["ResourceStatusResponse"];
+ };
+ };
+ };
+ };
+ /** Starts Flyio single sign on */
+ ExtensionController_startFlyioSSO: {
+ parameters: {
+ path: {
+ extension_id: string;
+ };
+ };
+ responses: {
+ 200: never;
+ };
+ };
+ /** Gets resource billing */
+ ExtensionController_getResourceBilling: {
+ parameters: {
+ path: {
+ extension_id: string;
+ };
+ };
+ responses: {
+ 200: {
+ content: {
+ "application/json": Record<string, never>;
+ };
+ };
+ };
+ };
+ /** Creates a database */
+ ExtensionsController_provisionResource: {
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["ResourceProvisioningBody"];
+ };
+ };
+ responses: {
+ 201: {
+ content: {
+ "application/json": components["schemas"]["ResourceProvisioningResponse"];
+ };
+ };
+ };
+ };
}
diff --git a/studio/data/projects/project-restore-mutation.ts b/studio/data/projects/project-restore-mutation.ts
index 87c2626eb86..4fe249a0952 100644
--- a/studio/data/projects/project-restore-mutation.ts
+++ b/studio/data/projects/project-restore-mutation.ts
@@ -11,6 +11,7 @@ export type ProjectRestoreVariables = {
export async function restoreProject({ ref }: ProjectRestoreVariables) {
const { data, error } = await post('/platform/projects/{ref}/restore', {
params: { path: { ref } },
+ // @ts-ignore
body: {},
})
if (error) throw error
diff --git a/studio/data/service-status/edge-functions-status-query.ts b/studio/data/service-status/edge-functions-status-query.ts
new file mode 100644
index 00000000000..6e8eacaca36
--- /dev/null
+++ b/studio/data/service-status/edge-functions-status-query.ts
@@ -0,0 +1,35 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+
+import { get } from 'lib/common/fetch'
+import { ResponseError } from 'types'
+import { serviceStatusKeys } from './keys'
+
+export type EdgeFunctionServiceStatusVariables = {
+ projectRef?: string
+}
+
+export async function getEdgeFunctionServiceStatus(signal?: AbortSignal) {
+ const res = await get(`https://obuldanrptloktxcffvn.supabase.co/functions/v1/health-check`, {
+ signal,
+ })
+ return res as { healthy: boolean }
+}
+
+export type EdgeFunctionServiceStatusData = Awaited<ReturnType<typeof getEdgeFunctionServiceStatus>>
+export type EdgeFunctionServiceStatusError = ResponseError
+
+export const useEdgeFunctionServiceStatusQuery = <TData = EdgeFunctionServiceStatusData>(
+ { projectRef }: EdgeFunctionServiceStatusVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<EdgeFunctionServiceStatusData, EdgeFunctionServiceStatusError, TData> = {}
+) =>
+ useQuery<EdgeFunctionServiceStatusData, EdgeFunctionServiceStatusError, TData>(
+ serviceStatusKeys.edgeFunctions(projectRef),
+ ({ signal }) => getEdgeFunctionServiceStatus(signal),
+ {
+ enabled: enabled && typeof projectRef !== 'undefined',
+ ...options,
+ }
+ )
diff --git a/studio/data/service-status/keys.ts b/studio/data/service-status/keys.ts
new file mode 100644
index 00000000000..533e8799e7a
--- /dev/null
+++ b/studio/data/service-status/keys.ts
@@ -0,0 +1,10 @@
+export const serviceStatusKeys = {
+ postgres: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'service-status', 'postgres'] as const,
+ pooler: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'service-status', 'pooler'] as const,
+ serviceStatus: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'service-status'] as const,
+ edgeFunctions: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'service-status', 'edge-functions'] as const,
+}
diff --git a/studio/data/service-status/pooler-service-status-query.ts b/studio/data/service-status/pooler-service-status-query.ts
new file mode 100644
index 00000000000..51df2547198
--- /dev/null
+++ b/studio/data/service-status/pooler-service-status-query.ts
@@ -0,0 +1,52 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+
+import { post } from 'lib/common/fetch'
+import { ResponseError } from 'types'
+import { serviceStatusKeys } from './keys'
+import { API_URL } from 'lib/constants'
+
+// [Joshen] Need API to return a separate connectionString for pooler before we can do this
+
+export type PoolerServiceStatusVariables = {
+ projectRef?: string
+ connectionString?: string
+}
+
+export async function getPoolerServiceStatus(
+ { projectRef, connectionString }: PoolerServiceStatusVariables,
+ 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 response = await post(
+ `${API_URL}/pg-meta/${projectRef}/query?key=service_status`,
+ { query: 'select 1' },
+ { headers: Object.fromEntries(headers), signal }
+ )
+
+ return response.error === undefined
+}
+
+export type PoolerServiceStatusData = Awaited<ReturnType<typeof getPoolerServiceStatus>>
+export type PoolerServiceStatusError = ResponseError
+
+export const usePoolerServiceStatusQuery = <TData = PoolerServiceStatusData>(
+ { projectRef, connectionString }: PoolerServiceStatusVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<PoolerServiceStatusData, PoolerServiceStatusError, TData> = {}
+) =>
+ useQuery<PoolerServiceStatusData, PoolerServiceStatusError, TData>(
+ serviceStatusKeys.postgres(projectRef),
+ ({ signal }) => getPoolerServiceStatus({ projectRef, connectionString }, signal),
+ {
+ enabled:
+ enabled && typeof projectRef !== 'undefined' && typeof connectionString !== 'undefined',
+ ...options,
+ }
+ )
diff --git a/studio/data/service-status/postgres-service-status-query.ts b/studio/data/service-status/postgres-service-status-query.ts
new file mode 100644
index 00000000000..d311f4dce48
--- /dev/null
+++ b/studio/data/service-status/postgres-service-status-query.ts
@@ -0,0 +1,51 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+
+import { post } from 'lib/common/fetch'
+import { ResponseError } from 'types'
+import { serviceStatusKeys } from './keys'
+import { API_URL } from 'lib/constants'
+
+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 response = await post(
+ `${API_URL}/pg-meta/${projectRef}/query?key=service_status`,
+ { query: 'select 1' },
+ { headers: Object.fromEntries(headers), signal }
+ )
+
+ if (response.error) throw response.error
+ return response.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',
+ ...options,
+ }
+ )
diff --git a/studio/data/service-status/service-status-query.ts b/studio/data/service-status/service-status-query.ts
new file mode 100644
index 00000000000..38c82b0e23e
--- /dev/null
+++ b/studio/data/service-status/service-status-query.ts
@@ -0,0 +1,48 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+
+import { get } from 'data/fetchers'
+import { ResponseError } from 'types'
+import { serviceStatusKeys } from './keys'
+
+export type ProjectServiceStatusVariables = {
+ projectRef?: string
+}
+
+export async function getProjectServiceStatus(
+ { projectRef }: ProjectServiceStatusVariables,
+ signal?: AbortSignal
+) {
+ if (!projectRef) throw new Error('projectRef is required')
+
+ const { data, error } = await get(`/v1/projects/{ref}/health`, {
+ params: {
+ path: { ref: projectRef },
+ query: {
+ services: ['auth', 'realtime', 'rest', 'storage'],
+ },
+ },
+ signal,
+ })
+
+ if (error) throw error
+ return data
+}
+
+export type ProjectServiceStatusData = Awaited<ReturnType<typeof getProjectServiceStatus>>
+export type ProjectServiceStatusError = ResponseError
+
+export const useProjectServiceStatusQuery = <TData = ProjectServiceStatusData>(
+ { projectRef }: ProjectServiceStatusVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<ProjectServiceStatusData, ProjectServiceStatusError, TData> = {}
+) =>
+ useQuery<ProjectServiceStatusData, ProjectServiceStatusError, TData>(
+ serviceStatusKeys.serviceStatus(projectRef),
+ ({ signal }) => getProjectServiceStatus({ projectRef }, signal),
+ {
+ enabled: enabled && typeof projectRef !== 'undefined',
+ ...options,
+ }
+ )
diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsx
index ab163a209d0..97b4be6529d 100644
--- a/studio/pages/project/[ref]/index.tsx
+++ b/studio/pages/project/[ref]/index.tsx
@@ -1,6 +1,7 @@
import { ClientLibrary, ExampleProject } from 'components/interfaces/Home'
import { CLIENT_LIBRARIES, EXAMPLE_PROJECTS } from 'components/interfaces/Home/Home.constants'
import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
+import ServiceStatus from 'components/interfaces/Home/ServiceStatus'
import { ProjectLayoutWithAuth } from 'components/layouts'
import ProjectPausedState from 'components/layouts/ProjectLayout/ProjectPausedState'
import ProjectUpgradeFailedBanner from 'components/ui/ProjectUpgradeFailedBanner'
@@ -18,8 +19,9 @@ const Home: NextPageWithLayout = () => {
return (
<div className="w-full mx-auto my-16 space-y-16 max-w-7xl">
- <div className="flex items-center mx-6 space-x-6">
+ <div className="flex items-center justify-between mx-6 space-x-6">
<h1 className="text-3xl">{projectName}</h1>
+ {IS_PLATFORM && <ServiceStatus />}
</div>
<div className="mx-6">