refactor: Add logging statements for IncomingRequestMonitor

This commit adds logging statements to the IncomingRequestMonitor module to improve debugging and monitoring. The added log messages provide information about the number of incoming request monitors found and whether a monitor should process a request. This change enhances the visibility and understanding of the monitoring process.
This commit is contained in:
Simon Larsen 2024-06-24 17:31:42 +01:00
parent ea5474527c
commit 127cc6b9b1
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
4 changed files with 64 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin
import MonitorType from "Common/Types/Monitor/MonitorType";
import { EVERY_MINUTE } from "Common/Utils/CronTime";
import MonitorService from "CommonServer/Services/MonitorService";
import logger from "CommonServer/Utils/Logger";
import ProbeMonitorResponseService from "CommonServer/Utils/Probe/ProbeMonitorResponse";
import Monitor from "Model/Models/Monitor";
@ -12,6 +13,8 @@ RunCron(
"IncomingRequestMonitor:CheckHeartbeat",
{ schedule: EVERY_MINUTE, runOnStartup: false },
async () => {
logger.debug("Checking IncomingRequestMonitor:CheckHeartbeat");
const incomingRequestMonitors: Array<Monitor> = await MonitorService.findBy(
{
query: {
@ -31,13 +34,24 @@ RunCron(
},
);
logger.debug(
`Found ${incomingRequestMonitors.length} incoming request monitors`,
);
logger.debug(incomingRequestMonitors);
for (const monitor of incomingRequestMonitors) {
if (!monitor.monitorSteps) {
logger.debug("Monitor has no steps. Skipping...");
continue;
}
const processRequest: boolean = shouldProcessRequest(monitor);
logger.debug(
`Monitor: ${monitor.id} should process request: ${processRequest}`,
);
if (!processRequest) {
continue;
}

View File

@ -20,6 +20,19 @@ export default class IncomingRequestCriteria {
}): Promise<string | null> {
// Server Monitoring Checks
logger.debug(
"Checking IncomingRequestCriteria for Monitor: " +
input.dataToProcess.monitorId.toString(),
);
logger.debug(
"Data to process: " + JSON.stringify(input.dataToProcess, null, 2),
);
logger.debug(
"Criteria Filter: " + JSON.stringify(input.criteriaFilter, null, 2),
);
let value: number | string | undefined = input.criteriaFilter.value;
let overTimeValue: Array<number | boolean> | number | boolean | undefined =
@ -58,15 +71,24 @@ export default class IncomingRequestCriteria {
// All incoming request related checks
if (input.criteriaFilter.checkOn === CheckOn.IncomingRequest) {
logger.debug(
"Checking IncomingRequest for Monitor: " +
input.dataToProcess.monitorId.toString(),
);
const lastCheckTime: Date = (
input.dataToProcess as IncomingMonitorRequest
).incomingRequestReceivedAt;
logger.debug("Last Check Time: " + lastCheckTime);
const differenceInMinutes: number = OneUptimeDate.getDifferenceInMinutes(
lastCheckTime,
OneUptimeDate.getCurrentDate(),
);
logger.debug("Difference in minutes: " + differenceInMinutes);
if (!value) {
return null;
}
@ -85,14 +107,32 @@ export default class IncomingRequestCriteria {
}
if (input.criteriaFilter.filterType === FilterType.RecievedInMinutes) {
logger.debug(
"Checking RecievedInMinutes for Monitor: " +
input.dataToProcess.monitorId.toString(),
);
if (value && differenceInMinutes <= (value as number)) {
logger.debug(
"RecievedInMinutes for Monitor: " +
input.dataToProcess.monitorId.toString() +
" is true",
);
return `Incoming request / heartbeat received in ${value} minutes.`;
}
return null;
}
if (input.criteriaFilter.filterType === FilterType.NotRecievedInMinutes) {
logger.debug(
"Checking NotRecievedInMinutes for Monitor: " +
input.dataToProcess.monitorId.toString(),
);
if (value && differenceInMinutes > (value as number)) {
logger.debug(
"NotRecievedInMinutes for Monitor: " +
input.dataToProcess.monitorId.toString() +
" is true",
);
return `Incoming request / heartbeat not received in ${value} minutes.`;
}
return null;

View File

@ -175,6 +175,10 @@ export default class ProbeMonitorResponseService {
monitor.monitorType === MonitorType.IncomingRequest &&
(dataToProcess as IncomingMonitorRequest).incomingRequestReceivedAt
) {
logger.debug(
`${dataToProcess.monitorId.toString()} - Incoming request received at ${(dataToProcess as IncomingMonitorRequest).incomingRequestReceivedAt}`,
);
await MonitorService.updateOneById({
id: monitor.id!,
data: {
@ -186,6 +190,8 @@ export default class ProbeMonitorResponseService {
isRoot: true,
},
});
logger.debug(`${dataToProcess.monitorId.toString()} - Monitor Updated`);
}
if (
@ -1132,6 +1138,9 @@ export default class ProbeMonitorResponseService {
}
if (input.monitor.monitorType === MonitorType.IncomingRequest) {
logger.debug(
`${input.monitor.id?.toString()} - Incoming Request Monitor. Checking criteria filter.`,
);
//check incoming request
const incomingRequestResult: string | null =
await IncomingRequestCriteria.isMonitorInstanceCriteriaFilterMet({

View File

@ -39,7 +39,7 @@ const IncomingRequestMonitorView: FunctionComponent<ComponentProps> = (
<div className="flex space-x-3 justify-between">
<InfoCard
className="w-1/2 shadow-none border-2 border-gray-100"
title="Request Received At"
title="Last Request Received At"
value={
props.incomingMonitorRequest?.incomingRequestReceivedAt
? OneUptimeDate.getDateAsLocalFormattedString(