Skip to content

Commit 0410316

Browse files
authored
Enable prisma metrics and add them to the /metrics endpoint (#2111)
* Enable prisma metrics and add them to the /metrics endpoint * Add support for bearer token auth on metrics endpoint
1 parent c571c5e commit 0410316

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

apps/webapp/app/routes/metrics.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import { LoaderFunctionArgs } from "@remix-run/server-runtime";
2+
import { prisma } from "~/db.server";
23
import { metricsRegister } from "~/metrics.server";
34

45
export async function loader({ request }: LoaderFunctionArgs) {
5-
return new Response(await metricsRegister.metrics(), {
6+
// If the TRIGGER_METRICS_AUTH_PASSWORD is set, we need to check if the request has the correct password in auth header
7+
const authPassword = process.env.TRIGGER_METRICS_AUTH_PASSWORD;
8+
9+
if (authPassword) {
10+
const auth = request.headers.get("Authorization");
11+
if (auth !== `Bearer ${authPassword}`) {
12+
return new Response("Unauthorized", { status: 401 });
13+
}
14+
}
15+
16+
const prismaMetrics = await prisma.$metrics.prometheus();
17+
const coreMetrics = await metricsRegister.metrics();
18+
19+
return new Response(coreMetrics + prismaMetrics, {
620
headers: {
721
"Content-Type": metricsRegister.contentType,
822
},

internal-packages/database/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ datasource db {
77
generator client {
88
provider = "prisma-client-js"
99
binaryTargets = ["native", "debian-openssl-1.1.x"]
10-
previewFeatures = ["tracing"]
10+
previewFeatures = ["tracing", "metrics"]
1111
}
1212

1313
model User {

0 commit comments

Comments
 (0)