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
86 changes: 86 additions & 0 deletions packages/app/src/components/Slos/SloListToolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Group, MultiSelect, Select, TextInput } from '@mantine/core';
import { IconSearch } from '@tabler/icons-react';

import {
DEFAULT_SLO_SORT,
isSloSort,
SLO_SORT_OPTIONS,
type SloSort,
} from './sloListSort';

/** Search, tag and source filters and the sort of the SLO list. */
export function SloListToolbar({
search,
onSearchChange,
tags,
tagFilter,
onTagFilterChange,
sources,
sourceFilter,
onSourceFilterChange,
sort,
onSortChange,
}: {
search: string;
onSearchChange: (search: string) => void;
/** The tags the team's SLOs carry. */
tags: string[];
tagFilter: string[];
onTagFilterChange: (tags: string[]) => void;
/** The sources the team's SLOs are defined on. */
sources: { value: string; label: string }[];
sourceFilter: string | null;
onSourceFilterChange: (source: string | null) => void;
sort: SloSort;
onSortChange: (sort: SloSort) => void;
}) {
return (
<Group gap="xs" mb="md">
<TextInput
placeholder="Search by name, description or tag"
leftSection={<IconSearch size={14} />}
value={search}
onChange={e => onSearchChange(e.currentTarget.value)}
w={320}
data-testid="slo-search"
/>
{/* Stay while a filter is set, so a stale link can still be cleared. */}
{(tags.length > 0 || tagFilter.length > 0) && (
<MultiSelect
aria-label="Filter by tag"
placeholder={tagFilter.length > 0 ? undefined : 'All tags'}
data={[...new Set([...tags, ...tagFilter])]}
value={tagFilter}
onChange={onTagFilterChange}
searchable
clearable
w={220}
data-testid="slo-tag-filter"
/>
)}
{(sources.length > 1 || sourceFilter != null) && (
<Select
aria-label="Filter by source"
placeholder="All sources"
data={sources}
value={sourceFilter}
onChange={onSourceFilterChange}
clearable
w={200}
data-testid="slo-source-filter"
/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — A source filter that is not in the options shows "All sources" while hiding every row

Unlike the tag MultiSelect, which merges tagFilter into data, the source Select only lists sources. If ?source= holds an id no SLO uses (an old link, or you just deleted the last SLO on that source), the Select falls back to the "All sources" placeholder but the list is still filtered to nothing. Add the current sourceFilter to data when it is missing (for example with an 'Unknown source' label), the same way the tag filter handles stale values.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

)}
<Select
aria-label="Sort by"
data={SLO_SORT_OPTIONS.map(o => ({ ...o }))}
value={sort}
onChange={value =>
onSortChange(isSloSort(value) ? value : DEFAULT_SLO_SORT)
}
allowDeselect={false}
w={180}
data-testid="slo-sort"
/>
</Group>
);
}
65 changes: 65 additions & 0 deletions packages/app/src/components/Slos/SloRowMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo';
import { ActionIcon, Menu } from '@mantine/core';
import { notifications } from '@mantine/notifications';
import { IconDots, IconTrash } from '@tabler/icons-react';

import { useDeleteSlo } from '@/slo';
import { useConfirm } from '@/useConfirm';
import { getApiErrorMessage } from '@/utils/apiErrors';

export function SloRowMenu({ slo }: { slo: SloApiResponse }) {
const confirm = useConfirm();
const deleteSlo = useDeleteSlo();

const handleDelete = async () => {
if (
!(await confirm(
<>
Delete <b>{slo.name}</b>?
{slo.alerts.fastBurn || slo.alerts.slowBurn
? ' Its burn alerts are deleted too.'
: ''}{' '}
This is <b>not reversible</b>.
</>,
'Delete',
{ variant: 'danger' },
))
) {
return;
}
try {
await deleteSlo.mutateAsync(slo.id);
notifications.show({ color: 'green', message: `Deleted ${slo.name}` });
} catch (e) {
notifications.show({
color: 'red',
message: await getApiErrorMessage(e, 'Could not delete the SLO'),
});
}
};

return (
<Menu position="bottom-end" withinPortal>
<Menu.Target>
<ActionIcon
variant="subtle"
aria-label={`Actions for ${slo.name}`}
data-testid={`slo-row-menu-${slo.id}`}
onClick={e => e.stopPropagation()}
>
<IconDots size={16} />
</ActionIcon>
</Menu.Target>
<Menu.Dropdown onClick={e => e.stopPropagation()}>
<Menu.Item
color="red"
leftSection={<IconTrash size={14} />}
onClick={handleDelete}
data-testid="slo-delete"
>
Delete
</Menu.Item>
</Menu.Dropdown>
</Menu>
);
}
5 changes: 5 additions & 0 deletions packages/app/src/components/Slos/SloTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Group, Stack, Table, Text, Tooltip } from '@mantine/core';

