Merge pull request #1527 from bluewave-labs/fix/fe/simplify-monitor-summary
remove monitors from summary, unused
This commit is contained in:
8 files changed
+87
-67
No files matched your search
@@ -58,7 +58,7 @@ const CreateMonitor = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const { monitors, isLoading } = useSelector((state) => state.uptimeMonitors);
|
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -205,7 +205,7 @@ const CreateMonitor = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
}, [monitorId, authToken, monitors, dispatch, navigate]);
|
}, [monitorId, authToken, dispatch, navigate]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="create-monitor">
|
<Box className="create-monitor">
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const UptimeMonitors = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const uptimeMonitorsState = useSelector((state) => state.uptimeMonitors);
|
const { isLoading, monitorsSummary } = useSelector((state) => state.uptimeMonitors);
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const dispatch = useDispatch({});
|
const dispatch = useDispatch({});
|
||||||
const [monitorUpdateTrigger, setMonitorUpdateTrigger] = useState(false);
|
const [monitorUpdateTrigger, setMonitorUpdateTrigger] = useState(false);
|
||||||
@@ -35,9 +35,9 @@ const UptimeMonitors = () => {
|
|||||||
|
|
||||||
//TODO bring fetching to this component, like on pageSpeed
|
//TODO bring fetching to this component, like on pageSpeed
|
||||||
|
|
||||||
const loading = uptimeMonitorsState?.isLoading;
|
const loading = isLoading;
|
||||||
|
|
||||||
const totalMonitors = uptimeMonitorsState?.monitorsSummary?.monitorCounts?.total;
|
const totalMonitors = monitorsSummary?.monitorCounts?.total;
|
||||||
|
|
||||||
const hasMonitors = totalMonitors > 0;
|
const hasMonitors = totalMonitors > 0;
|
||||||
const noMonitors = !hasMonitors;
|
const noMonitors = !hasMonitors;
|
||||||
@@ -86,20 +86,20 @@ const UptimeMonitors = () => {
|
|||||||
>
|
>
|
||||||
<StatusBox
|
<StatusBox
|
||||||
title="up"
|
title="up"
|
||||||
value={uptimeMonitorsState?.monitorsSummary?.monitorCounts?.up ?? 0}
|
value={monitorsSummary?.monitorCounts?.up ?? 0}
|
||||||
/>
|
/>
|
||||||
<StatusBox
|
<StatusBox
|
||||||
title="down"
|
title="down"
|
||||||
value={uptimeMonitorsState?.monitorsSummary?.monitorCounts?.down ?? 0}
|
value={monitorsSummary?.monitorCounts?.down ?? 0}
|
||||||
/>
|
/>
|
||||||
<StatusBox
|
<StatusBox
|
||||||
title="paused"
|
title="paused"
|
||||||
value={uptimeMonitorsState?.monitorsSummary?.monitorCounts?.paused ?? 0}
|
value={monitorsSummary?.monitorCounts?.paused ?? 0}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<CurrentMonitoring
|
<CurrentMonitoring
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
monitors={uptimeMonitorsState.monitorsSummary.monitors}
|
monitors={monitorsSummary.monitors}
|
||||||
totalMonitors={totalMonitors}
|
totalMonitors={totalMonitors}
|
||||||
handlePause={handlePause}
|
handlePause={handlePause}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import {
|
|||||||
createMonitorBodyValidation,
|
createMonitorBodyValidation,
|
||||||
getMonitorURLByQueryValidation,
|
getMonitorURLByQueryValidation,
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
getMonitorsAndSummaryByTeamIdParamValidation,
|
getMonitorsSummaryByTeamIdParamValidation,
|
||||||
getMonitorsAndSummaryByTeamIdQueryValidation,
|
getMonitorsSummaryByTeamIdQueryValidation,
|
||||||
getMonitorsByTeamIdQueryValidation,
|
getMonitorsByTeamIdQueryValidation,
|
||||||
pauseMonitorParamValidation,
|
pauseMonitorParamValidation,
|
||||||
getMonitorStatsByIdParamValidation,
|
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.
|
* @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).
|
* @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 {
|
try {
|
||||||
await getMonitorsAndSummaryByTeamIdParamValidation.validateAsync(req.params);
|
await getMonitorsSummaryByTeamIdParamValidation.validateAsync(req.params);
|
||||||
await getMonitorsAndSummaryByTeamIdQueryValidation.validateAsync(req.query);
|
await getMonitorsSummaryByTeamIdQueryValidation.validateAsync(req.query);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleValidationError(error, SERVICE_NAME));
|
next(handleValidationError(error, SERVICE_NAME));
|
||||||
return;
|
return;
|
||||||
@@ -229,7 +229,7 @@ class MonitorController {
|
|||||||
try {
|
try {
|
||||||
const { teamId } = req.params;
|
const { teamId } = req.params;
|
||||||
const { type } = req.query;
|
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({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.MONITOR_GET_BY_USER_ID(teamId),
|
msg: successMessages.MONITOR_GET_BY_USER_ID(teamId),
|
||||||
|
|||||||
@@ -513,24 +513,32 @@ const getMonitorById = async (monitorId) => {
|
|||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const getMonitorsAndSummaryByTeamId = async (teamId, type) => {
|
const getMonitorsSummaryByTeamId = async (teamId, type) => {
|
||||||
try {
|
try {
|
||||||
const monitors = await Monitor.find({ teamId, type });
|
const monitorCounts = await Monitor.aggregate([
|
||||||
const monitorCounts = monitors.reduce(
|
{
|
||||||
(acc, monitor) => {
|
$match: {
|
||||||
if (monitor.status === true) {
|
type: { $in: type },
|
||||||
acc.up += 1;
|
},
|
||||||
} else if (monitor.status === false) {
|
|
||||||
acc.down += 1;
|
|
||||||
} else if (monitor.isActive === false) {
|
|
||||||
acc.paused += 1;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
},
|
},
|
||||||
{ up: 0, down: 0, paused: 0 }
|
{
|
||||||
);
|
$facet: {
|
||||||
monitorCounts.total = monitors.length;
|
total: [{ $count: "count" }],
|
||||||
return { monitors, monitorCounts };
|
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) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.method = "getMonitorsAndSummaryByTeamId";
|
error.method = "getMonitorsAndSummaryByTeamId";
|
||||||
@@ -751,7 +759,7 @@ export {
|
|||||||
getMonitorStatsById,
|
getMonitorStatsById,
|
||||||
getMonitorById,
|
getMonitorById,
|
||||||
getUptimeDetailsById,
|
getUptimeDetailsById,
|
||||||
getMonitorsAndSummaryByTeamId,
|
getMonitorsSummaryByTeamId,
|
||||||
getMonitorsByTeamId,
|
getMonitorsByTeamId,
|
||||||
createMonitor,
|
createMonitor,
|
||||||
deleteMonitor,
|
deleteMonitor,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class MonitorRoutes {
|
|||||||
this.router.get("/:monitorId", this.monitorController.getMonitorById);
|
this.router.get("/:monitorId", this.monitorController.getMonitorById);
|
||||||
this.router.get(
|
this.router.get(
|
||||||
"/team/summary/:teamId",
|
"/team/summary/:teamId",
|
||||||
this.monitorController.getMonitorsAndSummaryByTeamId
|
this.monitorController.getMonitorsSummaryByTeamId
|
||||||
);
|
);
|
||||||
this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId);
|
this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId);
|
||||||
|
|
||||||
|
|||||||
+41
-29
@@ -218,38 +218,50 @@ class NewJobQueue {
|
|||||||
concurrency: 5,
|
concurrency: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.on("active", (job) => {
|
// worker.on("active", (job) => {
|
||||||
this.logger.info({
|
// this.logger.info({
|
||||||
message: `Worker started processing job: ${job.id}`,
|
// message: `Worker started processing job: ${job.id}`,
|
||||||
service: SERVICE_NAME,
|
// service: SERVICE_NAME,
|
||||||
method: "createWorker",
|
// method: "createWorker",
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
worker.on("completed", (job) => {
|
// worker.on("completed", (job) => {
|
||||||
this.logger.info({
|
// this.logger.info({
|
||||||
message: `Worker completed job: ${job.id}`,
|
// message: `Worker completed job: ${job.id}`,
|
||||||
service: SERVICE_NAME,
|
// service: SERVICE_NAME,
|
||||||
method: "createWorker",
|
// method: "createWorker",
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
worker.on("failed", (job, err) => {
|
// // Log job progress updates
|
||||||
this.logger.error({
|
// worker.on("progress", (job, progress) => {
|
||||||
message: `Worker failed job: ${job.id}`,
|
// this.logger.info({
|
||||||
service: SERVICE_NAME,
|
// message: `Job progress: ${job.id}`,
|
||||||
method: "createWorker",
|
// service: SERVICE_NAME,
|
||||||
stack: err.stack,
|
// method: "createWorker",
|
||||||
});
|
// details: `Progress: ${progress}%`,
|
||||||
});
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
worker.on("stalled", (jobId) => {
|
// // Log when a job fails
|
||||||
this.logger.warn({
|
// worker.on("failed", (job, err) => {
|
||||||
message: `Worker stalled job: ${jobId}`,
|
// this.logger.error({
|
||||||
service: SERVICE_NAME,
|
// message: `Worker failed job: ${job.id}`,
|
||||||
method: "createWorker",
|
// 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;
|
return worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const SERVICE_NAME = "SettingsService";
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
logLevel: undefined,
|
logLevel: process.env.LOG_LEVEL,
|
||||||
apiBaseUrl: undefined,
|
apiBaseUrl: undefined,
|
||||||
clientHost: process.env.CLIENT_HOST,
|
clientHost: process.env.CLIENT_HOST,
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
|
|||||||
@@ -136,11 +136,11 @@ const getMonitorByIdQueryValidation = joi.object({
|
|||||||
normalize: joi.boolean(),
|
normalize: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getMonitorsAndSummaryByTeamIdParamValidation = joi.object({
|
const getMonitorsSummaryByTeamIdParamValidation = joi.object({
|
||||||
teamId: joi.string().required(),
|
teamId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getMonitorsAndSummaryByTeamIdQueryValidation = joi.object({
|
const getMonitorsSummaryByTeamIdQueryValidation = joi.object({
|
||||||
type: joi
|
type: joi
|
||||||
.alternatives()
|
.alternatives()
|
||||||
.try(
|
.try(
|
||||||
@@ -467,8 +467,8 @@ export {
|
|||||||
createMonitorBodyValidation,
|
createMonitorBodyValidation,
|
||||||
getMonitorByIdParamValidation,
|
getMonitorByIdParamValidation,
|
||||||
getMonitorByIdQueryValidation,
|
getMonitorByIdQueryValidation,
|
||||||
getMonitorsAndSummaryByTeamIdParamValidation,
|
getMonitorsSummaryByTeamIdParamValidation,
|
||||||
getMonitorsAndSummaryByTeamIdQueryValidation,
|
getMonitorsSummaryByTeamIdQueryValidation,
|
||||||
getMonitorsByTeamIdValidation,
|
getMonitorsByTeamIdValidation,
|
||||||
getMonitorsByTeamIdQueryValidation,
|
getMonitorsByTeamIdQueryValidation,
|
||||||
getMonitorStatsByIdParamValidation,
|
getMonitorStatsByIdParamValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user