Add debug logging for worker initialization and heartbeat checks

This commit is contained in:
Simon Larsen 2024-09-20 11:07:35 +01:00
parent af177d0569
commit 21ea8d0aa2
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
3 changed files with 74 additions and 45 deletions

View File

@ -14,11 +14,15 @@ const APP_NAME: string = "worker";
const init: PromiseVoidFunction = async (): Promise<void> => {
try {
logger.debug("Initializing Worker");
// Initialize telemetry
Telemetry.init({
serviceName: APP_NAME,
});
logger.debug("Telemetry initialized");
const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
// Check the status of infrastructure components
return await InfrastructureStatus.checkStatus({
@ -37,27 +41,43 @@ const init: PromiseVoidFunction = async (): Promise<void> => {
},
});
logger.debug("App initialized");
// Connect to Postgres database
await PostgresAppInstance.connect();
logger.debug("Postgres connected");
// Connect to Redis
await Redis.connect();
logger.debug("Redis connected");
// Connect to Clickhouse database
await ClickhouseAppInstance.connect(
ClickhouseAppInstance.getDatasourceOptions(),
);
logger.debug("Clickhouse connected");
// Initialize real-time functionalities
await Realtime.init();
logger.debug("Realtime initialized");
// Initialize home routes at the end since it has a catch-all route
await WorkerRoutes.init();
logger.debug("Routes initialized");
// Add default routes to the app
await App.addDefaultRoutes();
logger.debug("Default routes added");
logger.info("Worker Initialized Successfully");
} catch (err) {
logger.error("App Init Failed:");
logger.error("Worker Init Failed:");
logger.error(err);
throw err;
}

View File

@ -101,6 +101,10 @@ RunCron(
continue;
}
logger.debug(
`Updating incoming request monitor heartbeat checked at: ${monitor.id?.toString()}`,
);
await MonitorService.updateOneById({
id: monitor.id!,
data: {

View File

@ -15,54 +15,59 @@ RunCron(
"ServerMonitor:CheckOnlineStatus",
{ schedule: EVERY_MINUTE, runOnStartup: false },
async () => {
const twoMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(2);
try {
const twoMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(2);
const serverMonitors: Array<Monitor> = await MonitorService.findBy({
query: {
monitorType: MonitorType.Server,
serverMonitorRequestReceivedAt:
QueryHelper.lessThanEqualToOrNull(twoMinsAgo),
},
props: {
isRoot: true,
},
select: {
_id: true,
monitorSteps: true,
serverMonitorRequestReceivedAt: true,
createdAt: true,
},
limit: LIMIT_MAX,
skip: 0,
});
const serverMonitors: Array<Monitor> = await MonitorService.findBy({
query: {
monitorType: MonitorType.Server,
serverMonitorRequestReceivedAt:
QueryHelper.lessThanEqualToOrNull(twoMinsAgo),
},
props: {
isRoot: true,
},
select: {
_id: true,
monitorSteps: true,
serverMonitorRequestReceivedAt: true,
createdAt: true,
},
limit: LIMIT_MAX,
skip: 0,
});
for (const monitor of serverMonitors) {
try {
if (!monitor.monitorSteps) {
continue;
for (const monitor of serverMonitors) {
try {
if (!monitor.monitorSteps) {
continue;
}
const processRequest: boolean = shouldProcessRequest(monitor);
if (!processRequest) {
continue;
}
const serverMonitorResponse: ServerMonitorResponse = {
monitorId: monitor.id!,
onlyCheckRequestReceivedAt: true,
requestReceivedAt:
monitor.serverMonitorRequestReceivedAt || monitor.createdAt!,
hostname: "",
};
await MonitorResourceUtil.monitorResource(serverMonitorResponse);
} catch (error) {
logger.error(
`Error in ServerMonitor:CheckOnlineStatus for monitorId: ${monitor.id}`,
);
logger.error(error);
}
const processRequest: boolean = shouldProcessRequest(monitor);
if (!processRequest) {
continue;
}
const serverMonitorResponse: ServerMonitorResponse = {
monitorId: monitor.id!,
onlyCheckRequestReceivedAt: true,
requestReceivedAt:
monitor.serverMonitorRequestReceivedAt || monitor.createdAt!,
hostname: "",
};
await MonitorResourceUtil.monitorResource(serverMonitorResponse);
} catch (error) {
logger.error(
`Error in ServerMonitor:CheckOnlineStatus for monitorId: ${monitor.id}`,
);
logger.error(error);
}
} catch (error) {
logger.error("Error in ServerMonitor:CheckOnlineStatus");
logger.error(error);
}
},
);