Skip to content

Commit 50a799a

Browse files
committed
chore: add metrics
1 parent b813a55 commit 50a799a

File tree

3 files changed

+3068
-1988
lines changed

3 files changed

+3068
-1988
lines changed

Diff for: apps/worker/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "tsc && devScript --copyOnly"
88
},
99
"dependencies": {
10+
"@bmatei/apollo-prometheus-exporter": "^3.0.0",
1011
"@sentry/node": "6.19.7",
1112
"@sentry/tracing": "6.19.7",
1213
"apollo-server-cache-redis": "3.3.1",
@@ -18,6 +19,7 @@
1819
"archiver": "7.0.1",
1920
"axios": "0.27.0",
2021
"discord-api-types": "0.37.100",
22+
"express": "^4.21.2",
2123
"fastify": "3.29.5",
2224
"graphql": "16.9.0",
2325
"ioredis": "5.4.1",
@@ -28,11 +30,13 @@
2830
"mongodb": "4.17.2",
2931
"mongodb-caching": "1.1.0",
3032
"p-event": "6.0.1",
33+
"prom-client": "^15.1.3",
3134
"source-map-support": "0.5.21",
3235
"validator": "13.12.0"
3336
},
3437
"devDependencies": {
3538
"@types/archiver": "6.0.2",
39+
"@types/express": "^5.0.0",
3640
"@types/lodash": "4.17.7",
3741
"@types/node": "22.5.5",
3842
"@types/validator": "13.12.2",

Diff for: apps/worker/src/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import { resolvers as v3Resolvers } from "./v3/resolvers";
2828
import { typeDefs as v3TypeDefs } from "./v3/typeDefinition";
2929
import { resolvers as v4Resolvers } from "./v4/resolvers";
3030
import { typeDefs as v4TypeDefs } from "./v4/typeDefinition";
31+
import { createPrometheusExporterPlugin } from "@bmatei/apollo-prometheus-exporter";
32+
import express from "express";
33+
import { Counter, Registry } from "prom-client";
3134

3235
if (process.env.NODE_ENV !== "production")
3336
require("dotenv").config({ path: "../../../.env" });
@@ -70,7 +73,16 @@ export interface Context {
7073
transaction: Transaction;
7174
}
7275

76+
const pathMetric = new Counter({
77+
name: "premid_old_api_path",
78+
help: "The path of the request",
79+
labelNames: ["path"]
80+
});
81+
7382
async function run() {
83+
const registry = new Registry();
84+
registry.registerMetric(pathMetric);
85+
const expressApp = express();
7486
redis.setMaxListeners(12);
7587
redis.on("error", error => {
7688
console.log(error);
@@ -103,6 +115,7 @@ async function run() {
103115
introspection: true,
104116
cache: baseRedisCache,
105117
plugins: [
118+
createPrometheusExporterPlugin({ app: expressApp, register: registry }),
106119
sentryPlugin,
107120
fastifyAppClosePlugin(app),
108121
ApolloServerPluginDrainHttpServer({ httpServer: app.server }),
@@ -134,6 +147,7 @@ async function run() {
134147
});
135148

136149
app.addHook("onRequest", async (req, reply) => {
150+
pathMetric.labels(req.url).inc();
137151
//@ts-ignore
138152
req.responseTimeCalc = process.hrtime();
139153
reply.headers({
@@ -248,6 +262,8 @@ async function run() {
248262
.then(url => {
249263
console.log(`🚀 API Listening on ${url}`);
250264
});
265+
266+
expressApp.listen(2112, "0.0.0.0");
251267
}
252268

253269
run();

0 commit comments

Comments
 (0)