From 044921c04eebe96b875d263479a25c51d5c10870 Mon Sep 17 00:00:00 2001 From: Alex Fedotyev <61838744+alex-fedotyev@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:46:00 +0000 Subject: [PATCH] feat(app): SLO objective, details and editing in the builder Adds the objective section to the SLO builder (a target with presets for 99%, 99.5%, 99.9% and 99.95%, the error budget it leaves, and a rolling 7 or 30 day window) and a details section with a description and tags. SLOs can now be edited at /slos//edit, from the list's row menu: the form loads the saved definition and keeps what the builder does not show, such as a group-by, alerts and eligible-event filters, as saved. Co-Authored-By: Claude Opus 5.5 --- packages/app/pages/slos/[sloId]/edit.tsx | 3 + .../components/Slos/SloDefinitionFields.tsx | 144 +++++++++++++++++- .../app/src/components/Slos/SloEditorPage.tsx | 58 +++++-- .../app/src/components/Slos/SloRowMenu.tsx | 11 +- .../components/Slos/__tests__/sloForm.test.ts | 46 ++++++ packages/app/src/components/Slos/sloForm.ts | 24 +++ packages/app/src/components/Slos/sloUtils.ts | 10 +- packages/app/src/slo.ts | 12 ++ 8 files changed, 296 insertions(+), 12 deletions(-) create mode 100644 packages/app/pages/slos/[sloId]/edit.tsx diff --git a/packages/app/pages/slos/[sloId]/edit.tsx b/packages/app/pages/slos/[sloId]/edit.tsx new file mode 100644 index 000000000..c21f7658e --- /dev/null +++ b/packages/app/pages/slos/[sloId]/edit.tsx @@ -0,0 +1,3 @@ +import SloEditorPage from '@/components/Slos/SloEditorPage'; + +export default SloEditorPage; diff --git a/packages/app/src/components/Slos/SloDefinitionFields.tsx b/packages/app/src/components/Slos/SloDefinitionFields.tsx index 5a34738c8..e2effd953 100644 --- a/packages/app/src/components/Slos/SloDefinitionFields.tsx +++ b/packages/app/src/components/Slos/SloDefinitionFields.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef } from 'react'; import { type Control, + Controller, type UseFormGetValues, type UseFormSetValue, useFormState, @@ -8,8 +9,18 @@ import { } from 'react-hook-form'; import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata'; import { buildSloAvailabilityCondition } from '@hyperdx/common-utils/dist/core/slo'; +import { SloWindowSchema } from '@hyperdx/common-utils/dist/slo'; import { SourceKind, type TSource } from '@hyperdx/common-utils/dist/types'; -import { Input } from '@mantine/core'; +import { + Button, + Group, + Input, + NumberInput, + Radio, + TagsInput, + Text, + Textarea, +} from '@mantine/core'; import SearchWhereInput from '@/components/SearchInput/SearchWhereInput'; import { SourceSelectControlled } from '@/components/SourceSelect'; @@ -17,8 +28,10 @@ import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEdito import type { SloFormValues } from './sloForm'; import { SloFormRow } from './SloFormLayout'; +import { formatSloWindow } from './sloUtils'; const SLO_SOURCE_KINDS = [SourceKind.Trace, SourceKind.Log]; +const TARGET_PRESETS = [99, 99.5, 99.9, 99.95]; /** Which events count, and which of them are good. */ export function SloIndicatorFields({ @@ -97,3 +110,132 @@ export function SloIndicatorFields({ ); } + +/** The target and the rolling window it applies to. */ +export function SloObjectiveFields({ + control, + setValue, +}: { + control: Control; + setValue: UseFormSetValue; +}) { + const [target, sloWindow] = useWatch({ + control, + name: ['target', 'window'], + }); + return ( + <> + + + ( + field.onChange(typeof v === 'number' ? v : 0)} + error={fieldState.error?.message} + w={120} + data-testid="slo-target" + /> + )} + /> + {TARGET_PRESETS.map(t => ( + + ))} + + + Error budget: {Number((100 - (target ?? 0)).toFixed(3))}% of eligible + events may be bad over {formatSloWindow(sloWindow)}. + + + + ( + { + const next = SloWindowSchema.safeParse(value); + if (next.success) field.onChange(next.data); + }} + aria-label="Window" + data-testid="slo-window" + > + + {SloWindowSchema.options.map(w => ( + + ))} + + + )} + /> + + + ); +} + +/** What the SLO is for, and tags to find it by. */ +export function SloDetailsFields({ + control, +}: { + control: Control; +}) { + return ( + <> + + ( +