import { useSources } from '@/source';

import { SloRowMenu } from './SloRowMenu';
import { SloStateBadge } from './SloStateBadge';
import {
budgetColorVar,
Expand Down Expand Up @@ -114,6 +115,9 @@ function SloRow({
</Text>
</Text>
</Table.Td>
<Table.Td>
<SloRowMenu slo={slo} />
</Table.Td>
</Table.Tr>
);
}
Expand Down Expand Up @@ -141,6 +145,7 @@ export function SloTable({ slos }: { slos: SloApiResponse[] }) {
help="How fast the budget is being spent: 1x spends it exactly over the window."
/>
<Table.Th>Target</Table.Th>
<Table.Th w={48} />
</Table.Tr>
</Table.Thead>
<Table.Tbody>
Expand Down
84 changes: 74 additions & 10 deletions packages/app/src/components/Slos/SlosListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useMemo } from 'react';
import Head from 'next/head';
import { parseAsStringEnum, useQueryState } from 'nuqs';
import { compareSlosWorstFirst } from '@hyperdx/common-utils/dist/core/sloStats';
import {
parseAsArrayOf,
parseAsString,
parseAsStringEnum,
useQueryState,
} from 'nuqs';
import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo';
import {
Alert,
Button,
Expand All @@ -18,7 +23,15 @@ import EmptyState from '@/components/EmptyState';
import { PageHeader } from '@/components/PageHeader';
import { withAppNavForSurface } from '@/layout';
import { useSlos, useSlosEnabledGuard } from '@/slo';
import { useSources } from '@/source';

import {
compareSlos,
DEFAULT_SLO_SORT,
SLO_SORT_VALUES,
type SloSort,
} from './sloListSort';
import { SloListToolbar } from './SloListToolbar';
import { SloTable } from './SloTable';
import {
getSloDisplayState,
Expand All @@ -27,24 +40,61 @@ import {
sloStateLabel,
} from './sloUtils';

function matchesSearch(slo: SloApiResponse, term: string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Search joins all the fields into one string, so a term can match across field boundaries

[name, description, ...tags].join(' ').includes(term) matches a term like 'api prod' when the name ends in 'api' and a tag is 'prod', which no single field contains. Test each field on its own ([name, description, ...tags].some(f => f.toLowerCase().includes(q))), as filterAndSortDashboards in components/Dashboards/dashboardsListUtils.ts:89 does.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

return [slo.name, slo.description ?? '', ...slo.tags]
.join(' ')
.toLowerCase()
.includes(term.toLowerCase());
}

export default function SlosListPage() {
const enabled = useSlosEnabledGuard();
const title = usePageTitle('SLOs');
const { data: slos, isPending, isError, refetch } = useSlos();

const { data: allSources } = useSources();
const [search, setSearch] = useQueryState('search');
const [stateFilter, setStateFilter] = useQueryState(
'state',
parseAsStringEnum<SloDisplayState>(SLO_DISPLAY_STATES),
);

// Worst first, so what needs attention is on top.
const filtered = useMemo(
() =>
(slos ?? [])
.filter(slo => !stateFilter || getSloDisplayState(slo) === stateFilter)
.sort(compareSlosWorstFirst),
[slos, stateFilter],
const [tagFilter, setTagFilter] = useQueryState(
'tag',
parseAsArrayOf(parseAsString).withDefault([]),
);
const [sourceFilter, setSourceFilter] = useQueryState('source');
// Worst first by default, so what needs attention is on top.
const [sort, setSort] = useQueryState(
'sort',
parseAsStringEnum<SloSort>(SLO_SORT_VALUES).withDefault(DEFAULT_SLO_SORT),
);

const filtered = useMemo(() => {
const term = search?.trim() ?? '';
const tags = tagFilter.map(tag => tag.toLowerCase());
return (slos ?? [])
.filter(
slo =>
(!term || matchesSearch(slo, term)) &&
(!stateFilter || getSloDisplayState(slo) === stateFilter) &&
// Every tag picked, as the dashboards list filters.
tags.every(tag => slo.tags.some(t => t.toLowerCase() === tag)) &&
(!sourceFilter || slo.source === sourceFilter),
)
.sort(compareSlos(sort));
}, [slos, search, stateFilter, tagFilter, sourceFilter, sort]);

// The tags and sources the team's SLOs use, to filter by.
const { tagOptions, sourceOptions } = useMemo(() => {
const sourceIds = [...new Set((slos ?? []).map(slo => slo.source))];
return {
tagOptions: [...new Set((slos ?? []).flatMap(slo => slo.tags))].sort(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Tag options are deduped case-sensitively, but the filter matches tags case-insensitively

new Set(slos.flatMap(slo => slo.tags)) lists 'Prod' and 'prod' as two options, yet picking either one matches both because the filter lowercases. The dashboards list deals with this by collapsing case variants into one option (see the comment in components/Dashboards/dashboardsListUtils.ts:78). Dedupe the options by toLowerCase() here too.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

sourceOptions: sourceIds.map(id => ({
value: id,
label: allSources?.find(s => s.id === id)?.name ?? 'Unknown source',
})),
};
}, [slos, allSources]);

const counts = useMemo(() => {
const result = new Map<SloDisplayState, number>();
Expand Down Expand Up @@ -96,6 +146,20 @@ export default function SlosListPage() {
</Button>
))}
</Group>
<SloListToolbar
search={search ?? ''}
onSearchChange={value => setSearch(value || null)}
tags={tagOptions}
tagFilter={tagFilter}
onTagFilterChange={value =>
setTagFilter(value.length > 0 ? value : null)
}
sources={sourceOptions}
sourceFilter={sourceFilter}
onSourceFilterChange={setSourceFilter}
sort={sort}
onSortChange={setSort}
/>
{isPending ? (
<Skeleton h={200} />
) : isError ? (
Expand Down
77 changes: 77 additions & 0 deletions packages/app/src/components/Slos/__tests__/sloList.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo';

import { compareSlos } from '@/components/Slos/sloListSort';

/** An SLO with only what the sort reads; no status means no update yet. */
const slo = (
name: string,
status?: { sli: number; budgetRemaining: number; burnRate: number },
): SloApiResponse => ({
id: name,
version: 1,
name,
tags: [],
source: 'source-1',
indicator: {
template: 'availability',
eligible: { where: '', whereLanguage: 'sql' },
good: "StatusCode != 'Error'",
},
target: 99,
window: '7d',
alerts: {},
alertStates: {},
createdAt: '2026-11-01T00:00:00.000Z',
updatedAt: '2026-11-01T00:00:00.000Z',
status: status && {
eligible: 1000,
good: Math.round(status.sli * 1000),
bad: 1000 - Math.round(status.sli * 1000),
sli: status.sli,
errorBudget: 10,
budgetRemaining: status.budgetRemaining,
budgetRemainingEvents: 0,
burn: [
{
rule: 'fastBurn',
window: '1h',
shortWindow: '5m',
budgetSpent: 0.02,
minEvents: 20,
threshold: 3.36,
eligible: 100,
bad: 1,
burnRate: status.burnRate,
shortBurnRate: status.burnRate,
},
],
state: status.budgetRemaining <= 0 ? 'breached' : 'healthy',
evaluatedAt: '2026-11-01T00:00:00.000Z',
windowStart: '2026-10-25T00:00:00.000Z',
windowEnd: '2026-11-01T00:00:00.000Z',
durationMs: 0,
rowsRead: 0,
},
});

describe('SLO list sort', () => {
const slos = [
slo('b', { sli: 0.999, budgetRemaining: 0.9, burnRate: 0.5 }),
slo('pending'),
slo('a', { sli: 0.95, budgetRemaining: -1, burnRate: 30 }),
slo('c', { sli: 0.998, budgetRemaining: 0.4, burnRate: 4 }),
];
const sorted = (sort: Parameters<typeof compareSlos>[0]) =>
[...slos].sort(compareSlos(sort)).map(s => s.name);

it('puts SLOs without numbers last', () => {
expect(sorted('sli')).toEqual(['a', 'c', 'b', 'pending']);
expect(sorted('budget')).toEqual(['a', 'c', 'b', 'pending']);
expect(sorted('burn')).toEqual(['a', 'c', 'b', 'pending']);
});

it('sorts by name, or worst first', () => {
expect(sorted('name')).toEqual(['a', 'b', 'c', 'pending']);
expect(sorted('worst')[0]).toBe('a');
});
});
Loading
Loading