fix remaining type issues
This commit is contained in:
1 parent
9583332852
commit
ce568424a3
13 files changed
+108
-40
No files matched your search
@@ -17,7 +17,7 @@ import { BaseBox } from "@/components/design-elements";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import { formatDateWithTz, tooltipDateFormatLookup } from "@/utils/TimeUtils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
export const BarDockerCount = ({
|
||||
data,
|
||||
dataKey,
|
||||
@@ -25,7 +25,7 @@ export const BarDockerCount = ({
|
||||
title,
|
||||
emptyText,
|
||||
}: {
|
||||
data: GroupedCheck[];
|
||||
data: AggregateCheck[];
|
||||
dataKey: string;
|
||||
range: string;
|
||||
title: string;
|
||||
@@ -89,7 +89,7 @@ export const BarDockerCount = ({
|
||||
vertical={false}
|
||||
/>
|
||||
<XAxis
|
||||
dataKey={"_id"}
|
||||
dataKey={"bucketDate"}
|
||||
tick={(props) => <XTick {...props} range={range} />}
|
||||
/>
|
||||
<YAxis
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
tooltipDateFormatLookup,
|
||||
} from "@/utils/TimeUtils";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
|
||||
type XTickProps = {
|
||||
@@ -33,7 +33,6 @@ export const XTick = ({ x, y, payload, range }: XTickProps) => {
|
||||
const format = tickDateFormatLookup(range);
|
||||
const theme = useTheme();
|
||||
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
|
||||
console.log(payload);
|
||||
return (
|
||||
<Text
|
||||
x={x}
|
||||
@@ -85,7 +84,7 @@ export const ChartResponseTime = ({
|
||||
checks,
|
||||
range,
|
||||
}: {
|
||||
checks: GroupedCheck[];
|
||||
checks: AggregateCheck[];
|
||||
range: string;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -87,7 +87,7 @@ export const HistogramDockerPercentage = ({
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<XAxis
|
||||
dataKey={"_id"}
|
||||
dataKey={"bucketDate"}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tick={(props) => <XTick {...props} range={range} />}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Fragment, useId } from "react";
|
||||
import { XTick } from "./ChartResponseTime";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
|
||||
const AREA_COLORS = [
|
||||
// Blues
|
||||
@@ -104,7 +104,7 @@ export const HistogramInfrastructure = ({
|
||||
title: string;
|
||||
type: string;
|
||||
idx: number | null;
|
||||
checks: GroupedCheck[];
|
||||
checks: AggregateCheck[];
|
||||
xKey: string;
|
||||
yDomain?: number[];
|
||||
dataKeys: string[];
|
||||
@@ -118,7 +118,7 @@ export const HistogramInfrastructure = ({
|
||||
const theme = useTheme();
|
||||
const uniqueId = useId();
|
||||
|
||||
let avgTemps: { bucketDate: Date; avg_temp: number | null }[] = [];
|
||||
let avgTemps: { bucketDate: string; avg_temp: number | null }[] = [];
|
||||
let tempYDomain: number[] = [];
|
||||
if (type === "temp") {
|
||||
avgTemps = checks.map((check) => {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { HistogramPageSpeedScoresTooltip } from "./HistogramPageSpeedScoresTooltip";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
import type { Palette } from "@mui/material/styles";
|
||||
type PaletteColorKey = Extract<
|
||||
keyof Palette,
|
||||
@@ -52,7 +52,7 @@ export const HistogramPageSpeedScores = ({
|
||||
checks,
|
||||
range,
|
||||
}: {
|
||||
checks: GroupedCheck[];
|
||||
checks: AggregateCheck[];
|
||||
range: string;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "recharts";
|
||||
import { TrendingUp, AlertTriangle } from "lucide-react";
|
||||
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
import type { MonitorStatus } from "@/types/monitor";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -26,8 +26,8 @@ const XLabel = ({
|
||||
p2,
|
||||
range,
|
||||
}: {
|
||||
p1: GroupedCheck;
|
||||
p2: GroupedCheck;
|
||||
p1: AggregateCheck;
|
||||
p2: AggregateCheck;
|
||||
range: string;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
@@ -65,7 +65,7 @@ export const HistogramStatus = ({
|
||||
range,
|
||||
title,
|
||||
}: {
|
||||
checks: GroupedCheck[];
|
||||
checks: AggregateCheck[];
|
||||
status: MonitorStatus;
|
||||
range: string;
|
||||
title: string;
|
||||
@@ -84,7 +84,7 @@ export const HistogramStatus = ({
|
||||
const CustomTooltip = ({ active, payload }: any) => {
|
||||
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
|
||||
if (!active || !payload?.length) return null;
|
||||
const d = payload[0]?.payload as GroupedCheck & {
|
||||
const d = payload[0]?.payload as AggregateCheck & {
|
||||
avgResponseTime?: number;
|
||||
};
|
||||
const avg = d?.avgResponseTime ?? 0;
|
||||
@@ -133,7 +133,7 @@ export const HistogramStatus = ({
|
||||
}
|
||||
|
||||
const totalChecks = normalChecks.reduce((count, check) => {
|
||||
return count + check.count;
|
||||
return count + (check.count ?? 0);
|
||||
}, 0);
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { getGbs, getFrequency } from "./InfraUtils";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
|
||||
const InfraDetailGauge = ({
|
||||
title,
|
||||
@@ -42,7 +42,11 @@ const InfraDetailGauge = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const InfraDetailsGauges = ({ checks }: { checks: GroupedCheck[] }) => {
|
||||
export const InfraDetailsGauges = ({
|
||||
checks,
|
||||
}: {
|
||||
checks: AggregateCheck[];
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||
|
||||
@@ -2,12 +2,12 @@ import Grid from "@mui/material/Grid";
|
||||
import { HistogramInfrastructure } from "@/components/monitors";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
import { useMemo } from "react";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
|
||||
const getChartConfigs = (theme: any, checks: GroupedCheck[], t: any) => {
|
||||
const getChartConfigs = (theme: any, checks: AggregateCheck[], t: any) => {
|
||||
return [
|
||||
{
|
||||
title: t("common.charts.infrastructure.memory.title"),
|
||||
@@ -52,7 +52,7 @@ export const InfraDetailsGraphs = ({
|
||||
checks,
|
||||
range,
|
||||
}: {
|
||||
checks: GroupedCheck[];
|
||||
checks: AggregateCheck[];
|
||||
range: string;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -4,17 +4,18 @@ import Grid from "@mui/material/Grid";
|
||||
import { HistogramInfrastructure } from "@/components/monitors";
|
||||
import { Select } from "@/components/inputs";
|
||||
|
||||
import type { IInfraCheck } from "@/types/check";
|
||||
import type { AggregateCheck } from "@/types/check";
|
||||
import { useMemo, useState, useEffect } from "react";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
|
||||
const getChartConfigs = (
|
||||
theme: any,
|
||||
checks: IInfraCheck[],
|
||||
checks: AggregateCheck[],
|
||||
selectedInterface: string
|
||||
) => {
|
||||
const idx = checks[0]?.net.findIndex((i) => i.name === selectedInterface);
|
||||
const idx =
|
||||
checks?.[0]?.net?.findIndex((i) => i.name === selectedInterface) ?? -1;
|
||||
if (idx === -1) return [];
|
||||
return [
|
||||
{
|
||||
@@ -56,7 +57,7 @@ export const InfraDetailsNetGraphs = ({
|
||||
checks,
|
||||
range,
|
||||
}: {
|
||||
checks: IInfraCheck[];
|
||||
checks: AggregateCheck[];
|
||||
range: string;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
@@ -68,11 +69,15 @@ export const InfraDetailsNetGraphs = ({
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (checks[0]) {
|
||||
if (checks?.[0]?.net && checks[0].net.length > 0) {
|
||||
const firstNonLoopback = checks[0].net.find(
|
||||
(iface) => iface.name !== "lo"
|
||||
);
|
||||
setSelectedInterface(firstNonLoopback?.name || "");
|
||||
setSelectedInterface(
|
||||
firstNonLoopback?.name || checks[0].net[0]?.name || ""
|
||||
);
|
||||
} else {
|
||||
setSelectedInterface("");
|
||||
}
|
||||
}, [checks]);
|
||||
return (
|
||||
@@ -84,7 +89,7 @@ export const InfraDetailsNetGraphs = ({
|
||||
value={selectedInterface}
|
||||
onChange={(e) => setSelectedInterface(e.target.value)}
|
||||
>
|
||||
{checks[0]?.net.map((iface) => {
|
||||
{checks?.[0]?.net?.map((iface) => {
|
||||
return (
|
||||
<MenuItem key={iface.name} value={iface.name}>
|
||||
{iface.name}
|
||||
@@ -108,7 +113,7 @@ export const InfraDetailsNetGraphs = ({
|
||||
idx={config.idx}
|
||||
key={`${config.type}-${config.idx ?? ""}`}
|
||||
checks={checks}
|
||||
xKey="_id"
|
||||
xKey="bucketDate"
|
||||
yDomain={config.yDomain}
|
||||
dataKeys={config.dataKeys}
|
||||
gradient={true}
|
||||
|
||||
@@ -146,16 +146,28 @@ export interface CheckWithMonitor {
|
||||
updatedAt: string;
|
||||
timings: CheckTimings;
|
||||
}
|
||||
export interface GroupedCheck {
|
||||
bucketDate: Date;
|
||||
export interface AggregateCheck {
|
||||
bucketDate: string;
|
||||
|
||||
// Common aggregates
|
||||
count?: number;
|
||||
upChecks?: number;
|
||||
downChecks?: number;
|
||||
avgResponseTime?: number;
|
||||
avgResponseTimeUp?: number;
|
||||
avgResponseTimeDown?: number;
|
||||
|
||||
// Docker aggregates
|
||||
totalContainers?: number;
|
||||
runningContainers?: number;
|
||||
runningPercent?: number;
|
||||
healthyContainers?: number;
|
||||
healthyPercent?: number;
|
||||
runningContainersSnapshot?: IDockerContainerSummary[];
|
||||
totalExposedPorts?: number;
|
||||
uniqueImages?: number;
|
||||
|
||||
// PageSpeed aggregates
|
||||
accessibility?: number | null;
|
||||
bestPractices?: number | null;
|
||||
seo?: number | null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GroupedCheck, ICheck } from "@/types/check";
|
||||
import type { AggregateCheck, ICheck } from "@/types/check";
|
||||
import type { IMonitorStats } from "./monitorStats";
|
||||
|
||||
export const MonitorTypes = [
|
||||
@@ -61,7 +61,7 @@ export interface IMonitorWithStats {
|
||||
}
|
||||
|
||||
export interface IMonitorWithMonitorStats {
|
||||
checks: GroupedCheck[];
|
||||
checks: AggregateCheck[];
|
||||
monitor: IMonitor;
|
||||
stats: IMonitorStats;
|
||||
}
|
||||
@@ -48,7 +48,12 @@ class MongoCheckRepository implements IChecksRepository {
|
||||
avgResponseTimeDown: doc.avgResponseTimeDown,
|
||||
totalContainers: doc.totalContainers,
|
||||
runningContainers: doc.runningContainers,
|
||||
runningPercent: doc.runningPercent,
|
||||
healthyContainers: doc.healthyContainers,
|
||||
healthyPercent: doc.healthyPercent,
|
||||
runningContainersSnapshot: doc.runningContainersSnapshot,
|
||||
totalExposedPorts: doc.totalExposedPorts,
|
||||
uniqueImages: doc.uniqueImages,
|
||||
accessibility: doc.accessibility,
|
||||
bestPractices: doc.bestPractices,
|
||||
seo: doc.seo,
|
||||
@@ -190,12 +195,53 @@ class MongoCheckRepository implements IChecksRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
runningContainersSnapshot: { $last: "$runningContainersSnapshot" },
|
||||
totalExposedPorts: { $last: "$totalExposedPorts" },
|
||||
uniqueImages: { $last: "$uniqueImages" },
|
||||
};
|
||||
};
|
||||
|
||||
private getDockerProjection = (): object => {
|
||||
const projectStage: any = { status: 1, responseTime: 1, createdAt: 1 };
|
||||
projectStage["dockerContainers"] = 1;
|
||||
projectStage["runningContainersSnapshot"] = {
|
||||
$filter: {
|
||||
input: { $ifNull: ["$dockerContainers", []] },
|
||||
as: "c",
|
||||
cond: { $eq: ["$$c.running", true] },
|
||||
},
|
||||
};
|
||||
projectStage["totalExposedPorts"] = {
|
||||
$sum: {
|
||||
$map: {
|
||||
input: { $ifNull: ["$dockerContainers", []] },
|
||||
as: "c",
|
||||
in: { $size: { $ifNull: ["$$c.exposed_ports", []] } },
|
||||
},
|
||||
},
|
||||
};
|
||||
projectStage["uniqueImages"] = {
|
||||
$size: {
|
||||
$setUnion: [
|
||||
{
|
||||
$filter: {
|
||||
input: {
|
||||
$map: {
|
||||
input: { $ifNull: ["$dockerContainers", []] },
|
||||
as: "c",
|
||||
in: "$$c.base_image",
|
||||
},
|
||||
},
|
||||
as: "img",
|
||||
cond: {
|
||||
$and: [{ $ne: ["$$img", null] }, { $ne: ["$$img", ""] }],
|
||||
},
|
||||
},
|
||||
},
|
||||
[],
|
||||
],
|
||||
},
|
||||
};
|
||||
return projectStage;
|
||||
};
|
||||
|
||||
@@ -516,6 +562,7 @@ class MongoCheckRepository implements IChecksRepository {
|
||||
.allowDiskUse(true)
|
||||
.hint({ "metadata.monitorId": 1, createdAt: 1 });
|
||||
|
||||
console.log(checks);
|
||||
return checks.map(this.toAggregateCheck);
|
||||
};
|
||||
|
||||
|
||||
@@ -136,8 +136,6 @@ export interface CheckEntity {
|
||||
expiry: Date;
|
||||
}
|
||||
|
||||
// AggregateCheck reflects the minimal shape needed from aggregation results
|
||||
// for list/history views, with string ids and optional docker payload.
|
||||
export interface AggregateCheck {
|
||||
// Time bucket identifier from aggregation (_id)
|
||||
bucketDate: Date;
|
||||
@@ -153,8 +151,12 @@ export interface AggregateCheck {
|
||||
// Docker aggregates (counts per bucket)
|
||||
totalContainers?: number;
|
||||
runningContainers?: number;
|
||||
runningPercent?: number;
|
||||
healthyContainers?: number;
|
||||
|
||||
healthyPercent?: number;
|
||||
runningContainersSnapshot?: IDockerContainerSummary[];
|
||||
totalExposedPorts?: number;
|
||||
uniqueImages?: number;
|
||||
// PageSpeed aggregates
|
||||
accessibility?: number | null;
|
||||
bestPractices?: number | null;
|
||||
@@ -166,8 +168,7 @@ export interface AggregateCheck {
|
||||
lcp?: number | null;
|
||||
tbt?: number | null;
|
||||
|
||||
// Infrastructure aggregates (optional snapshot/averages)
|
||||
cpu?: Partial<ICpuInfo>;
|
||||
// Infrastructure aggregates
|
||||
memory?: Partial<IMemoryInfo>;
|
||||
disk?: Partial<IDiskInfo>[];
|
||||
host?: Partial<IHostInfo>;
|
||||
|
||||
Reference in new issue
Block a user