-
Notifications
You must be signed in to change notification settings - Fork 0
fix: accept postgres:// in PrismaClientConfigSchema + Neon-aware health probe #1406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import type { Env } from '../types.ts'; | |
| export async function handleHealth(env: Env): Promise<Response> { | ||
| type ServiceStatus = 'healthy' | 'degraded' | 'down'; | ||
| type ServiceResult = { status: ServiceStatus; latency_ms?: number }; | ||
| type DatabaseResult = ServiceResult & { db_name?: string; hyperdrive_host?: string }; | ||
|
|
||
| const probe = async (fn: () => Promise<void>): Promise<ServiceResult> => { | ||
| const t0 = Date.now(); | ||
|
|
@@ -37,13 +38,46 @@ export async function handleHealth(env: Env): Promise<Response> { | |
| } | ||
| }; | ||
|
|
||
| // Extended database probe: verify connectivity AND confirm we're on the correct | ||
| // production database. Returns db_name and hyperdrive_host for observability. | ||
| const databaseProbe = async (): Promise<DatabaseResult> => { | ||
| if (!env.HYPERDRIVE) { | ||
| return { status: 'down' }; | ||
| } | ||
| const t0 = Date.now(); | ||
| try { | ||
| const prisma = _internals.createPrismaClient(env.HYPERDRIVE.connectionString); | ||
| const rows = await prisma.$queryRaw<Array<{ db_name: string }>>` | ||
| SELECT current_database() AS db_name | ||
| `; | ||
| const dbName = rows[0]?.db_name ?? 'unknown'; | ||
| const latency_ms = Date.now() - t0; | ||
| // Fail-fast guard: warn if connected to wrong database | ||
| if (dbName !== 'adblock-compiler') { | ||
| return { | ||
| status: 'degraded', | ||
| latency_ms, | ||
| db_name: dbName, | ||
| hyperdrive_host: env.HYPERDRIVE.host, | ||
| }; | ||
| } | ||
| return { | ||
| status: 'healthy', | ||
| latency_ms, | ||
| db_name: dbName, | ||
| hyperdrive_host: env.HYPERDRIVE.host, | ||
| }; | ||
| } catch { | ||
| return { | ||
| status: 'down', | ||
| latency_ms: Date.now() - t0, | ||
| hyperdrive_host: env.HYPERDRIVE?.host, | ||
| }; | ||
|
Comment on lines
+53
to
+75
|
||
| } | ||
| }; | ||
|
|
||
| const [database, cache] = await Promise.all([ | ||
| env.HYPERDRIVE | ||
| ? probe(async () => { | ||
| const prisma = _internals.createPrismaClient(env.HYPERDRIVE!.connectionString); | ||
| await prisma.$queryRaw`SELECT 1`; | ||
| }) | ||
| : Promise.resolve<ServiceResult>({ status: 'down' }), | ||
| databaseProbe(), | ||
| probe(async () => { | ||
| await env.COMPILATION_CACHE.list({ limit: 1 }); | ||
| }), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment describes this as a “production database” probe and says the endpoint exposes “no sensitive data”, but the handler now returns DB metadata and the file header still mentions a D1
SELECT 1probe. Please update the documentation comments to match the current Hyperdrive/Prisma probe behavior and the data actually returned.