Merge pull request #1527 from bluewave-labs/fix/fe/simplify-monitor-summary

remove monitors from summary, unused
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-01-07 14:54:52 -08:00
commit cba6734623
8 files changed
+87 -67

No files matched your search

+6 -6
View File
@@ -5,8 +5,8 @@ import {
createMonitorBodyValidation,
getMonitorURLByQueryValidation,
editMonitorBodyValidation,
getMonitorsAndSummaryByTeamIdParamValidation,
getMonitorsAndSummaryByTeamIdQueryValidation,
getMonitorsSummaryByTeamIdParamValidation,
getMonitorsSummaryByTeamIdQueryValidation,
getMonitorsByTeamIdQueryValidation,
pauseMonitorParamValidation,
getMonitorStatsByIdParamValidation,
@@ -217,10 +217,10 @@ class MonitorController {
* @returns {Object} The response object with a success status, a message, and the data containing the monitors and summary for the team.
* @throws {Error} If there is an error during the process, especially if there is a validation error (422).
*/
getMonitorsAndSummaryByTeamId = async (req, res, next) => {
getMonitorsSummaryByTeamId = async (req, res, next) => {
try {
await getMonitorsAndSummaryByTeamIdParamValidation.validateAsync(req.params);
await getMonitorsAndSummaryByTeamIdQueryValidation.validateAsync(req.query);
await getMonitorsSummaryByTeamIdParamValidation.validateAsync(req.params);
await getMonitorsSummaryByTeamIdQueryValidation.validateAsync(req.query);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
@@ -229,7 +229,7 @@ class MonitorController {
try {
const { teamId } = req.params;
const { type } = req.query;
const monitorsSummary = await this.db.getMonitorsAndSummaryByTeamId(teamId, type);
const monitorsSummary = await this.db.getMonitorsSummaryByTeamId(teamId, type);
return res.status(200).json({
success: true,
msg: successMessages.MONITOR_GET_BY_USER_ID(teamId),
+25 -17
View File
@@ -513,24 +513,32 @@ const getMonitorById = async (monitorId) => {
* @throws {Error}
*/
const getMonitorsAndSummaryByTeamId = async (teamId, type) => {
const getMonitorsSummaryByTeamId = async (teamId, type) => {
try {
const monitors = await Monitor.find({ teamId, type });
const monitorCounts = monitors.reduce(
(acc, monitor) => {
if (monitor.status === true) {
acc.up += 1;
} else if (monitor.status === false) {
acc.down += 1;
} else if (monitor.isActive === false) {
acc.paused += 1;
}
return acc;
const monitorCounts = await Monitor.aggregate([
{
$match: {
type: { $in: type },
},
},
{ up: 0, down: 0, paused: 0 }
);
monitorCounts.total = monitors.length;
return { monitors, monitorCounts };
{
$facet: {
total: [{ $count: "count" }],
up: [{ $match: { status: true } }, { $count: "count" }],
down: [{ $match: { status: false } }, { $count: "count" }],
paused: [{ $match: { isActive: false } }, { $count: "count" }],
},
},
{
$project: {
total: { $arrayElemAt: ["$total.count", 0] },
up: { $arrayElemAt: ["$up.count", 0] },
down: { $arrayElemAt: ["$down.count", 0] },
paused: { $arrayElemAt: ["$paused.count", 0] },
},
},
]);
return { monitorCounts: monitorCounts[0] };
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getMonitorsAndSummaryByTeamId";
@@ -751,7 +759,7 @@ export {
getMonitorStatsById,
getMonitorById,
getUptimeDetailsById,
getMonitorsAndSummaryByTeamId,
getMonitorsSummaryByTeamId,
getMonitorsByTeamId,
createMonitor,
deleteMonitor,
+1 -1
View File
@@ -32,7 +32,7 @@ class MonitorRoutes {
this.router.get("/:monitorId", this.monitorController.getMonitorById);
this.router.get(
"/team/summary/:teamId",
this.monitorController.getMonitorsAndSummaryByTeamId
this.monitorController.getMonitorsSummaryByTeamId
);
this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId);
+41 -29
View File
@@ -218,38 +218,50 @@ class NewJobQueue {
concurrency: 5,
});
worker.on("active", (job) => {
this.logger.info({
message: `Worker started processing job: ${job.id}`,
service: SERVICE_NAME,
method: "createWorker",
});
});
// worker.on("active", (job) => {
// this.logger.info({
// message: `Worker started processing job: ${job.id}`,
// service: SERVICE_NAME,
// method: "createWorker",
// });
// });
worker.on("completed", (job) => {
this.logger.info({
message: `Worker completed job: ${job.id}`,
service: SERVICE_NAME,
method: "createWorker",
});
});
// worker.on("completed", (job) => {
// this.logger.info({
// message: `Worker completed job: ${job.id}`,
// service: SERVICE_NAME,
// method: "createWorker",
// });
// });
worker.on("failed", (job, err) => {
this.logger.error({
message: `Worker failed job: ${job.id}`,
service: SERVICE_NAME,
method: "createWorker",
stack: err.stack,
});
});
// // Log job progress updates
// worker.on("progress", (job, progress) => {
// this.logger.info({
// message: `Job progress: ${job.id}`,
// service: SERVICE_NAME,
// method: "createWorker",
// details: `Progress: ${progress}%`,
// });
// });
worker.on("stalled", (jobId) => {
this.logger.warn({
message: `Worker stalled job: ${jobId}`,
service: SERVICE_NAME,
method: "createWorker",
});
});
// // Log when a job fails
// worker.on("failed", (job, err) => {
// this.logger.error({
// message: `Worker failed job: ${job.id}`,
// service: SERVICE_NAME,
// method: "createWorker",
// details: `Error: ${err.message}`,
// stack: err.stack,
// });
// });
// worker.on("stalled", (jobId) => {
// this.logger.warn({
// message: `Worker stalled job: ${jobId}`,
// service: SERVICE_NAME,
// method: "createWorker",
// });
// });
return worker;
}
+1 -1
View File
@@ -2,7 +2,7 @@ const SERVICE_NAME = "SettingsService";
import dotenv from "dotenv";
dotenv.config();
const envConfig = {
logLevel: undefined,
logLevel: process.env.LOG_LEVEL,
apiBaseUrl: undefined,
clientHost: process.env.CLIENT_HOST,
jwtSecret: process.env.JWT_SECRET,
+4 -4
View File
@@ -136,11 +136,11 @@ const getMonitorByIdQueryValidation = joi.object({
normalize: joi.boolean(),
});
const getMonitorsAndSummaryByTeamIdParamValidation = joi.object({
const getMonitorsSummaryByTeamIdParamValidation = joi.object({
teamId: joi.string().required(),
});
const getMonitorsAndSummaryByTeamIdQueryValidation = joi.object({
const getMonitorsSummaryByTeamIdQueryValidation = joi.object({
type: joi
.alternatives()
.try(
@@ -467,8 +467,8 @@ export {
createMonitorBodyValidation,
getMonitorByIdParamValidation,
getMonitorByIdQueryValidation,
getMonitorsAndSummaryByTeamIdParamValidation,
getMonitorsAndSummaryByTeamIdQueryValidation,
getMonitorsSummaryByTeamIdParamValidation,
getMonitorsSummaryByTeamIdQueryValidation,
getMonitorsByTeamIdValidation,
getMonitorsByTeamIdQueryValidation,
getMonitorStatsByIdParamValidation,