mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 07:10:53 +00:00
Refactor MonitorResourceUtil; improve error handling and streamline logging statements
This commit is contained in:
parent
ed7a693966
commit
b79dafc9df
@ -131,8 +131,7 @@ export default class MonitorResourceUtil {
|
||||
|
||||
// get last log. We do this because there are many monitoring steps and we need to store those.
|
||||
logger.debug(
|
||||
`${dataToProcess.monitorId.toString()} - monitor type ${
|
||||
monitor.monitorType
|
||||
`${dataToProcess.monitorId.toString()} - monitor type ${monitor.monitorType
|
||||
}`,
|
||||
);
|
||||
|
||||
@ -237,11 +236,18 @@ export default class MonitorResourceUtil {
|
||||
`${dataToProcess.monitorId.toString()} - Saving monitor metrics`,
|
||||
);
|
||||
|
||||
await this.saveMonitorMetrics({
|
||||
monitorId: monitor.id!,
|
||||
projectId: monitor.projectId!,
|
||||
dataToProcess: dataToProcess,
|
||||
});
|
||||
try {
|
||||
|
||||
await this.saveMonitorMetrics({
|
||||
monitorId: monitor.id!,
|
||||
projectId: monitor.projectId!,
|
||||
dataToProcess: dataToProcess,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
logger.error("Unable to save metrics");
|
||||
logger.error(err);
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`${dataToProcess.monitorId.toString()} - Monitor metrics saved`,
|
||||
@ -291,7 +297,7 @@ export default class MonitorResourceUtil {
|
||||
if (incidentTemplate.autoResolveIncident) {
|
||||
if (
|
||||
!autoResolveCriteriaInstanceIdIncidentIdsDictionary[
|
||||
criteriaInstance.data.id.toString()
|
||||
criteriaInstance.data.id.toString()
|
||||
]
|
||||
) {
|
||||
autoResolveCriteriaInstanceIdIncidentIdsDictionary[
|
||||
@ -361,13 +367,11 @@ export default class MonitorResourceUtil {
|
||||
|
||||
if (response.criteriaMetId && response.rootCause) {
|
||||
logger.debug(
|
||||
`${dataToProcess.monitorId.toString()} - Criteria met: ${
|
||||
response.criteriaMetId
|
||||
`${dataToProcess.monitorId.toString()} - Criteria met: ${response.criteriaMetId
|
||||
}`,
|
||||
);
|
||||
logger.debug(
|
||||
`${dataToProcess.monitorId.toString()} - Root cause: ${
|
||||
response.rootCause
|
||||
`${dataToProcess.monitorId.toString()} - Root cause: ${response.rootCause
|
||||
}`,
|
||||
);
|
||||
|
||||
@ -407,7 +411,7 @@ export default class MonitorResourceUtil {
|
||||
!response.criteriaMetId &&
|
||||
monitorSteps.data.defaultMonitorStatusId &&
|
||||
monitor.currentMonitorStatusId?.toString() !==
|
||||
monitorSteps.data.defaultMonitorStatusId.toString()
|
||||
monitorSteps.data.defaultMonitorStatusId.toString()
|
||||
) {
|
||||
logger.debug(
|
||||
`${dataToProcess.monitorId.toString()} - No criteria met. Change to default status.`,
|
||||
@ -444,7 +448,7 @@ export default class MonitorResourceUtil {
|
||||
lastMonitorStatusTimeline &&
|
||||
lastMonitorStatusTimeline.monitorStatusId &&
|
||||
lastMonitorStatusTimeline.monitorStatusId.toString() ===
|
||||
monitorSteps.data.defaultMonitorStatusId.toString()
|
||||
monitorSteps.data.defaultMonitorStatusId.toString()
|
||||
) {
|
||||
// status is same as last status. do not create new status timeline.
|
||||
// do nothing! status is same as last status.
|
||||
@ -755,7 +759,7 @@ export default class MonitorResourceUtil {
|
||||
input.criteriaInstance.data?.changeMonitorStatus &&
|
||||
input.criteriaInstance.data?.monitorStatusId &&
|
||||
input.criteriaInstance.data?.monitorStatusId.toString() !==
|
||||
input.monitor.currentMonitorStatusId?.toString()
|
||||
input.monitor.currentMonitorStatusId?.toString()
|
||||
) {
|
||||
logger.debug(
|
||||
`${input.monitor.id?.toString()} - Change monitor status to ${input.criteriaInstance.data?.monitorStatusId.toString()}`,
|
||||
@ -792,7 +796,7 @@ export default class MonitorResourceUtil {
|
||||
lastMonitorStatusTimeline &&
|
||||
lastMonitorStatusTimeline.monitorStatusId &&
|
||||
lastMonitorStatusTimeline.monitorStatusId.toString() ===
|
||||
monitorStatusId.toString()
|
||||
monitorStatusId.toString()
|
||||
) {
|
||||
// status is same as last status. do not create new status timeline.
|
||||
return;
|
||||
@ -840,9 +844,9 @@ export default class MonitorResourceUtil {
|
||||
(incident: Incident) => {
|
||||
return (
|
||||
incident.createdCriteriaId ===
|
||||
input.criteriaInstance.data?.id.toString() &&
|
||||
input.criteriaInstance.data?.id.toString() &&
|
||||
incident.createdIncidentTemplateId ===
|
||||
criteriaIncident.id.toString()
|
||||
criteriaIncident.id.toString()
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -951,9 +955,9 @@ export default class MonitorResourceUtil {
|
||||
openIncident: Incident;
|
||||
rootCause: string;
|
||||
dataToProcess:
|
||||
| ProbeMonitorResponse
|
||||
| IncomingMonitorRequest
|
||||
| DataToProcess;
|
||||
| ProbeMonitorResponse
|
||||
| IncomingMonitorRequest
|
||||
| DataToProcess;
|
||||
}): Promise<void> {
|
||||
const resolvedStateId: ObjectID =
|
||||
await IncidentStateTimelineService.getResolvedStateIdForProject(
|
||||
@ -1013,7 +1017,7 @@ export default class MonitorResourceUtil {
|
||||
|
||||
if (
|
||||
input.autoResolveCriteriaInstanceIdIncidentIdsDictionary[
|
||||
input.openIncident.createdCriteriaId?.toString()
|
||||
input.openIncident.createdCriteriaId?.toString()
|
||||
]
|
||||
) {
|
||||
if (
|
||||
|
Loading…
Reference in New Issue
Block a user