From 14529b9e34ea975692a79c423f83607ed1679d1a Mon Sep 17 00:00:00 2001 From: Alex Fedotyev <61838744+alex-fedotyev@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:48:03 +0000 Subject: [PATCH] feat(app): bad events flyout on the SLO page Adds a flyout with an SLO's bad events, opened from a "View bad events" button on the SLO page or from the list's row menu. It is Search's own results table, fed by the same filters the SLO counts with, so the events can be examined without leaving the SLO; latency SLOs list the slowest first. It covers the last hour or the whole window, and can open on any range from the URL (?bad=burn|window|custom&from&to), which alert notifications link to. For the last hour it also says how many bad events the SLO counted at its last update. Co-Authored-By: Claude Opus 5.5 --- .../app/src/components/Slos/SloDetailPage.tsx | 47 +++++- .../src/components/Slos/SloEventsDrawer.tsx | 150 ++++++++++++++++++ .../app/src/components/Slos/SloRowMenu.tsx | 23 ++- packages/app/src/components/Slos/sloUtils.ts | 41 ++++- 4 files changed, 253 insertions(+), 8 deletions(-) create mode 100644 packages/app/src/components/Slos/SloEventsDrawer.tsx diff --git a/packages/app/src/components/Slos/SloDetailPage.tsx b/packages/app/src/components/Slos/SloDetailPage.tsx index 7f7fec7cc..cdb74ace5 100644 --- a/packages/app/src/components/Slos/SloDetailPage.tsx +++ b/packages/app/src/components/Slos/SloDetailPage.tsx @@ -1,19 +1,23 @@ +import { useMemo } from 'react'; import dynamic from 'next/dynamic'; import Head from 'next/head'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import { parseAsInteger, parseAsStringEnum, useQueryStates } from 'nuqs'; import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo'; import type { TSource } from '@hyperdx/common-utils/dist/types'; import { Alert, Anchor, Breadcrumbs, + Button, Container, Group, Skeleton, Stack, Text, } from '@mantine/core'; +import { IconSearch } from '@tabler/icons-react'; import { usePageTitle } from '@/brand'; import { PageHeader } from '@/components/PageHeader'; @@ -21,10 +25,15 @@ import { withAppNavForSurface } from '@/layout'; import { useSlo, useSlosEnabledGuard } from '@/slo'; import { useSource } from '@/source'; +import { + SloEventsDrawer, + type SloEventsRange, + type SloEventsRequest, +} from './SloEventsDrawer'; import { SloNumbers } from './SloNumbers'; import { SloRowMenu } from './SloRowMenu'; import { SloStateBadge } from './SloStateBadge'; -import { getSloDisplayState } from './sloUtils'; +import { getSloDisplayState, getSloEventsRange } from './sloUtils'; import { type SloLiveStatus, useSloLiveStatus, @@ -45,6 +54,26 @@ function SloDetailView({ const router = useRouter(); // Named with its section, as the alert detail page is. const title = usePageTitle(`${slo.name} - SLOs`); + // The bad-events flyout lives in the URL, with its time range, so list + // rows and alert notifications can open it directly: + // ?bad=burn|window|custom&from&to. + const [badEvents, setBadEvents] = useQueryStates({ + bad: parseAsStringEnum(['burn', 'window', 'custom']), + from: parseAsInteger, + to: parseAsInteger, + }); + + const eventsRequest = useMemo(() => { + const { bad, from, to } = badEvents; + if (bad == null || from == null || to == null || to <= from) return null; + return { range: bad, dateRange: [new Date(from), new Date(to)] }; + }, [badEvents]); + + // Ranges that end now are resolved here, when the flyout is opened. + const openBadEvents = (range: 'burn' | 'window') => { + const [from, to] = getSloEventsRange(slo, range, Date.now()); + void setBadEvents({ bad: range, from, to }); + }; const state = live?.state ?? getSloDisplayState(slo); return ( @@ -70,6 +99,15 @@ function SloDetailView({ } actions={ + router.push('/slos')} /> } @@ -89,6 +127,13 @@ function SloDetailView({ /> + setBadEvents({ bad: null, from: null, to: null })} + /> ); } diff --git a/packages/app/src/components/Slos/SloEventsDrawer.tsx b/packages/app/src/components/Slos/SloEventsDrawer.tsx new file mode 100644 index 000000000..e3ccd486c --- /dev/null +++ b/packages/app/src/components/Slos/SloEventsDrawer.tsx @@ -0,0 +1,150 @@ +import { useMemo } from 'react'; +import { buildSearchChartConfig } from '@hyperdx/common-utils/dist/core/searchChartConfig'; +import { + buildSloBadEventsSearch, + getSloBurnRule, +} from '@hyperdx/common-utils/dist/core/slo'; +import { getFirstTimestampValueExpression } from '@hyperdx/common-utils/dist/core/utils'; +import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo'; +import { DisplayType, type TSource } from '@hyperdx/common-utils/dist/types'; +import { Drawer, Group, SegmentedControl, Stack, Text } from '@mantine/core'; + +import DBSqlRowTableWithSideBar from '@/components/DBSqlRowTableWithSidebar'; +import { DrawerHeader } from '@/components/DrawerUtils'; +import { useFormatTime } from '@/useFormatTime'; +import { useZIndex, ZIndexContext } from '@/zIndex'; + +import { + formatBurnWindow, + formatCount, + formatSloWindow, + getSourceDefaultSelect, +} from './sloUtils'; + +export type SloEventsRange = 'burn' | 'window' | 'custom'; + +export type SloEventsRequest = { + range: SloEventsRange; + dateRange: [Date, Date]; +}; + +/** + * Flyout with an SLO's bad events, so they can be examined without leaving + * the SLO. The table is Search's own results table, fed by the same filters + * the SLO counts with. The time range comes from the caller, who resolves it + * when the flyout opens. + */ +export function SloEventsDrawer({ + slo, + source, + request, + onRangeChange, + onClose, +}: { + slo: SloApiResponse; + source?: TSource; + request: SloEventsRequest | null; + onRangeChange: (range: 'burn' | 'window') => void; + onClose: () => void; +}) { + const contextZIndex = useZIndex(); + const drawerZIndex = contextZIndex + 10; + const formatTime = useFormatTime(); + // The burn rule's first window, the last hour. + const burn = getSloBurnRule(slo.window)[0]; + const isLatency = slo.indicator.template === 'latency'; + const dateRange = request?.dateRange; + + const config = useMemo(() => { + if (!source || !dateRange) return undefined; + const defaultSelect = getSourceDefaultSelect(source); + const search = buildSloBadEventsSearch(slo, defaultSelect); + const sourceOrderBy = + 'orderByExpression' in source ? source.orderByExpression?.trim() : ''; + return { + ...buildSearchChartConfig(source, { + where: search.where, + whereLanguage: search.whereLanguage, + filters: search.filters, + select: search.select ?? defaultSelect, + orderBy: + search.orderBy ?? + (sourceOrderBy || + `${getFirstTimestampValueExpression(source.timestampValueExpression)} DESC`), + displayType: DisplayType.Search, + dateRange, + }), + dateRange, + }; + }, [source, dateRange, slo]); + + // The SLO's own count for the burn window, so a small difference from late + // data is not a surprise. + const storedBurn = slo.status?.burn[0]; + const sloBadCount = + request?.range === 'burn' && storedBurn?.window === burn.window + ? storedBurn.bad + : undefined; + + return ( + + + + + + + onRangeChange(value === 'window' ? 'window' : 'burn') + } + data={[ + { + value: 'burn', + label: `Last ${formatBurnWindow(burn.window)}`, + }, + { + value: 'window', + label: `Last ${formatSloWindow(slo.window)}`, + }, + ...(request?.range === 'custom' + ? [{ value: 'custom', label: 'Selected range' }] + : []), + ]} + data-testid="slo-events-range" + /> + {dateRange && ( + + {formatTime(dateRange[0], { format: 'short' })} to{' '} + {formatTime(dateRange[1], { format: 'short' })}. + {isLatency ? ' Slowest first.' : ''} + {sloBadCount != null + ? ` The SLO counted ${formatCount(sloBadCount)} bad events at its last update.` + : ''} + + )} + +
+ {config && source && ( + + )} +
+
+
+
+ ); +} diff --git a/packages/app/src/components/Slos/SloRowMenu.tsx b/packages/app/src/components/Slos/SloRowMenu.tsx index e3041e962..f928fb048 100644 --- a/packages/app/src/components/Slos/SloRowMenu.tsx +++ b/packages/app/src/components/Slos/SloRowMenu.tsx @@ -1,13 +1,22 @@ import Link from 'next/link'; +import { useRouter } from 'next/router'; import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo'; import { ActionIcon, Menu } from '@mantine/core'; import { notifications } from '@mantine/notifications'; -import { IconCopy, IconDots, IconPencil, IconTrash } from '@tabler/icons-react'; +import { + IconCopy, + IconDots, + IconPencil, + IconSearch, + IconTrash, +} from '@tabler/icons-react'; import { useDeleteSlo } from '@/slo'; import { useConfirm } from '@/useConfirm'; import { getApiErrorMessage } from '@/utils/apiErrors'; +import { getSloEventsRange } from './sloUtils'; + export function SloRowMenu({ slo, onDeleted, @@ -15,6 +24,7 @@ export function SloRowMenu({ slo: SloApiResponse; onDeleted?: () => void; }) { + const router = useRouter(); const confirm = useConfirm(); const deleteSlo = useDeleteSlo(); @@ -46,6 +56,11 @@ export function SloRowMenu({ } }; + const viewBadEvents = () => { + const [from, to] = getSloEventsRange(slo, 'burn', Date.now()); + void router.push(`/slos/${slo.id}?bad=burn&from=${from}&to=${to}`); + }; + return ( @@ -59,6 +74,12 @@ export function SloRowMenu({ e.stopPropagation()}> + } + onClick={viewBadEvents} + > + View bad events +