Skip to content

Commit

Permalink
feat: add group by latency and uptime
Browse files Browse the repository at this point in the history
Closes #1434
  • Loading branch information
mainawycliffe committed Nov 2, 2023
1 parent fe05705 commit 85da351
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/Canary/grouping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ export function getGroupedChecks(checks: HealthCheck[] = [], groupBy?: string) {
return groupedChecks;
}

if (groupBy === "latency") {
const groupedChecks: Record<string, HealthCheck[]> = {};
const groupNames: string[] = [];
checks.forEach((check) => {
const value = check[groupBy].p95
? "p95"
: check[groupBy].p97
? "p97"
: "p99" ?? "(unknown)";
if (groupNames.indexOf(value.toString()) === -1) {
groupNames.push(value.toString());
groupedChecks[value] = [];
}
groupedChecks[value].push(check);
});
return groupedChecks;
}

if (groupBy === "uptime") {
const groupedChecks: Record<string, HealthCheck[]> = {};
const groupNames: string[] = [];
checks.forEach((check) => {
const value =
(
(check[groupBy].passed /
(check[groupBy].failed + check[groupBy].passed)) *
100
).toFixed() + "%" || "(unknown)";
if (groupNames.indexOf(value.toString()) === -1) {
groupNames.push(value.toString());
groupedChecks[value] = [];
}
groupedChecks[value].push(check);
});
return groupedChecks;
}

const groupedChecks: Record<string, HealthCheck[]> = { Others: [] };
const groupNames = ["Others"];
checks.forEach((check) => {
Expand Down
21 changes: 21 additions & 0 deletions src/components/Dropdown/GroupByDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { getLabelSelections } from "./lib/lists";
import { ReactSelectDropdown } from "../ReactSelectDropdown";
import { ComponentProps } from "react";
import { HealthCheck } from "../../api/types/health";
import { BsSpeedometer } from "react-icons/bs";
import { FaClock } from "react-icons/fa";
import { GoClock } from "react-icons/go";

const defaultGroupSelections = {
"no-group": {
Expand Down Expand Up @@ -42,6 +45,24 @@ const defaultGroupSelections = {
value: "description",
labelValue: null,
key: "description"
},
latency: {
id: "latency",
name: "latency",
icon: <BsSpeedometer />,
description: "Latency",
value: "latency",
labelValue: null,
key: "latency"
},
uptime: {
id: "uptime",
name: "uptime",
icon: <GoClock />,
description: "Uptime",
value: "uptime",
labelValue: null,
key: "uptime"
}
};

Expand Down

0 comments on commit 85da351

Please sign in to comment.