incidents repo and data reversal
This commit is contained in:
1 parent
605b4713af
commit
51081a6a0e
32 files changed
+537
-241
No files matched your search
@@ -8,7 +8,7 @@ import { StatusLabel, ValueLabel } from "@/components/design-elements";
|
||||
import { BaseBox } from "@/components/design-elements";
|
||||
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import type { ICheck } from "@/types/check";
|
||||
import type { Check } from "@/types/check";
|
||||
import type { MonitorStatus } from "@/types/monitor";
|
||||
import { formatDateWithTz } from "@/utils/TimeUtils";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
@@ -16,7 +16,7 @@ import { getMonitorPath } from "@/utils/MonitorUtils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type CheckDetailsCardProps = {
|
||||
check: ICheck;
|
||||
check: Check;
|
||||
};
|
||||
|
||||
export const CheckDetailsCard = ({ check }: CheckDetailsCardProps) => {
|
||||
@@ -50,7 +50,7 @@ export const CheckDetailsCard = ({ check }: CheckDetailsCardProps) => {
|
||||
const httpText = Number.isFinite(httpStatusCode)
|
||||
? String(httpStatusCode)
|
||||
: "-";
|
||||
const typeText = check?.metadata?.type ?? "-";
|
||||
const typeText = check?.type ?? "-";
|
||||
const checkedAtText = check?.createdAt
|
||||
? formatDateWithTz(check.createdAt, "ddd, MMM D, YYYY, HH:mm A", uiTimezone)
|
||||
: "-";
|
||||
@@ -71,7 +71,7 @@ export const CheckDetailsCard = ({ check }: CheckDetailsCardProps) => {
|
||||
})}
|
||||
</Typography>
|
||||
{(() => {
|
||||
const href = `/${getMonitorPath(check.metadata.type)}/${check.metadata.monitorId}`;
|
||||
const href = `/${getMonitorPath(check.type)}/${check.monitorId}`;
|
||||
return href ? (
|
||||
<Typography variant="body2" sx={{ mt: 0.5 }}>
|
||||
<Link
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ICheck, CheckTimingPhases } from "@/types/check";
|
||||
import type { Check, CheckTimingPhases } from "@/types/check";
|
||||
import { PieChart, Pie, ResponsiveContainer, Tooltip, Legend } from "recharts";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
@@ -6,7 +6,7 @@ import { alpha, useTheme } from "@mui/material/styles";
|
||||
import { useState } from "react";
|
||||
import { BaseBox } from "@/components/design-elements";
|
||||
import { useTranslation } from "react-i18next";
|
||||
type TimingsChartProps = { check: ICheck | null };
|
||||
type TimingsChartProps = { check: Check | null };
|
||||
|
||||
export type TimingSegment = {
|
||||
name: string;
|
||||
|
||||
@@ -24,18 +24,17 @@ export const HeatmapResponseTime = ({
|
||||
}
|
||||
|
||||
if (!checks || checks.length === 0) return null;
|
||||
let data = Array<any>();
|
||||
|
||||
if (!checks || checks.length === 0) {
|
||||
checks = [];
|
||||
}
|
||||
if (checks.length !== 25) {
|
||||
const placeholders = Array(25 - checks.length).fill({
|
||||
status: "placeholder",
|
||||
const latestChecks = checks.slice(-25).reverse();
|
||||
|
||||
let data: Array<ICheck | { status: "placeholder" }>;
|
||||
if (latestChecks.length !== 25) {
|
||||
const placeholders = Array(25 - latestChecks.length).fill({
|
||||
status: "placeholder" as const,
|
||||
});
|
||||
data = [...checks, ...placeholders];
|
||||
data = [...latestChecks, ...placeholders];
|
||||
} else {
|
||||
data = checks;
|
||||
data = latestChecks;
|
||||
}
|
||||
return (
|
||||
<Box sx={{ width: "100%" }}>
|
||||
|
||||
@@ -3,15 +3,17 @@ import Tooltip from "@mui/material/Tooltip";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { formatDateWithTz } from "@/utils/TimeUtils";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import type { LatestCheck } from "@/types/check";
|
||||
import type { Check } from "@/types/check";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
|
||||
type HeatmapCheck = Check | { status: "placeholder" };
|
||||
|
||||
export const HeatmapResponseTimeTooltip = ({
|
||||
children,
|
||||
check,
|
||||
}: {
|
||||
children: React.ReactElement;
|
||||
check: LatestCheck;
|
||||
check: HeatmapCheck;
|
||||
}) => {
|
||||
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
|
||||
const theme = useTheme();
|
||||
@@ -47,7 +49,7 @@ export const HeatmapResponseTimeTooltip = ({
|
||||
>
|
||||
<Typography>
|
||||
{formatDateWithTz(
|
||||
check?.checkedAt,
|
||||
check?.createdAt,
|
||||
"ddd, MMMM D, YYYY, HH:mm A",
|
||||
uiTimezone
|
||||
)}
|
||||
|
||||
@@ -22,7 +22,10 @@ export const HistogramResponseTime = ({
|
||||
|
||||
if (!Array.isArray(checks) || checks.length === 0) return null;
|
||||
|
||||
const normalized = normalizeResponseTimes(checks.slice(-25), "responseTime");
|
||||
const normalized = normalizeResponseTimes(
|
||||
checks.slice(-25).reverse(),
|
||||
"responseTime"
|
||||
);
|
||||
let data = Array<any>();
|
||||
|
||||
if (!normalized || normalized.length === 0) {
|
||||
@@ -36,7 +39,6 @@ export const HistogramResponseTime = ({
|
||||
} else {
|
||||
data = normalized;
|
||||
}
|
||||
|
||||
const chartHeight = typeof height === "number" ? `${height}px` : height;
|
||||
const gridGap = gap ?? theme.spacing(0.5);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ export const BarDockerCount = ({
|
||||
) : (
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<BarChart
|
||||
data={data}
|
||||
data={[...data].reverse()}
|
||||
margin={{ top: 8, right: 8, left: isSmall ? 4 : 12, bottom: 8 }}
|
||||
>
|
||||
<defs>
|
||||
|
||||
@@ -62,7 +62,7 @@ export const HistogramDockerPercentage = ({
|
||||
) : (
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<AreaChart
|
||||
data={data}
|
||||
data={[...data].reverse()}
|
||||
margin={{ top: 8, right: 8, left: isSmall ? 0 : 8, bottom: 8 }}
|
||||
>
|
||||
<CartesianGrid
|
||||
|
||||
@@ -117,11 +117,12 @@ export const HistogramInfrastructure = ({
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const uniqueId = useId();
|
||||
let data = checks.reverse();
|
||||
|
||||
let avgTemps: { bucketDate: string; avg_temp: number | null }[] = [];
|
||||
let tempYDomain: number[] = [];
|
||||
if (type === "temp") {
|
||||
avgTemps = checks.map((check) => {
|
||||
avgTemps = data.map((check) => {
|
||||
const temps = check.cpu?.temperature || [];
|
||||
if (temps.length === 0) return { ...check, avg_temp: null };
|
||||
const totalTemp = temps.reduce((sum, temp) => sum + (temp || 0), 0);
|
||||
@@ -139,7 +140,7 @@ export const HistogramInfrastructure = ({
|
||||
return (
|
||||
<BaseChart icon={null} title={title}>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<AreaChart data={type === "temp" ? avgTemps : checks}>
|
||||
<AreaChart data={type === "temp" ? avgTemps : data}>
|
||||
<XAxis
|
||||
dataKey={xKey}
|
||||
tick={(props) => <XTick {...props} range={range} />}
|
||||
|
||||
@@ -4,12 +4,12 @@ import Grid from "@mui/material/Grid";
|
||||
|
||||
import { useParams } from "react-router";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ICheck } from "@/types/check";
|
||||
import type { Check } from "@/types/check";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
const CheckDetails = () => {
|
||||
const { id } = useParams();
|
||||
|
||||
const { response, loading, error } = useGet<ApiResponse<ICheck>>(
|
||||
const { response, loading, error } = useGet<ApiResponse<Check>>(
|
||||
`/checks/${id}`
|
||||
);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { SelectChangeEvent } from "@mui/material/Select";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
import type { ICheck } from "@/types/check";
|
||||
import type { Check } from "@/types/check";
|
||||
import { config } from "@/config/index";
|
||||
|
||||
const ChecksPage = () => {
|
||||
@@ -29,7 +29,7 @@ const ChecksPage = () => {
|
||||
const monitors: IMonitor[] = monitorResponse?.data || [];
|
||||
|
||||
const { response: checksResponse, loading: checksLoading } = useGet<
|
||||
ApiResponse<{ hasMore: boolean; checks: ICheck[] }>
|
||||
ApiResponse<{ hasMore: boolean; checks: Check[] }>
|
||||
>(
|
||||
`/checks?page=${page}&rowsPerPage=${rowsPerPage}&range=${range}&status=${status}${
|
||||
selectedMonitorId !== "all" ? `&monitorId=${selectedMonitorId}` : ""
|
||||
@@ -101,6 +101,7 @@ const ChecksPage = () => {
|
||||
</Stack>
|
||||
<ChecksTable
|
||||
checks={checks}
|
||||
monitors={monitors}
|
||||
hasMore={hasMore}
|
||||
page={page}
|
||||
setPage={setPage}
|
||||
|
||||
@@ -6,27 +6,26 @@ import {
|
||||
} from "@/components/design-elements";
|
||||
import Box from "@mui/material/Box";
|
||||
import type { Header } from "@/components/design-elements/Table";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { formatDateWithTz } from "@/utils/TimeUtils";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import type { ICheck } from "@/types/check";
|
||||
import type { MonitorStatus } from "@/types/monitor";
|
||||
import { useNavigate } from "react-router";
|
||||
|
||||
type CheckWithMonitor = ICheck & {
|
||||
metadata?: { monitorId?: { name?: string } };
|
||||
};
|
||||
import type { Check } from "@/types/check";
|
||||
|
||||
export const ChecksTable = ({
|
||||
checks,
|
||||
monitors,
|
||||
hasMore,
|
||||
page,
|
||||
setPage,
|
||||
rowsPerPage,
|
||||
setRowsPerPage,
|
||||
}: {
|
||||
checks: CheckWithMonitor[];
|
||||
checks: Check[];
|
||||
monitors: IMonitor[] | null;
|
||||
hasMore?: boolean;
|
||||
page: number;
|
||||
setPage: (page: number) => void;
|
||||
@@ -38,12 +37,15 @@ export const ChecksTable = ({
|
||||
const navigate = useNavigate();
|
||||
|
||||
const getHeaders = (t: Function, uiTimezone: string) => {
|
||||
const headers: Header<CheckWithMonitor>[] = [
|
||||
const headers: Header<Check>[] = [
|
||||
{
|
||||
id: "monitorName",
|
||||
content: t("common.table.headers.monitor"),
|
||||
render: (row) => {
|
||||
return row.metadata?.monitorId?.name || "N/A";
|
||||
return (
|
||||
monitors?.find((monitor) => monitor.id === row.monitorId)?.name ||
|
||||
"N/A"
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -69,6 +71,7 @@ export const ChecksTable = ({
|
||||
content: t("checks.table.headers.statusCode"),
|
||||
render: (row) => {
|
||||
const code = row.httpStatusCode;
|
||||
if (!code) return "N/A";
|
||||
const value =
|
||||
code < 300 ? "positive" : code < 400 ? "neutral" : "negative";
|
||||
return <ValueLabel value={value} text={String(code)} />;
|
||||
@@ -108,7 +111,7 @@ export const ChecksTable = ({
|
||||
headers={headers}
|
||||
data={checks}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/checks/${row._id}`);
|
||||
navigate(`/checks/${row.id}`);
|
||||
}}
|
||||
emptyViewText={t("checks.table.empty")}
|
||||
/>
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useTheme } from "@mui/material/styles";
|
||||
import { useNavigate, useParams } from "react-router";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import type { IIncident } from "@/types/incident";
|
||||
import type { IncidentWithDetails } from "@/types/incident";
|
||||
import { formatDateWithTz } from "@/utils/TimeUtils";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
@@ -22,7 +22,9 @@ const IncidentDetailsPage = () => {
|
||||
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { response } = useGet<ApiResponse<IIncident>>(`/incidents/${id}`);
|
||||
const { response } = useGet<ApiResponse<IncidentWithDetails>>(
|
||||
`/incidents/${id}`
|
||||
);
|
||||
const incident = response?.data || null;
|
||||
|
||||
if (!incident) {
|
||||
@@ -45,11 +47,11 @@ const IncidentDetailsPage = () => {
|
||||
<Stack direction={{ xs: "column", md: "row" }} gap={theme.spacing(8)}>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.monitor")}
|
||||
subtitle={incident.monitorId?.name || "N/A"}
|
||||
subtitle={incident.monitor?.name || "N/A"}
|
||||
onClick={() => {
|
||||
const type = incident.monitorId.type as MonitorType;
|
||||
const type = incident.monitor.type;
|
||||
const path = getMonitorPath(type);
|
||||
const id = (incident.monitorId as any)?._id;
|
||||
const id = incident.monitor?.id;
|
||||
if (id) navigate(`/${path}/${id}`);
|
||||
}}
|
||||
/>
|
||||
@@ -78,7 +80,7 @@ const IncidentDetailsPage = () => {
|
||||
<ResolutionCard
|
||||
resolved={incident.resolved}
|
||||
type={incident.resolutionType}
|
||||
by={incident.resolvedBy?.email}
|
||||
by={incident.resolvedByUser?.email}
|
||||
note={incident.resolutionNote}
|
||||
timestampLabel={
|
||||
incident.resolved && incident.endedAt
|
||||
|
||||
@@ -13,7 +13,7 @@ import { usePatch } from "@/hooks/UseApi";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { formatDateWithTz } from "@/utils/TimeUtils";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import type { IIncident } from "@/types/incident";
|
||||
import type { IncidentWithDetails } from "@/types/incident";
|
||||
import { useNavigate } from "react-router";
|
||||
|
||||
export const IncidentTable = ({
|
||||
@@ -25,7 +25,7 @@ export const IncidentTable = ({
|
||||
setRowsPerPage,
|
||||
refetch,
|
||||
}: {
|
||||
incidents: IIncident[];
|
||||
incidents: IncidentWithDetails[];
|
||||
count: number;
|
||||
page: number;
|
||||
setPage: (page: number) => void;
|
||||
@@ -39,12 +39,12 @@ export const IncidentTable = ({
|
||||
const navigate = useNavigate();
|
||||
|
||||
const getHeaders = (t: Function, uiTimezone: string) => {
|
||||
const headers: Header<IIncident>[] = [
|
||||
const headers: Header<IncidentWithDetails>[] = [
|
||||
{
|
||||
id: "name",
|
||||
content: t("common.table.headers.monitor"),
|
||||
render: (row) => {
|
||||
return row.monitorId?.name || "N/A";
|
||||
return row.monitor?.name || "N/A";
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -75,7 +75,7 @@ export const IncidentTable = ({
|
||||
id: "status",
|
||||
content: t("incidents.table.headers.monitorStatus"),
|
||||
render: (row) => {
|
||||
const status = row.monitorId?.status;
|
||||
const status = row.monitor?.status;
|
||||
return status ? (
|
||||
<StatusLabel status={status} />
|
||||
) : (
|
||||
@@ -106,7 +106,7 @@ export const IncidentTable = ({
|
||||
id: "resolvedBy",
|
||||
content: t("incidents.table.headers.resolvedBy"),
|
||||
render: (row) => {
|
||||
return row.resolvedBy?.email || "N/A";
|
||||
return row.resolvedByUser?.email || "N/A";
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -118,7 +118,7 @@ export const IncidentTable = ({
|
||||
loading={isPatching}
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
await patch(`/incidents/${row._id}/resolve`, {
|
||||
await patch(`/incidents/${row.id}/resolve`, {
|
||||
resolutionNote: "Resolved via UI",
|
||||
});
|
||||
refetch();
|
||||
@@ -158,7 +158,7 @@ export const IncidentTable = ({
|
||||
headers={headers}
|
||||
data={incidents}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/incidents/${row._id}`);
|
||||
navigate(`/incidents/${row.id}`);
|
||||
}}
|
||||
emptyViewPositive
|
||||
emptyViewText={t("incidents.table.empty")}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { useState, useEffect } from "react";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import type { SelectChangeEvent } from "@mui/material/Select";
|
||||
import type { IIncident } from "@/types/incident";
|
||||
import type { IncidentWithDetails } from "@/types/incident";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
import { config } from "@/config/index";
|
||||
|
||||
@@ -31,7 +31,7 @@ const IncidentsPage = () => {
|
||||
loading: incidentsLoading,
|
||||
isValidating: incidentsValidating,
|
||||
refetch,
|
||||
} = useGet<ApiResponse<{ count: number; incidents: IIncident[] }>>(
|
||||
} = useGet<ApiResponse<{ count: number; incidents: IncidentWithDetails[] }>>(
|
||||
`/incidents?page=${page}&rowsPerPage=${rowsPerPage}&range=${range}${
|
||||
selectedMonitorId && selectedMonitorId !== "all"
|
||||
? `&monitorId=${selectedMonitorId}`
|
||||
|
||||
+28
-20
@@ -1,4 +1,4 @@
|
||||
import type { MonitorType } from "./monitor";
|
||||
import type { MonitorType, MonitorStatus } from "./monitor";
|
||||
|
||||
export interface CheckTimingPhases {
|
||||
wait: number;
|
||||
@@ -11,7 +11,7 @@ export interface CheckTimingPhases {
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface CheckTimings {
|
||||
export interface GotTimings {
|
||||
start: string;
|
||||
socket: string;
|
||||
lookup: string;
|
||||
@@ -103,6 +103,12 @@ export interface INetInfo {
|
||||
fifo_in: number;
|
||||
fifo_out: number;
|
||||
}
|
||||
|
||||
export interface ICaptureInfo {
|
||||
version?: string;
|
||||
mode?: string;
|
||||
}
|
||||
|
||||
export interface ICheck {
|
||||
_id: string;
|
||||
metadata: {
|
||||
@@ -119,33 +125,35 @@ export interface ICheck {
|
||||
expiry: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
timings: CheckTimings;
|
||||
timings: GotTimings;
|
||||
lighthouse?: ICheckLighthouseFields;
|
||||
system?: ISystemInfo;
|
||||
// Present for docker monitor checks
|
||||
dockerContainers?: IDockerContainerSummary[];
|
||||
}
|
||||
export interface CheckWithMonitor {
|
||||
_id: string;
|
||||
metadata: {
|
||||
monitorId: {
|
||||
_id: string;
|
||||
name: string;
|
||||
};
|
||||
type: string;
|
||||
teamId: string;
|
||||
};
|
||||
status: string;
|
||||
|
||||
export interface Check {
|
||||
id: string;
|
||||
monitorId: string;
|
||||
teamId: string;
|
||||
type: MonitorType;
|
||||
status: MonitorStatus;
|
||||
httpStatusCode?: number;
|
||||
message: string;
|
||||
responseTime: number;
|
||||
normalResponseTime?: number;
|
||||
httpStatusCode: number;
|
||||
ack: boolean;
|
||||
expiry: string;
|
||||
responseTime?: number;
|
||||
timings?: GotTimings;
|
||||
errorMessage?: string;
|
||||
ackAt?: string;
|
||||
ackBy?: string;
|
||||
system?: ISystemInfo;
|
||||
capture?: ICaptureInfo;
|
||||
lighthouse?: ICheckLighthouseFields;
|
||||
dockerContainers?: IDockerContainerSummary[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
timings: CheckTimings;
|
||||
expiry: string;
|
||||
}
|
||||
|
||||
export interface AggregateCheck {
|
||||
bucketDate: string;
|
||||
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
import type { IMongoUser } from "@/types/user";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
|
||||
export interface IIncident {
|
||||
_id: string;
|
||||
monitorId: IMonitor;
|
||||
export const ResolutionTypes = ["auto", "manual"] as const;
|
||||
export type ResolutionType = (typeof ResolutionTypes)[number];
|
||||
import type { MonitorType, MonitorStatus } from "@/types/monitor";
|
||||
export interface Incident {
|
||||
id: string;
|
||||
monitorId: string;
|
||||
teamId: string;
|
||||
startedAt: string;
|
||||
startCheck: string;
|
||||
resolved: boolean;
|
||||
endedAt?: string;
|
||||
endCheck?: string;
|
||||
resolvedBy?: IMongoUser;
|
||||
resolutionType?: string;
|
||||
resolved: boolean;
|
||||
resolvedBy?: string;
|
||||
resolutionType?: ResolutionType;
|
||||
resolutionNote?: string;
|
||||
}
|
||||
|
||||
export interface IncidentWithDetails extends Incident {
|
||||
monitor: {
|
||||
id: string;
|
||||
name: string;
|
||||
type: MonitorType;
|
||||
status: MonitorStatus;
|
||||
};
|
||||
resolvedByUser?: {
|
||||
email: string;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user