mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Add adhoc REST call debug stats
This commit is contained in:
parent
3bc0015dbe
commit
07f23d4137
6 changed files with 79 additions and 8 deletions
35
backend/src/restCallStats.ts
Normal file
35
backend/src/restCallStats.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { sorter } from "./utils";
|
||||
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
type CallStats = { method: string; path: string; source: string; count: number };
|
||||
const restCallStats: Map<string, CallStats> = new Map();
|
||||
|
||||
const looseSnowflakeRegex = /\d{15,}/g;
|
||||
const queryParamsRegex = /\?.*$/g;
|
||||
|
||||
export function logRestCall(method: string, path: string) {
|
||||
const anonymizedPath = path.replace(looseSnowflakeRegex, "0000").replace(queryParamsRegex, "");
|
||||
const stackLines = (new Error().stack || "").split("\n").slice(10); // Remove initial fluff
|
||||
const firstSrcLine = stackLines.findIndex((line) => line.includes("/backend/src"));
|
||||
const source = stackLines
|
||||
.slice(firstSrcLine !== -1 ? firstSrcLine : -5)
|
||||
.filter((l) => !l.includes("processTicksAndRejections"))
|
||||
.join("\n");
|
||||
const key = `${method}|${anonymizedPath}|${source}`;
|
||||
if (!restCallStats.has(key)) {
|
||||
restCallStats.set(key, {
|
||||
method,
|
||||
path: anonymizedPath,
|
||||
source,
|
||||
count: 0,
|
||||
});
|
||||
}
|
||||
restCallStats.get(key)!.count++;
|
||||
}
|
||||
|
||||
export function getTopRestCallStats(count: number): CallStats[] {
|
||||
const stats = Array.from(restCallStats.values());
|
||||
stats.sort(sorter("count", "DESC"));
|
||||
return stats.slice(0, count);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue