wire up services/repositories
This commit is contained in:
1 parent
700baf2061
commit
6587ddf389
14 files changed
+206
-7
No files matched your search
@@ -91,3 +91,5 @@ class MongoDockerLogsRepository implements IDockerLogsRepository {
|
||||
deleteByMonitorIdsNotIn = async (monitorIds: string[]) =>
|
||||
(await DockerLogModel.deleteMany({ "metadata.monitorId": { $nin: monitorIds.map((id) => new mongoose.Types.ObjectId(id)) } })).deletedCount ?? 0;
|
||||
}
|
||||
|
||||
export default MongoDockerLogsRepository;
|
||||
@@ -13,7 +13,7 @@ export interface IDockerLogsService {
|
||||
createDockerLogs(logs: DockerLog[]): Promise<number>;
|
||||
}
|
||||
|
||||
export class DockerLogsSerivce implements IDockerLogsService {
|
||||
export class DockerLogsService implements IDockerLogsService {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
|
||||
private logger: ILogger;
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
GroupedGeoCheckResult,
|
||||
DockerDetailsResult,
|
||||
DockerContainerDetailsResult,
|
||||
DockerContainerLogsResult,
|
||||
} from "@/domain/monitors/monitor.type.js";
|
||||
import { supportsGeoCheck, supportsUptimeDetails } from "@/domain/monitors/monitor.type.js";
|
||||
import type {
|
||||
@@ -31,6 +32,7 @@ import type { ImportedMonitor } from "@/api/validation/monitorValidation.js";
|
||||
import { ILogger } from "@/utils/logger.js";
|
||||
import { IJobScheduler } from "@/worker/worker.interface.js";
|
||||
import { DateRange } from "@/types/query.js";
|
||||
import { IDockerLogsRepository } from "@/domain/docker/docker-log.repository.interface.js";
|
||||
|
||||
const SERVICE_NAME = "MonitorService";
|
||||
|
||||
@@ -73,6 +75,13 @@ export interface IMonitorService {
|
||||
containerName: string;
|
||||
dateRange: DateRange;
|
||||
}): Promise<DockerContainerDetailsResult>;
|
||||
getDockerContainerLogs(args: {
|
||||
teamId: string;
|
||||
monitorId: string;
|
||||
containerName: string;
|
||||
before?: Date;
|
||||
limit: number;
|
||||
}): Promise<DockerContainerLogsResult>;
|
||||
getGeoChecksByMonitorId(args: {
|
||||
teamId: string;
|
||||
monitorId: string;
|
||||
@@ -130,6 +139,7 @@ export class MonitorService implements IMonitorService {
|
||||
private monitorsRepository: IMonitorsRepository;
|
||||
private checksRepository: IChecksRepository;
|
||||
private geoChecksRepository: IGeoChecksRepository;
|
||||
private dockerLogsRepository: IDockerLogsRepository;
|
||||
private monitorStatsRepository: IMonitorStatsRepository;
|
||||
private statusPagesRepository: IStatusPagesRepository;
|
||||
private incidentsRepository: IIncidentsRepository;
|
||||
@@ -141,6 +151,7 @@ export class MonitorService implements IMonitorService {
|
||||
monitorsRepository,
|
||||
checksRepository,
|
||||
geoChecksRepository,
|
||||
dockerLogsRepository,
|
||||
monitorStatsRepository,
|
||||
statusPagesRepository,
|
||||
incidentsRepository,
|
||||
@@ -151,6 +162,7 @@ export class MonitorService implements IMonitorService {
|
||||
monitorsRepository: IMonitorsRepository;
|
||||
checksRepository: IChecksRepository;
|
||||
geoChecksRepository: IGeoChecksRepository;
|
||||
dockerLogsRepository: IDockerLogsRepository;
|
||||
monitorStatsRepository: IMonitorStatsRepository;
|
||||
statusPagesRepository: IStatusPagesRepository;
|
||||
incidentsRepository: IIncidentsRepository;
|
||||
@@ -161,6 +173,7 @@ export class MonitorService implements IMonitorService {
|
||||
this.monitorsRepository = monitorsRepository;
|
||||
this.checksRepository = checksRepository;
|
||||
this.geoChecksRepository = geoChecksRepository;
|
||||
this.dockerLogsRepository = dockerLogsRepository;
|
||||
this.monitorStatsRepository = monitorStatsRepository;
|
||||
this.statusPagesRepository = statusPagesRepository;
|
||||
this.incidentsRepository = incidentsRepository;
|
||||
@@ -385,6 +398,38 @@ export class MonitorService implements IMonitorService {
|
||||
};
|
||||
};
|
||||
|
||||
getDockerContainerLogs = async ({
|
||||
teamId,
|
||||
monitorId,
|
||||
containerName,
|
||||
before,
|
||||
limit,
|
||||
}: {
|
||||
teamId: string;
|
||||
monitorId: string;
|
||||
containerName: string;
|
||||
before?: Date;
|
||||
limit: number;
|
||||
}): Promise<DockerContainerLogsResult> => {
|
||||
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
||||
if (!monitor) {
|
||||
throw new AppError({
|
||||
message: `Monitor with ID ${monitorId} not found`,
|
||||
status: 404,
|
||||
});
|
||||
}
|
||||
|
||||
if (monitor.type !== "docker") {
|
||||
throw new AppError({
|
||||
message: `${monitor.type} monitors are not supported for docker container logs`,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const logs = await this.dockerLogsRepository.findByContainerName({ monitorId, containerName, before, limit });
|
||||
return { logs, nextCursor: logs.length === limit ? (logs[logs.length - 1]?.checkedAt ?? null) : null };
|
||||
};
|
||||
|
||||
getGeoChecksByMonitorId = async ({
|
||||
teamId,
|
||||
monitorId,
|
||||
@@ -593,6 +638,14 @@ export class MonitorService implements IMonitorService {
|
||||
});
|
||||
});
|
||||
|
||||
await this.dockerLogsRepository.deleteByMonitorId(monitor.id).catch((err: unknown) => {
|
||||
this.logger.warn({
|
||||
message: `Error deleting docker logs for monitor ${monitor.id} with name ${monitor.name}`,
|
||||
service: SERVICE_NAME,
|
||||
stack: err instanceof Error ? err.stack : undefined,
|
||||
});
|
||||
});
|
||||
|
||||
await this.monitorStatsRepository.deleteByMonitorId(monitor.id).catch((err: unknown) => {
|
||||
this.logger.warn({
|
||||
message: `Error deleting monitor stats for monitor ${monitor.id} with name ${monitor.name}`,
|
||||
|
||||
@@ -5,6 +5,7 @@ export type { GeoContinent } from "@/domain/geo-checks/geo-check.type.js";
|
||||
import http from "node:http";
|
||||
import { HardwareStats } from "@/domain/checks/check.type.js";
|
||||
import { MonitorStats } from "@/domain/monitor-stats/monitor-stats.type.js";
|
||||
import { DockerLogPage } from "@/domain/docker/docker-log.type.js";
|
||||
|
||||
export const HttpStatusCodes = [
|
||||
...Object.keys(http.STATUS_CODES).map(Number),
|
||||
@@ -189,3 +190,5 @@ export interface Game {
|
||||
export type GamesMap = Record<string, Game>;
|
||||
|
||||
export type MonitorScheduleFields = Pick<Monitor, "id" | "type" | "isActive" | "interval" | "geoCheckEnabled" | "geoCheckInterval">;
|
||||
|
||||
export type DockerContainerLogsResult = DockerLogPage;
|
||||
Reference in new issue
Block a user