From 4d989746fda146c7bf6020a1c8e374f3f6e05da3 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 21 Jul 2025 12:04:16 -0700 Subject: [PATCH] remove unused routes, add authentication --- server/controllers/diagnosticController.js | 66 ++++------------------ server/routes/diagnosticRoute.js | 6 +- 2 files changed, 15 insertions(+), 57 deletions(-) diff --git a/server/controllers/diagnosticController.js b/server/controllers/diagnosticController.js index 774af8d7d..6ba880dcb 100755 --- a/server/controllers/diagnosticController.js +++ b/server/controllers/diagnosticController.js @@ -12,62 +12,20 @@ obs.observe({ entryTypes: ["measure"] }); class DiagnosticController { constructor(db) { this.db = db; - this.getMonitorsByTeamIdExecutionStats = this.getMonitorsByTeamIdExecutionStats.bind(this); - this.getDbStats = this.getDbStats.bind(this); } - getMonitorsByTeamIdExecutionStats = asyncHandler( - async (req, res, next) => { - const data = await this.db.getMonitorsByTeamIdExecutionStats(req); - return res.success({ - msg: "OK", - data, - }); - }, - SERVICE_NAME, - "getMonitorsByTeamIdExecutionStats" - ); - - getDbStats = asyncHandler( - async (req, res, next) => { - const { methodName, args = [] } = req.body; - if (!methodName || !this.db[methodName]) { - return res.error({ - msg: "Invalid method name or method doesn't exist", - status: 400, - }); - } - const explainMethod = await this.db[methodName].apply(this.db, args); - const stats = { - methodName, - timestamp: new Date(), - explain: explainMethod, - }; - return res.success({ - msg: "OK", - data: stats, - }); - }, - SERVICE_NAME, - "getDbStats" - ); - - getCPUUsage = asyncHandler( - async (req, res, next) => { - const startUsage = process.cpuUsage(); - const timingPeriod = 1000; // measured in ms - await new Promise((resolve) => setTimeout(resolve, timingPeriod)); - const endUsage = process.cpuUsage(startUsage); - const cpuUsage = { - userUsageMs: endUsage.user / 1000, - systemUsageMs: endUsage.system / 1000, - usagePercentage: ((endUsage.user + endUsage.system) / 1000 / timingPeriod) * 100, - }; - return cpuUsage; - }, - SERVICE_NAME, - "getCPUUsage" - ); + getCPUUsage = async () => { + const startUsage = process.cpuUsage(); + const timingPeriod = 1000; // measured in ms + await new Promise((resolve) => setTimeout(resolve, timingPeriod)); + const endUsage = process.cpuUsage(startUsage); + const cpuUsage = { + userUsageMs: endUsage.user / 1000, + systemUsageMs: endUsage.system / 1000, + usagePercentage: ((endUsage.user + endUsage.system) / 1000 / timingPeriod) * 100, + }; + return cpuUsage; + }; getSystemStats = asyncHandler( async (req, res, next) => { diff --git a/server/routes/diagnosticRoute.js b/server/routes/diagnosticRoute.js index 28f31a622..a15f5a038 100755 --- a/server/routes/diagnosticRoute.js +++ b/server/routes/diagnosticRoute.js @@ -1,4 +1,6 @@ import { Router } from "express"; +import { verifyJWT } from "../middleware/verifyJWT.js"; +import { isAllowed } from "../middleware/isAllowed.js"; class DiagnosticRoutes { constructor(diagnosticController) { @@ -7,9 +9,7 @@ class DiagnosticRoutes { this.initRoutes(); } initRoutes() { - this.router.post("/db/stats", this.diagnosticController.getDbStats); - this.router.get("/system", this.diagnosticController.getSystemStats); - this.router.get("/db/get-monitors-by-team-id/:teamId", this.diagnosticController.getMonitorsByTeamIdExecutionStats); + this.router.get("/system", verifyJWT, isAllowed(["admin", "superadmin"]), this.diagnosticController.getSystemStats); } getRouter() {