handle docker checks
This commit is contained in:
1 parent
1a1dc7d807
commit
78d3b23e93
3 files changed
+70
-4
No files matched your search
@@ -24,6 +24,7 @@ import { getHardwareUpChecks, getHardwareStats, getHardwareTotalChecks } from "@
|
|||||||
import { CheckFilter, DateRange } from "@/types/query.js";
|
import { CheckFilter, DateRange } from "@/types/query.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { NETWORK_ERROR } from "@/types/network.js";
|
import { NETWORK_ERROR } from "@/types/network.js";
|
||||||
|
import { getDockerLatestCheck, getDockerStats, getDockerTotalChecks, getDockerUpChecks } from "@/domain/checks/check.docker.aggregation.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "ChecksRepository";
|
const SERVICE_NAME = "ChecksRepository";
|
||||||
|
|
||||||
@@ -304,6 +305,9 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
if (options?.type === "pagespeed") {
|
if (options?.type === "pagespeed") {
|
||||||
return this.findPageSpeedDateRangeChecks(monitorObjectId, start, end, dateString);
|
return this.findPageSpeedDateRangeChecks(monitorObjectId, start, end, dateString);
|
||||||
}
|
}
|
||||||
|
if (options?.type === "docker") {
|
||||||
|
return this.findDockerDateRangeChecks(monitorObjectId, start, end, dateString);
|
||||||
|
}
|
||||||
return this.findUptimeDateRangeChecks(options?.type ?? "http", monitorObjectId, start, end, dateString);
|
return this.findUptimeDateRangeChecks(options?.type ?? "http", monitorObjectId, start, end, dateString);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -414,7 +418,7 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
return totalDeleted;
|
return totalDeleted;
|
||||||
};
|
};
|
||||||
private findUptimeDateRangeChecks = async (
|
private findUptimeDateRangeChecks = async (
|
||||||
monitorType: Exclude<MonitorType, "hardware" | "pagespeed">,
|
monitorType: Exclude<MonitorType, "hardware" | "pagespeed" | "docker">,
|
||||||
monitorObjectId: mongoose.Types.ObjectId,
|
monitorObjectId: mongoose.Types.ObjectId,
|
||||||
startDate: Date,
|
startDate: Date,
|
||||||
endDate: Date,
|
endDate: Date,
|
||||||
@@ -630,6 +634,30 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
groupedChecks: result?.groupedChecks ?? [],
|
groupedChecks: result?.groupedChecks ?? [],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private findDockerDateRangeChecks = async (monitorObjectId: mongoose.Types.ObjectId, startDate: Date, endDate: Date, dateString: string) => {
|
||||||
|
const monitorId = monitorObjectId.toHexString();
|
||||||
|
const dates = { start: startDate, end: endDate };
|
||||||
|
const [totalChecks, upChecks, aggregate, latestDoc] = await Promise.all([
|
||||||
|
getDockerTotalChecks(monitorId, dates),
|
||||||
|
getDockerUpChecks(monitorId, dates),
|
||||||
|
getDockerStats(monitorId, dates, dateString),
|
||||||
|
getDockerLatestCheck(monitorId),
|
||||||
|
]);
|
||||||
|
return {
|
||||||
|
monitorType: "docker" as const,
|
||||||
|
aggregateData: { totalChecks: totalChecks ?? 0 },
|
||||||
|
upChecks,
|
||||||
|
aggregate,
|
||||||
|
latest: latestDoc
|
||||||
|
? {
|
||||||
|
containers: latestDoc.containers ?? [],
|
||||||
|
summary: latestDoc.containerSummary,
|
||||||
|
checkedAt: toDateString(latestDoc.createdAt),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MongoChecksRepository;
|
export default MongoChecksRepository;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { MonitorType } from "@/domain/monitors/monitor.type.js";
|
import type { MonitorType } from "@/domain/monitors/monitor.type.js";
|
||||||
import { DockerContainerInfo, DockerContainerSummary } from "@/types/network.js";
|
import { DockerContainerInfo, DockerContainerSummary } from "@/types/network.js";
|
||||||
import type { Response } from "got";
|
import type { Response } from "got";
|
||||||
import { number } from "zod";
|
|
||||||
|
|
||||||
export const CHECK_TTL_SENTINEL = 366;
|
export const CHECK_TTL_SENTINEL = 366;
|
||||||
|
|
||||||
@@ -151,11 +150,10 @@ export interface PageSpeedGroupedCheck {
|
|||||||
accessibility: number;
|
accessibility: number;
|
||||||
bestPractices: number;
|
bestPractices: number;
|
||||||
seo: number;
|
seo: number;
|
||||||
totalChecks: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UptimeChecksResult {
|
export interface UptimeChecksResult {
|
||||||
monitorType: Exclude<MonitorType, "hardware" | "pagespeed">;
|
monitorType: Exclude<MonitorType, "hardware" | "pagespeed" | "docker">;
|
||||||
groupedChecks: GroupedUptimeCheck[];
|
groupedChecks: GroupedUptimeCheck[];
|
||||||
groupedUpChecks: GroupedCheck[];
|
groupedUpChecks: GroupedCheck[];
|
||||||
groupedDownChecks: GroupedCheck[];
|
groupedDownChecks: GroupedCheck[];
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import type {
|
|||||||
PageSpeedDetailsResult,
|
PageSpeedDetailsResult,
|
||||||
GamesMap,
|
GamesMap,
|
||||||
GroupedGeoCheckResult,
|
GroupedGeoCheckResult,
|
||||||
|
DockerDetailsResult,
|
||||||
} from "@/domain/monitors/monitor.type.js";
|
} from "@/domain/monitors/monitor.type.js";
|
||||||
import { supportsGeoCheck, supportsUptimeDetails } from "@/domain/monitors/monitor.type.js";
|
import { supportsGeoCheck, supportsUptimeDetails } from "@/domain/monitors/monitor.type.js";
|
||||||
import type { UptimeChecksResult, HardwareChecksResult, PageSpeedChecksResult, DockerChecksResult } from "@/domain/checks/check.type.js";
|
import type { UptimeChecksResult, HardwareChecksResult, PageSpeedChecksResult, DockerChecksResult } from "@/domain/checks/check.type.js";
|
||||||
@@ -40,6 +41,7 @@ export interface IMonitorService {
|
|||||||
getUptimeDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<UptimeDetailsResult>;
|
getUptimeDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<UptimeDetailsResult>;
|
||||||
getHardwareDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<HardwareDetailsResult>;
|
getHardwareDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<HardwareDetailsResult>;
|
||||||
getPageSpeedDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<PageSpeedDetailsResult>;
|
getPageSpeedDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<PageSpeedDetailsResult>;
|
||||||
|
getDockerDetailsById(args: { teamId: string; monitorId: string; dateRange: DateRange }): Promise<PageSpeedDetailsResult>;
|
||||||
getGeoChecksByMonitorId(args: {
|
getGeoChecksByMonitorId(args: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
monitorId: string;
|
monitorId: string;
|
||||||
@@ -282,6 +284,44 @@ export class MonitorService implements IMonitorService {
|
|||||||
monitorStats,
|
monitorStats,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
getDockerDetailsById = async ({
|
||||||
|
teamId,
|
||||||
|
monitorId,
|
||||||
|
dateRange,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
monitorId: string;
|
||||||
|
dateRange: DateRange;
|
||||||
|
}): Promise<DockerDetailsResult> => {
|
||||||
|
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 details`, status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const checksData = await this.checksRepository.findByDateRangeAndMonitorId(monitor.id, dateRange, {
|
||||||
|
type: monitor.type,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checksData.monitorType !== "docker") {
|
||||||
|
throw new AppError({ message: "Unable to load docker stats for this monitor", status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const monitorStats = await this.monitorStatsRepository.findByMonitorId(monitor.id);
|
||||||
|
|
||||||
|
return {
|
||||||
|
monitor,
|
||||||
|
stats: {
|
||||||
|
aggregateData: checksData.aggregateData,
|
||||||
|
upChecks: checksData.upChecks,
|
||||||
|
aggregate: checksData.aggregate,
|
||||||
|
latest: checksData.latest,
|
||||||
|
},
|
||||||
|
monitorStats,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
getGeoChecksByMonitorId = async ({
|
getGeoChecksByMonitorId = async ({
|
||||||
teamId,
|
teamId,
|
||||||
|
|||||||
Reference in new issue
Block a user