mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-11 18:04:27 +08:00
sending different path to prometheus
This commit is contained in:
parent
9acd68e99f
commit
d14a582cb8
3 changed files with 21 additions and 8 deletions
|
|
@ -21,6 +21,10 @@ describe("middlewares/auth", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
mockRequest = {
|
||||
baseUrl: "/api/v1",
|
||||
route: {
|
||||
path: "/",
|
||||
},
|
||||
headers: {
|
||||
authorization: "Bearer 123456789",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -71,18 +71,17 @@ function authenticateRequest(authOptions = DEFAULT_OPTIONS): Handler {
|
|||
recordAuthTime(
|
||||
authType,
|
||||
"failure",
|
||||
req.originalUrl,
|
||||
Math.round(performance.now() - startTime)
|
||||
Math.round(performance.now() - startTime),
|
||||
req
|
||||
);
|
||||
|
||||
return next(error);
|
||||
}
|
||||
|
||||
recordAuthTime(
|
||||
token.type,
|
||||
"success",
|
||||
req.originalUrl,
|
||||
Math.round(performance.now() - startTime)
|
||||
Math.round(performance.now() - startTime),
|
||||
req
|
||||
);
|
||||
|
||||
next();
|
||||
|
|
|
|||
|
|
@ -191,9 +191,19 @@ const authTime = new Histogram({
|
|||
export function recordAuthTime(
|
||||
type: string,
|
||||
status: "success" | "failure",
|
||||
path: string,
|
||||
time: number
|
||||
time: number,
|
||||
req: MonkeyTypes.Request
|
||||
): void {
|
||||
const pathNoGet = path?.replace(/\?.*/, "");
|
||||
const reqPath = req.baseUrl + req.route.path;
|
||||
|
||||
let normalizedPath = "/";
|
||||
if (reqPath !== "/") {
|
||||
normalizedPath = reqPath.endsWith("/") ? reqPath.slice(0, -1) : reqPath;
|
||||
}
|
||||
|
||||
const pathNoGet = normalizedPath.replace(/\?.*/, "");
|
||||
|
||||
console.log(pathNoGet);
|
||||
|
||||
authTime.observe({ type, status, path: pathNoGet }, time);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue