Skip to content
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

feat: include support for metrics #131

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 113 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@
"express": "^4.17.1",
"express-fileupload": "^1.4.0",
"express-openapi-validator": "^5.0.4",
"express-prom-bundle": "^7.0.0",
"express-session": "^1.17.1",
"http-status-codes": "^2.1.4",
"ipfs-http-client": "^56.0.3",
"ipfs-http-gateway": "0.9.3",
"json-refs": "^3.0.15",
"memorystore": "^1.6.7",
"node-fetch": "2.6.6",
"prom-client": "^15.1.0",
"puppeteer": "^20.7.4",
"serve-index": "^1.9.1",
"solc": "^0.8.17",
Expand Down Expand Up @@ -131,4 +133,4 @@
"text-summary"
]
}
}
}
35 changes: 35 additions & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import { initDeprecatedRoutes } from "./deprecated.routes";
import { getAddress } from "ethers";
import { logger } from "../common/loggerLoki";
import { setLibSourcifyLogger } from "@ethereum-sourcify/lib-sourcify";

import promBundle from "express-prom-bundle";
import { SourcifyEventManager } from "../common/SourcifyEventManager/SourcifyEventManager";

import client from "prom-client";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const fileUpload = require("express-fileupload");

Expand Down Expand Up @@ -175,6 +181,35 @@ export class Server {
next();
});

// Add the options to the prometheus middleware most option are for http_request_duration_seconds histogram metric
const metricsMiddleware = promBundle({
includeMethod: true,
includePath: true,
includeStatusCode: true,
includeUp: true,
httpDurationMetricName: "sourcify_http_request_duration_seconds",
promClient: {
collectDefaultMetrics: {
prefix: "sourcify_",
}
}
});
// add the prometheus middleware to all routes
this.app.use(metricsMiddleware);

const counter = new client.Counter({
name: "sourcify_event_count",
help: "events that happened during verification labeled with: event and chainId",
labelNames: ["event", "chainId"],
});

SourcifyEventManager.on("*", [
(event: string, argument: any) => {
const chainId = argument.chainId;
counter.labels({ event, chainId }).inc(1);
},
]);

// Session API endpoints require non "*" origins because of the session cookies
const sessionPaths = [
"/session", // all paths /session/verify /session/input-files etc.
Expand Down
Loading