From 85a5b83ab80b3b9df63840efc8232a0dde7dfee9 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 5 Feb 2025 13:59:28 -0800 Subject: [PATCH] fix DU operations --- .../distributedUptimeController.js | 1 + Server/db/mongo/MongoDB.js | 6 +++++ .../mongo/modules/distributedCheckModule.js | 15 ++++++++++++ Server/db/mongo/modules/monitorModule.js | 24 +++++++++++++++++++ Server/index.js | 6 ++++- 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Server/db/mongo/modules/distributedCheckModule.js diff --git a/Server/controllers/distributedUptimeController.js b/Server/controllers/distributedUptimeController.js index ee8f5398e..09c1497cf 100644 --- a/Server/controllers/distributedUptimeController.js +++ b/Server/controllers/distributedUptimeController.js @@ -138,6 +138,7 @@ class DistributedUptimeController { clearInterval(keepAlive); }); } catch (error) { + console.log(error); next(handleError(error, SERVICE_NAME, "getDistributedUptimeMonitors")); } } diff --git a/Server/db/mongo/MongoDB.js b/Server/db/mongo/MongoDB.js index e62828a41..8f035c2dc 100644 --- a/Server/db/mongo/MongoDB.js +++ b/Server/db/mongo/MongoDB.js @@ -43,6 +43,11 @@ import * as hardwareCheckModule from "./modules/hardwareCheckModule.js"; import * as checkModule from "./modules/checkModule.js"; +//**************************************** +// Distributed Checks +//**************************************** +import * as distributedCheckModule from "./modules/distributedCheckModule.js"; + //**************************************** // Maintenance Window //**************************************** @@ -74,6 +79,7 @@ class MongoDB { Object.assign(this, pageSpeedCheckModule); Object.assign(this, hardwareCheckModule); Object.assign(this, checkModule); + Object.assign(this, distributedCheckModule); Object.assign(this, maintenanceWindowModule); Object.assign(this, notificationModule); Object.assign(this, settingsModule); diff --git a/Server/db/mongo/modules/distributedCheckModule.js b/Server/db/mongo/modules/distributedCheckModule.js new file mode 100644 index 000000000..5c7fb09a8 --- /dev/null +++ b/Server/db/mongo/modules/distributedCheckModule.js @@ -0,0 +1,15 @@ +import DistributedUptimeCheck from "../../models/DistributedUptimeCheck.js"; +const SERVICE_NAME = "distributedCheckModule"; + +const createDistributedCheck = async (checkData) => { + try { + const check = await new DistributedUptimeCheck({ ...checkData }).save(); + return check; + } catch (error) { + error.service = SERVICE_NAME; + error.method = "createCheck"; + throw error; + } +}; + +export { createDistributedCheck }; diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index c3d1a38be..66ff2df6e 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -674,6 +674,26 @@ const getMonitorsByTeamId = async (req) => { }, ] : []), + ...(limit + ? [ + { + $lookup: { + from: "distributeduptimechecks", + let: { monitorId: "$_id" }, + pipeline: [ + { + $match: { + $expr: { $eq: ["$monitorId", "$$monitorId"] }, + }, + }, + { $sort: { createdAt: -1 } }, + ...(limit ? [{ $limit: limit }] : []), + ], + as: "distributeduptimechecks", + }, + }, + ] + : []), { $addFields: { @@ -692,6 +712,10 @@ const getMonitorsByTeamId = async (req) => { case: { $eq: ["$type", "hardware"] }, then: "$hardwarechecks", }, + { + case: { $eq: ["$type", "distributed_http"] }, + then: "$distributeduptimechecks", + }, ], default: [], }, diff --git a/Server/index.js b/Server/index.js index 7a4129bc9..23d16856a 100644 --- a/Server/index.js +++ b/Server/index.js @@ -244,7 +244,11 @@ const startApp = async () => { ServiceRegistry.get(MongoDB.SERVICE_NAME) ); - const distributedUptimeController = new DistributedUptimeController(); + const distributedUptimeController = new DistributedUptimeController( + ServiceRegistry.get(MongoDB.SERVICE_NAME), + http, + ServiceRegistry.get(StatusService.SERVICE_NAME) + ); //Create routes const authRoutes = new AuthRoutes(authController);