Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/slo-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@hyperdx/app': patch
---

feat: SLO pages behind NEXT_PUBLIC_ENABLE_SLOS

Adds a list of SLOs, a builder with a preview of good, bad and excluded
events, and a detail page whose numbers and SLI, error budget and burn-rate
charts are computed when it opens, with its fast and slow burn alerts and
their firings over the last 7 days, and a flyout of bad events. A grouped SLO
expands into its groups in the list, and its detail page shows all groups
or one, picked from a menu or a link. The list filters by tag and source
and sorts by state, name, SLI, budget left or burn rate, and an SLO can be
duplicated without its alerts. Search gets an SLO button that starts the
builder from the current query, and SLO alerts show as such on the Alerts
page.
4 changes: 4 additions & 0 deletions packages/app/src/components/Slos/SloCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ export function SloCharts({
slo,
source,
now,
group,
onBucketSelect,
}: {
slo: SloApiResponse;
source: TSource;
now: Date;
/** One group of a grouped SLO. */
group?: string;
onBucketSelect: (start: Date, end: Date) => void;
}) {
const formatTime = useFormatTime();
const { config, granularity, buckets, isLoading, error } = useSloHistory(
slo,
source,
now,
group,
);
const bucketMs = convertGranularityToSeconds(granularity) * 1000;
// The burn chart follows the rule's 1h condition, the one that pages first.
Expand Down
55 changes: 48 additions & 7 deletions packages/app/src/components/Slos/SloDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ 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 {
parseAsInteger,
parseAsStringEnum,
useQueryState,
useQueryStates,
} from 'nuqs';
import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo';
import type { TSource } from '@hyperdx/common-utils/dist/types';
import {
Expand Down Expand Up @@ -32,6 +37,7 @@ import {
type SloEventsRange,
type SloEventsRequest,
} from './SloEventsDrawer';
import { SloGroupSelect } from './SloGroupSelect';
import { SloNumbers } from './SloNumbers';
import { SloRowMenu } from './SloRowMenu';
import { SloStateBadge } from './SloStateBadge';
Expand All @@ -42,13 +48,21 @@ import {
useSloNow,
} from './useSloLiveStatus';

type SloGroupProps = {
/** The group of a grouped SLO the page shows; all groups when unset. */
group?: string;
onGroupChange: (group: string | null) => void;
};

function SloDetailView({
slo,
source,
now,
live,
liveError,
}: {
group,
onGroupChange,
}: SloGroupProps & {
slo: SloApiResponse;
source?: TSource;
now?: Date;
Expand Down Expand Up @@ -83,7 +97,16 @@ function SloDetailView({
setBadEvents({ bad: 'custom', from: start.getTime(), to: end.getTime() }),
[setBadEvents],
);
const state = live?.state ?? getSloDisplayState(slo);
// A grouped SLO is as bad as its worst group, which its stored state
// knows and the live numbers of all groups together do not.
const state =
group != null
? (live?.state ??
slo.status?.groups?.find(g => g.value === group)?.state ??
'pending')
: slo.groupBy != null
? getSloDisplayState(slo)
: (live?.state ?? getSloDisplayState(slo));

return (
<div data-testid="slo-detail-page">
Expand All @@ -104,6 +127,13 @@ function SloDetailView({
{slo.name}
</Text>
<SloStateBadge state={state} />
{slo.groupBy != null && (
<SloGroupSelect
slo={slo}
group={group}
onChange={onGroupChange}
/>
)}
</Group>
}
actions={
Expand All @@ -130,6 +160,7 @@ function SloDetailView({
)}
<SloNumbers
slo={slo}
group={group}
hasSource={source != null}
live={live}
liveError={liveError}
Expand All @@ -139,6 +170,7 @@ function SloDetailView({
slo={slo}
source={source}
now={now}
group={group}
onBucketSelect={onBucketSelect}
/>
)}
Expand All @@ -149,6 +181,7 @@ function SloDetailView({
<SloEventsDrawer
slo={slo}
source={source}
group={group}
request={eventsRequest}
onRangeChange={openBadEvents}
onClose={() => setBadEvents({ bad: null, from: null, to: null })}
Expand All @@ -161,19 +194,21 @@ function SloDetailView({
function SloDetailLive({
slo,
source,
}: {
...groupProps
}: SloGroupProps & {
slo: SloApiResponse;
source: TSource;
}) {
const now = useSloNow();
const { live, error } = useSloLiveStatus(slo, source, now);
const { live, error } = useSloLiveStatus(slo, source, now, groupProps.group);
return (
<SloDetailView
slo={slo}
source={source}
now={now}
live={live}
liveError={error}
{...groupProps}
/>
);
}
Expand All @@ -187,6 +222,8 @@ function SloDetailPage() {
const { data: source, isPending: isSourcePending } = useSource({
id: slo?.source,
});
// The group in view, from list rows and alert notifications too.
const [groupParam, setGroup] = useQueryState('group');

if (!enabled) return null;
if (isPending || (slo != null && isSourcePending)) {
Expand All @@ -207,11 +244,15 @@ function SloDetailPage() {
</Container>
);
}
const groupProps: SloGroupProps = {
group: slo.groupBy != null ? (groupParam ?? undefined) : undefined,
onGroupChange: value => void setGroup(value),
};
// A deleted source leaves the stored numbers, which say what went wrong.
return source ? (
<SloDetailLive slo={slo} source={source} />
<SloDetailLive slo={slo} source={source} {...groupProps} />
) : (
<SloDetailView slo={slo} />
<SloDetailView slo={slo} {...groupProps} />
);
}

Expand Down
26 changes: 23 additions & 3 deletions packages/app/src/components/Slos/SloDetailPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
getSloAlertRuleLabel,
getSloAlertTarget,
SLO_BURN_CONDITIONS,
SLO_MAX_GROUPS,
type SloApiResponse,
type SloState,
type SloGroupState,
type SloStats,
} from '@hyperdx/common-utils/dist/slo';
import { WebhookService } from '@hyperdx/common-utils/dist/types';
Expand Down Expand Up @@ -78,7 +79,7 @@ export function SloStatsGrid({
}: {
slo: SloApiResponse;
stats: SloStats;
state: SloState;
state: SloGroupState;
}) {
// The rule's conditions with their numbers, the 1h one first.
const [hour, sixHours] = getSloBurnRule(slo.window).map((condition, i) => ({
Expand Down Expand Up @@ -173,7 +174,12 @@ export function SloAlertPanel({ slo }: { slo: SloApiResponse }) {
? `Notifies ${channels.join(', ')} when ${sentence}.`
: `Turn it on to be notified when ${sentence}.`}
</Text>
{target && status && <SloRecentFirings alertId={status.id} />}
{target && status && (
<SloRecentFirings
alertId={status.id}
grouped={slo.groupBy != null}
/>
)}
</Stack>
);
})}
Expand Down Expand Up @@ -247,6 +253,20 @@ export function SloDefinitionPanel({
<Code>{slo.indicator.good}</Code>
)}
</Text>
{slo.groupBy != null && (
<Text size="sm" data-testid="slo-definition-group-by">
<Text span c="dimmed">
Group by:{' '}
</Text>
<Code>{slo.groupBy}</Code>
{status?.groupCount != null &&
`, ${formatCount(status.groupCount)} ${status.groupCount === 1 ? 'group' : 'groups'}` +
(status.groupCount > SLO_MAX_GROUPS
? `; the ${SLO_MAX_GROUPS} with the most events are tracked`
: '')}
. Each group has its own SLI, error budget and alerts.
</Text>
)}
<Text size="sm">
<Text span c="dimmed">
Objective:{' '}
Expand Down
18 changes: 14 additions & 4 deletions packages/app/src/components/Slos/SloEventsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useZIndex, ZIndexContext } from '@/zIndex';
import {
formatBurnWindow,
formatCount,
formatSloGroup,
formatSloWindow,
getSourceDefaultSelect,
} from './sloUtils';
Expand All @@ -37,12 +38,15 @@ export type SloEventsRequest = {
export function SloEventsDrawer({
slo,
source,
group,
request,
onRangeChange,
onClose,
}: {
slo: SloApiResponse;
source?: TSource;
/** One group of a grouped SLO. */
group?: string;
request: SloEventsRequest | null;
onRangeChange: (range: 'burn' | 'window') => void;
onClose: () => void;
Expand All @@ -58,7 +62,7 @@ export function SloEventsDrawer({
const config = useMemo(() => {
if (!source || !dateRange) return undefined;
const defaultSelect = getSourceDefaultSelect(source);
const search = buildSloBadEventsSearch(slo, defaultSelect);
const search = buildSloBadEventsSearch(slo, defaultSelect, group);
const sourceOrderBy =
'orderByExpression' in source ? source.orderByExpression?.trim() : '';
return {
Expand All @@ -76,11 +80,14 @@ export function SloEventsDrawer({
}),
dateRange,
};
}, [source, dateRange, slo]);
}, [source, dateRange, slo, group]);

// 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 status = slo.status;
const storedBurn = (
group != null ? status?.groups?.find(g => g.value === group) : status
)?.burn[0];
const sloBadCount =
request?.range === 'burn' && storedBurn?.window === burn.window
? storedBurn.bad
Expand All @@ -99,7 +106,10 @@ export function SloEventsDrawer({
>
<ZIndexContext value={drawerZIndex}>
<Stack gap={0} h="100vh">
<DrawerHeader header={`Bad events: ${slo.name}`} onClose={onClose} />
<DrawerHeader
header={`Bad events: ${slo.name}${group != null ? ` (${formatSloGroup(group)})` : ''}`}
onClose={onClose}
/>
<Group px="md" py="xs" gap="sm" wrap="wrap">
<SegmentedControl
size="xs"
Expand Down
57 changes: 57 additions & 0 deletions packages/app/src/components/Slos/SloGroupSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo';
import { Select } from '@mantine/core';

import { formatSloGroup, sloStateLabel } from './sloUtils';

const ALL_GROUPS = 'all';
// Option values carry a prefix: a group's value can be any string, empty too.
const GROUP_PREFIX = 'group:';

/**
* Picks the group of a grouped SLO the page shows, or all groups together.
* The tracked groups come worst first, with their state.
*/
export function SloGroupSelect({
slo,
group,
onChange,
}: {
slo: SloApiResponse;
group?: string;
onChange: (group: string | null) => void;
}) {
const groups = slo.status?.groups ?? [];
const states = new Map(groups.map(g => [g.value, g.state]));
// A group from a link may be one the SLO does not track.
const values = groups.map(g => g.value);
if (group != null && !states.has(group)) values.unshift(group);
const data = [
{ value: ALL_GROUPS, label: 'All groups' },
...values.map(value => {
const state = states.get(value);
return {
value: `${GROUP_PREFIX}${value}`,
label: `${formatSloGroup(value)}${state ? ` (${sloStateLabel(state)})` : ''}`,
};
}),
];
return (
<Select
size="xs"
w={260}
searchable
allowDeselect={false}
aria-label={`Group by ${slo.groupBy}`}
data={data}
value={group != null ? `${GROUP_PREFIX}${group}` : ALL_GROUPS}
onChange={value =>
onChange(
value?.startsWith(GROUP_PREFIX)
? value.slice(GROUP_PREFIX.length)
: null,
)
}
data-testid="slo-group-select"
/>
);
}
Loading
Loading