show all checks

This commit is contained in:
Alex Holliday committed 2026-02-25 18:43:12 +00:00
1 parent 88e28b9819
commit 477c30286d
9 files changed
+123 -39

No files matched your search

@@ -28,8 +28,6 @@ export const HeaderGeoTabs = ({
onLocationChange(newValue); onLocationChange(newValue);
}; };
console.log(locations);
return ( return (
<Stack <Stack
spacing={{ xs: theme.spacing(8), md: 0 }} spacing={{ xs: theme.spacing(8), md: 0 }}
@@ -8,14 +8,48 @@ import type { RootState } from "@/Types/state";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import prettyMilliseconds from "pretty-ms"; import prettyMilliseconds from "pretty-ms";
// Flatten geo check results - each location becomes a separate row
interface FlattenedGeoCheckResult {
id: string;
monitorId: string;
createdAt: string;
location: {
continent: string;
country: string;
city: string;
};
status: boolean;
statusCode: number;
timings: {
total: number;
};
}
const flattenGeoChecks = (geoChecks: GeoCheck[]): FlattenedGeoCheckResult[] => {
const flattened: FlattenedGeoCheckResult[] = [];
for (const check of geoChecks) {
for (const result of check.results) {
flattened.push({
id: `${check.id}-${result.location.continent}-${result.location.city}`,
monitorId: check.metadata.monitorId,
createdAt: check.createdAt,
location: result.location,
status: result.status,
statusCode: result.statusCode,
timings: result.timings,
});
}
}
return flattened;
};
const getHeaders = (t: Function, uiTimezone: string) => { const getHeaders = (t: Function, uiTimezone: string) => {
const headers: Header<GeoCheck>[] = [ const headers: Header<FlattenedGeoCheckResult>[] = [
{ {
id: "status", id: "status",
content: t("common.table.headers.status"), content: t("common.table.headers.status"),
render: (row) => { render: (row) => {
const firstResult = row.results[0]; const status = row.status ? "up" : "down";
const status = firstResult?.status ? "up" : "down";
return <StatusLabel status={status} />; return <StatusLabel status={status} />;
}, },
}, },
@@ -30,17 +64,14 @@ const getHeaders = (t: Function, uiTimezone: string) => {
id: "statusCode", id: "statusCode",
content: t("pages.checks.table.headers.statusCode"), content: t("pages.checks.table.headers.statusCode"),
render: (row) => { render: (row) => {
const firstResult = row.results[0]; return row.statusCode || "N/A";
return firstResult?.statusCode || "N/A";
}, },
}, },
{ {
id: "location", id: "location",
content: t("pages.checks.table.headers.location"), content: t("pages.checks.table.headers.location"),
render: (row) => { render: (row) => {
const firstResult = row.results[0]; const { continent, country, city } = row.location;
if (!firstResult) return "N/A";
const { continent, country, city } = firstResult.location;
return `${continent} - ${country}, ${city}`; return `${continent} - ${country}, ${city}`;
}, },
}, },
@@ -48,9 +79,8 @@ const getHeaders = (t: Function, uiTimezone: string) => {
id: "responseTime", id: "responseTime",
content: t("common.table.headers.responseTime"), content: t("common.table.headers.responseTime"),
render: (row) => { render: (row) => {
const firstResult = row.results[0]; if (!row.timings?.total) return "N/A";
if (!firstResult?.timings?.total) return "N/A"; return prettyMilliseconds(row.timings.total, { compact: true });
return prettyMilliseconds(firstResult.timings.total, { compact: true });
}, },
}, },
]; ];
@@ -75,6 +105,7 @@ export const GeoChecksTable = ({
const { t } = useTranslation(); const { t } = useTranslation();
const uiTimezone = useSelector((state: RootState) => state.ui.timezone); const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
const headers = getHeaders(t, uiTimezone); const headers = getHeaders(t, uiTimezone);
const flattenedData = flattenGeoChecks(geoChecks);
const handlePageChange = ( const handlePageChange = (
_e: React.MouseEvent<HTMLButtonElement> | null, _e: React.MouseEvent<HTMLButtonElement> | null,
@@ -95,7 +126,7 @@ export const GeoChecksTable = ({
<Box> <Box>
<Table <Table
headers={headers} headers={headers}
data={geoChecks} data={flattenedData}
/> />
<Pagination <Pagination
component="div" component="div"
@@ -144,9 +144,6 @@ const UptimeDetailsPage = () => {
params.append("dateRange", dateRange); params.append("dateRange", dateRange);
params.append("page", String(geoPage)); params.append("page", String(geoPage));
params.append("rowsPerPage", String(geoRowsPerPage)); params.append("rowsPerPage", String(geoRowsPerPage));
if (selectedLocation) {
params.append("continent", selectedLocation);
}
return `/geo-checks/${monitorId}?${params.toString()}`; return `/geo-checks/${monitorId}?${params.toString()}`;
}, [ }, [
monitorId, monitorId,
@@ -155,7 +152,6 @@ const UptimeDetailsPage = () => {
dateRange, dateRange,
geoPage, geoPage,
geoRowsPerPage, geoRowsPerPage,
selectedLocation,
]); ]);
const { data: geoChecksTableData } = useGet<GeoChecksResponse>( const { data: geoChecksTableData } = useGet<GeoChecksResponse>(
+7 -2
View File
@@ -142,14 +142,19 @@ class MonitorController {
const monitorId = requireString(req?.params?.monitorId, "Monitor ID"); const monitorId = requireString(req?.params?.monitorId, "Monitor ID");
const dateRange = requireString(req?.query?.dateRange, "dateRange"); const dateRange = requireString(req?.query?.dateRange, "dateRange");
const continent = optionalString(req?.query?.continent, "continent") as GeoContinent | undefined; const continentParam = req?.query?.continent;
const continents = continentParam
? Array.isArray(continentParam)
? (continentParam as GeoContinent[])
: [continentParam as GeoContinent]
: undefined;
const teamId = requireTeamId(req?.user?.teamId); const teamId = requireTeamId(req?.user?.teamId);
const data = await this.monitorService.getGeoChecksByMonitorId({ const data = await this.monitorService.getGeoChecksByMonitorId({
teamId, teamId,
monitorId, monitorId,
dateRange, dateRange,
continent, continents,
}); });
return res.status(200).json({ return res.status(200).json({
@@ -14,7 +14,7 @@ export interface IGeoChecksRepository {
dateRange: string, dateRange: string,
page: number, page: number,
rowsPerPage: number, rowsPerPage: number,
continent?: GeoContinent continents?: GeoContinent[]
): Promise<GeoChecksQueryResult>; ): Promise<GeoChecksQueryResult>;
findByMonitorIdAndDateRange(monitorId: string, startDate: Date, endDate: Date): Promise<GeoCheck[]>; findByMonitorIdAndDateRange(monitorId: string, startDate: Date, endDate: Date): Promise<GeoCheck[]>;
findGroupedByMonitorIdAndDateRange( findGroupedByMonitorIdAndDateRange(
@@ -22,7 +22,7 @@ export interface IGeoChecksRepository {
startDate: Date, startDate: Date,
endDate: Date, endDate: Date,
dateFormat: string, dateFormat: string,
continent?: GeoContinent continents?: GeoContinent[]
): Promise<GroupedGeoCheck[]>; ): Promise<GroupedGeoCheck[]>;
deleteByMonitorId(monitorId: string): Promise<number>; deleteByMonitorId(monitorId: string): Promise<number>;
deleteByTeamId(teamId: string): Promise<number>; deleteByTeamId(teamId: string): Promise<number>;
@@ -111,9 +111,16 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
dateRange: string, dateRange: string,
page: number, page: number,
rowsPerPage: number, rowsPerPage: number,
continent?: GeoContinent continents?: GeoContinent[]
): Promise<GeoChecksQueryResult> => { ): Promise<GeoChecksQueryResult> => {
try { try {
this.logger.debug({
message: "findByMonitorId called",
service: SERVICE_NAME,
method: "findByMonitorId",
details: { monitorId, continents, continentsLength: continents?.length },
});
const matchStage: Record<string, any> = { const matchStage: Record<string, any> = {
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId), "metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
...(dateRangeLookup[dateRange] && { ...(dateRangeLookup[dateRange] && {
@@ -130,13 +137,19 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
skip = page * rowsPerPage; skip = page * rowsPerPage;
} }
if (continent) { if (continents && continents.length > 0) {
this.logger.debug({
message: "Filtering by continents",
service: SERVICE_NAME,
method: "findByMonitorId",
details: { continents },
});
const pipeline: any[] = [ const pipeline: any[] = [
{ $match: matchStage }, { $match: matchStage },
{ $unwind: "$results" }, { $unwind: "$results" },
{ {
$match: { $match: {
"results.location.continent": continent, "results.location.continent": { $in: continents },
}, },
}, },
{ {
@@ -162,7 +175,7 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
GeoCheckModel.aggregate([ GeoCheckModel.aggregate([
{ $match: matchStage }, { $match: matchStage },
{ $unwind: "$results" }, { $unwind: "$results" },
{ $match: { "results.location.continent": continent } }, { $match: { "results.location.continent": { $in: continents } } },
{ $group: { _id: "$_id" } }, { $group: { _id: "$_id" } },
{ $count: "count" }, { $count: "count" },
]), ]),
@@ -174,12 +187,44 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
return { geoChecksCount, geoChecks }; return { geoChecksCount, geoChecks };
} else { } else {
const [geoChecksCount, docs] = await Promise.all([ this.logger.debug({
GeoCheckModel.countDocuments(matchStage), message: "No continent filtering - returning all checks",
GeoCheckModel.find(matchStage).sort({ createdAt: convertedSortOrder }).skip(skip).limit(rowsPerPage).lean() as Promise<GeoCheckDocument[]>, service: SERVICE_NAME,
method: "findByMonitorId",
});
// Still need to unwind to show each location as a separate row
const pipeline: any[] = [
{ $match: matchStage },
{ $unwind: "$results" },
{
$group: {
_id: "$_id",
doc: { $first: "$$ROOT" },
results: { $push: "$results" },
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: ["$doc", { results: "$results" }],
},
},
},
{ $sort: { createdAt: convertedSortOrder } },
{ $skip: skip },
{ $limit: rowsPerPage },
];
const [countPipeline, dataResults] = await Promise.all([
GeoCheckModel.aggregate([{ $match: matchStage }, { $unwind: "$results" }, { $group: { _id: "$_id" } }, { $count: "count" }]),
GeoCheckModel.aggregate(pipeline),
]); ]);
return { geoChecksCount, geoChecks: docs.map(this.toEntity) }; const geoChecksCount = countPipeline[0]?.count || 0;
const geoChecks = dataResults.map(this.toEntity);
return { geoChecksCount, geoChecks };
} }
} catch (error: any) { } catch (error: any) {
this.logger.error({ this.logger.error({
@@ -217,7 +262,7 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
startDate: Date, startDate: Date,
endDate: Date, endDate: Date,
dateFormat: string, dateFormat: string,
continent?: string continents?: GeoContinent[]
): Promise<GroupedGeoCheck[]> => { ): Promise<GroupedGeoCheck[]> => {
try { try {
const pipeline: any[] = [ const pipeline: any[] = [
@@ -236,11 +281,11 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
$unwind: "$results", $unwind: "$results",
}, },
// Filter by continent if specified // Filter by continent if specified
...(continent ...(continents && continents.length > 0
? [ ? [
{ {
$match: { $match: {
"results.location.continent": continent, "results.location.continent": { $in: continents },
}, },
}, },
] ]
@@ -177,10 +177,19 @@ class GeoChecksService implements IGeoChecksService {
} }
let { sortOrder, dateRange, page, rowsPerPage, continent } = query; let { sortOrder, dateRange, page, rowsPerPage, continent } = query;
const continents = continent ? (Array.isArray(continent) ? continent : [continent]) : undefined;
this.logger.debug({
message: "getGeoChecksByMonitor query params",
service: SERVICE_NAME,
method: "getGeoChecksByMonitor",
details: { continent, continents, query },
});
const parsedPage = page ? parseInt(page) : page; const parsedPage = page ? parseInt(page) : page;
const parsedRowsPerPage = rowsPerPage ? parseInt(rowsPerPage) : rowsPerPage; const parsedRowsPerPage = rowsPerPage ? parseInt(rowsPerPage) : rowsPerPage;
const result = await this.geoChecksRepository.findByMonitorId(monitorId, sortOrder, dateRange, parsedPage, parsedRowsPerPage, continent); const result = await this.geoChecksRepository.findByMonitorId(monitorId, sortOrder, dateRange, parsedPage, parsedRowsPerPage, continents);
return result; return result;
}; };
@@ -38,7 +38,7 @@ export interface IMonitorService {
getUptimeDetailsById(args: { teamId: string; monitorId: string; dateRange: string; normalize?: boolean }): Promise<UptimeDetailsResult>; getUptimeDetailsById(args: { teamId: string; monitorId: string; dateRange: string; normalize?: boolean }): Promise<UptimeDetailsResult>;
getHardwareDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<HardwareDetailsResult>; getHardwareDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<HardwareDetailsResult>;
getPageSpeedDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<PageSpeedDetailsResult>; getPageSpeedDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<PageSpeedDetailsResult>;
getGeoChecksByMonitorId(args: { teamId: string; monitorId: string; dateRange: string; continent?: GeoContinent }): Promise<any>; getGeoChecksByMonitorId(args: { teamId: string; monitorId: string; dateRange: string; continents?: GeoContinent[] }): Promise<any>;
getMonitorById(args: { teamId: string; monitorId: string }): Promise<Monitor>; getMonitorById(args: { teamId: string; monitorId: string }): Promise<Monitor>;
getMonitorsByTeamId(args: { getMonitorsByTeamId(args: {
teamId: string; teamId: string;
@@ -327,12 +327,12 @@ export class MonitorService implements IMonitorService {
teamId, teamId,
monitorId, monitorId,
dateRange, dateRange,
continent, continents,
}: { }: {
teamId: string; teamId: string;
monitorId: string; monitorId: string;
dateRange: string; dateRange: string;
continent?: GeoContinent; continents?: GeoContinent[];
}): Promise<any> => { }): Promise<any> => {
const monitor = await this.monitorsRepository.findById(monitorId, teamId); const monitor = await this.monitorsRepository.findById(monitorId, teamId);
if (!monitor) { if (!monitor) {
@@ -350,7 +350,7 @@ export class MonitorService implements IMonitorService {
start, start,
end, end,
this.getDateFormat(rangeKey), this.getDateFormat(rangeKey),
continent continents
); );
return { groupedGeoChecks }; return { groupedGeoChecks };
+1 -1
View File
@@ -324,7 +324,7 @@ const getChecksQueryValidation = joi.object({
page: joi.number(), page: joi.number(),
rowsPerPage: joi.number(), rowsPerPage: joi.number(),
status: joi.boolean(), status: joi.boolean(),
continent: joi.string().valid(...GeoContinents), continent: joi.alternatives().try(joi.string().valid(...GeoContinents), joi.array().items(joi.string().valid(...GeoContinents))),
}); });
const getTeamChecksQueryValidation = joi.object({ const getTeamChecksQueryValidation = joi.object({