denormalize resposne times

This commit is contained in:
Alex Holliday committed 2026-07-29 10:57:20 -07:00
1 parent 81aab35961
commit e3075318b6
10 files changed
+31 -92

No files matched your search

@@ -0,0 +1,6 @@
export const computeYAxisCap = (values: number[]): number | undefined => {
const sorted = values.slice().sort((a, b) => a - b);
if (sorted.length < 2) return undefined;
const p95 = sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * 0.95))];
return p95 > 0 ? Math.ceil(p95 * 2) : undefined;
};
@@ -4,6 +4,7 @@ import {
AreaChart,
Area,
XAxis,
YAxis,
Tooltip,
CartesianGrid,
ResponsiveContainer,
@@ -24,6 +25,8 @@ import { useTheme } from "@mui/material/styles";
import type { Theme } from "@mui/material/styles";
import type { GroupedCheck } from "@/Types/Check";
import type { RootState } from "@/Types/state";
import { useMemo } from "react";
import { computeYAxisCap } from "@/Components/monitors/charts/ChartUtils";
type XTickProps = {
x: number;
@@ -69,7 +72,7 @@ const ResponseTimeToolTip = ({
if (!active) return null;
const format = tooltipDateFormatLookup(range);
const responseTime = Math.floor(payload[0]?.payload?.originalAvgResponseTime || 0);
const responseTime = Math.floor(payload[0]?.payload?.avgResponseTime || 0);
return (
<BaseBox sx={{ py: theme.spacing(2), px: theme.spacing(4) }}>
<Typography>{formatDateWithTz(String(label), format, uiTimezone)}</Typography>
@@ -90,6 +93,10 @@ export const HistogramDetails = ({
}) => {
const theme = useTheme();
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
const yMax = useMemo(() => {
const totals = checks.map((check) => check.avgResponseTime || 0);
return computeYAxisCap(totals);
}, [checks]);
return (
<BaseChart
icon={
@@ -132,6 +139,12 @@ export const HistogramDetails = ({
/>
</linearGradient>
</defs>
<YAxis
hide
// scale="sqrt"
domain={[0, yMax ?? "auto"]}
allowDataOverflow
/>
<XAxis
axisLine={false}
tickLine={false}
@@ -29,6 +29,7 @@ import { useSelector } from "react-redux";
import { useMemo } from "react";
import { useTheme } from "@mui/material";
import { SPACING } from "@/Utils/Theme/constants";
import { computeYAxisCap } from "@/Components/monitors/charts/ChartUtils";
export const PHASE_KEYS = [
"avgDns",
@@ -140,12 +141,10 @@ export const HistogramDetailsStacked = ({
// Cap the y domain at 2x the p95 of bucket totals, so typical stacks sit
// around mid-height with headroom above
const yMax = useMemo(() => {
const totals = checks
.map((check) => PHASE_KEYS.reduce((sum, key) => sum + check[key], 0))
.sort((a, b) => a - b);
if (totals.length < 2) return undefined;
const p95 = totals[Math.min(totals.length - 1, Math.floor(totals.length * 0.95))];
return p95 > 0 ? Math.ceil(p95 * 2) : undefined;
const totals = checks.map((check) =>
PHASE_KEYS.reduce((sum, key) => sum + check[key], 0)
);
return computeYAxisCap(totals);
}, [checks]);
return (
@@ -61,7 +61,6 @@ const UptimeDetailsPage = () => {
}
const params = new URLSearchParams();
params.append("dateRange", dateRange);
params.append("normalize", "true");
return `/monitors/uptime/details/${monitorId}?${params.toString()}`;
}, [monitorId, dateRange]);
-4
View File
@@ -261,7 +261,3 @@ export interface HasResponseTime {
export type NormalizedCheck<T extends HasResponseTime = Check> = T & {
originalResponseTime: number;
};
export type NormalizedUptimeCheck<T extends GroupedCheck = GroupedCheck> = T & {
originalAvgResponseTime: number;
};