File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
internal-packages/database/prisma Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { LoaderFunctionArgs } from "@remix-run/server-runtime" ;
2
+ import { prisma } from "~/db.server" ;
2
3
import { metricsRegister } from "~/metrics.server" ;
3
4
4
5
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 , {
6
20
headers : {
7
21
"Content-Type" : metricsRegister . contentType ,
8
22
} ,
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ datasource db {
7
7
generator client {
8
8
provider = " prisma-client-js "
9
9
binaryTargets = [" native " , " debian-openssl-1.1.x " ]
10
- previewFeatures = [" tracing " ]
10
+ previewFeatures = [" tracing " , " metrics " ]
11
11
}
12
12
13
13
model User {
You can’t perform that action at this time.
0 commit comments