diff --git a/packages/app/src/components/alerts/AlertPropertiesSummary.tsx b/packages/app/src/components/alerts/AlertPropertiesSummary.tsx
index 233b082eb..6a0ed016f 100644
--- a/packages/app/src/components/alerts/AlertPropertiesSummary.tsx
+++ b/packages/app/src/components/alerts/AlertPropertiesSummary.tsx
@@ -1,5 +1,10 @@
import * as React from 'react';
import {
+ describeSloAlertRule,
+ getSloAlertRuleLabel,
+} from '@hyperdx/common-utils/dist/slo';
+import {
+ AlertSource,
isRangeThresholdType,
WebhookService,
} from '@hyperdx/common-utils/dist/types';
@@ -180,12 +185,22 @@ export function AlertPropertiesSummary({
return (
- If value {thresholdLabel}{' '}
- {alert.threshold}
- {isRangeThresholdType(alert.thresholdType) && (
+ {alert.source === AlertSource.SLO ? (
+ // Its value only says how close the SLO's burn rule is to holding.
+ <>
+ {getSloAlertRuleLabel(alert.sloRule ?? 'fastBurn')}: if{' '}
+ {describeSloAlertRule(alert.sloRule ?? 'fastBurn')}
+ >
+ ) : (
<>
- {' '}
- and {alert.thresholdMax ?? '-'}
+ If value {thresholdLabel}{' '}
+ {alert.threshold}
+ {isRangeThresholdType(alert.thresholdType) && (
+ <>
+ {' '}
+ and {alert.thresholdMax ?? '-'}
+ >
+ )}
>
)}
diff --git a/packages/app/src/components/alerts/AlertRowMenu.tsx b/packages/app/src/components/alerts/AlertRowMenu.tsx
index f18ae76bf..1b48e04e7 100644
--- a/packages/app/src/components/alerts/AlertRowMenu.tsx
+++ b/packages/app/src/components/alerts/AlertRowMenu.tsx
@@ -1,6 +1,7 @@
import * as React from 'react';
import Link from 'next/link';
import { isImportableAlert } from '@hyperdx/common-utils/dist/iac';
+import { getSloAlertRuleLabel } from '@hyperdx/common-utils/dist/slo';
import { AlertSource } from '@hyperdx/common-utils/dist/types';
import { ActionIcon, Menu, Modal } from '@mantine/core';
import { notifications } from '@mantine/notifications';
@@ -19,7 +20,7 @@ import { EditAlertModal } from '@/components/alerts/EditAlertModal';
import { EditInlineAlertModal } from '@/components/alerts/EditInlineAlertModal';
import { TerraformHelperPanel } from '@/components/Iac/TerraformHelperPanel';
import { useTerraformSnippets } from '@/components/Iac/useTerraformSnippets';
-import { IS_IAC_EXPORT_ENABLED } from '@/config';
+import { IS_IAC_EXPORT_ENABLED, IS_SLOS_ENABLED } from '@/config';
import type { AlertsPageItem } from '@/types';
import { useConfirm } from '@/useConfirm';
import { intervalToDateRange } from '@/utils/alerts';
@@ -65,7 +66,20 @@ export function AlertRowMenu({
// `||`, not `??`: the empty string these arrive as for an unresolvable
// source is not nullish, and would read as "Open " and "Delete ?".
const name = alertName?.trim() || 'this alert';
- const sourceLabel = linkTitle?.trim().toLowerCase() || 'source';
+ // An SLO owns its alert: it is edited from the SLO, and deleting it here
+ // turns the alert off on the SLO. With SLOs turned off there is no SLO
+ // page to edit it on.
+ const isSloAlert = alert.source === AlertSource.SLO;
+ const sloManaged = isSloAlert && IS_SLOS_ENABLED;
+ // The alert carries its SLO's name, so "Delete {name}?" would read as
+ // deleting the SLO.
+ const deleteMessage = isSloAlert
+ ? `Delete the ${getSloAlertRuleLabel(alert.sloRule ?? 'fastBurn').toLowerCase()} alert of ${alertName?.trim() || 'this SLO'}? The SLO keeps tracking.`
+ : `Delete ${name}?`;
+ // "SLO" is an acronym, so it keeps its case mid-sentence.
+ const sourceLabel = isSloAlert
+ ? 'SLO'
+ : linkTitle?.trim().toLowerCase() || 'source';
const [terraformOpened, setTerraformOpened] = React.useState(false);
const [editOpened, setEditOpened] = React.useState(false);
const confirm = useConfirm();
@@ -120,7 +134,7 @@ export function AlertRowMenu({
});
const onDelete = React.useCallback(async () => {
- const confirmed = await confirm(`Delete ${name}?`, 'Delete', {
+ const confirmed = await confirm(deleteMessage, 'Delete', {
variant: 'danger',
});
if (!confirmed) {
@@ -134,10 +148,11 @@ export function AlertRowMenu({
autoClose: 5000,
});
// The alerts list and the source-bound edit surfaces (saved search
- // modal / dashboard tile editor) all render this alert.
+ // modal / dashboard tile editor / SLO pages) all render this alert.
queryClient.invalidateQueries({ queryKey: api.getAlertsQueryKey() });
queryClient.invalidateQueries({ queryKey: ['saved-search'] });
queryClient.invalidateQueries({ queryKey: ['dashboards'] });
+ queryClient.invalidateQueries({ queryKey: ['slos'] });
onDeleted?.();
} catch (error) {
console.error('Failed to delete alert:', error);
@@ -152,7 +167,7 @@ export function AlertRowMenu({
brandName,
confirm,
deleteAlert,
- name,
+ deleteMessage,
onDeleted,
queryClient,
]);
@@ -171,13 +186,26 @@ export function AlertRowMenu({
- }
- onClick={() => setEditOpened(true)}
- data-testid={`alert-edit-${alert._id}`}
- >
- Edit alert
-
+ {sloManaged ? (
+ }
+ data-testid={`alert-edit-${alert._id}`}
+ >
+ Edit in SLO
+
+ ) : (
+ !isSloAlert && (
+ }
+ onClick={() => setEditOpened(true)}
+ data-testid={`alert-edit-${alert._id}`}
+ >
+ Edit alert
+
+ )
+ )}
{alertUrl && (
{
});
});
});
+
+describe('AlertPropertiesSummary condition', () => {
+ it('states the threshold of a threshold alert', () => {
+ renderWithMantine();
+
+ expect(screen.getByText(/If value/).textContent).toBe(
+ 'If value is at least (≥) 3',
+ );
+ });
+
+ // An SLO alert's threshold is 1 on a value that is not a burn rate, so the
+ // row states the SLO's burn rule instead.
+ it("states an SLO alert's burn rule", () => {
+ renderWithMantine(
+ ,
+ );
+
+ expect(
+ screen.getByText(
+ 'Slow burn: if 5% of the error budget is spent within 6 hours',
+ ),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/packages/app/src/components/alerts/__tests__/AlertRowMenu.test.tsx b/packages/app/src/components/alerts/__tests__/AlertRowMenu.test.tsx
index 462008c63..b0f0f21f9 100644
--- a/packages/app/src/components/alerts/__tests__/AlertRowMenu.test.tsx
+++ b/packages/app/src/components/alerts/__tests__/AlertRowMenu.test.tsx
@@ -24,10 +24,25 @@ jest.mock('@/api', () => ({
},
}));
-jest.mock('@/config', () => ({
- IS_IAC_EXPORT_ENABLED: true,
- BASE_PATH: '',
-}));
+// The flag lives in the factory: modules read it while the imports load,
+// before anything declared in this file exists.
+jest.mock('@/config', () => {
+ const flags = { slos: true };
+ return {
+ IS_IAC_EXPORT_ENABLED: true,
+ BASE_PATH: '',
+ get IS_SLOS_ENABLED() {
+ return flags.slos;
+ },
+ setSlosEnabled: (enabled: boolean) => {
+ flags.slos = enabled;
+ },
+ };
+});
+const setSlosEnabled = (enabled: boolean) =>
+ jest
+ .requireMock<{ setSlosEnabled: (enabled: boolean) => void }>('@/config')
+ .setSlosEnabled(enabled);
// The edit modal pulls in the whole alert form (queries, editors, target
// picker); this suite is about the menu, so stub it down to an open/closed
@@ -94,6 +109,14 @@ const unaddressableTileAlert: AlertsPageItem = {
unaddressableTile: true,
};
+const sloAlert: AlertsPageItem = {
+ ...savedSearchAlert,
+ _id: 'alert-5',
+ source: AlertSource.SLO,
+ savedSearchId: undefined,
+ sloId: 'slo-1',
+};
+
function renderMenu(ui: React.ReactElement) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
@@ -156,6 +179,57 @@ describe('AlertRowMenu', () => {
expect(screen.queryByTestId('edit-alert-modal')).not.toBeInTheDocument();
});
+ // An SLO owns its alert: edits go to the SLO.
+ it('sends an SLO alert to its SLO for edits', async () => {
+ renderMenu(
+ ,
+ );
+ await openMenu('alert-row-menu-alert-5');
+
+ expect(screen.getByTestId('alert-edit-alert-5')).toHaveAttribute(
+ 'href',
+ '/slos/slo-1/edit#alerts',
+ );
+ expect(screen.getByText('Open SLO')).toBeInTheDocument();
+ expect(
+ screen.queryByTestId('terraform-menu-item-alert-5'),
+ ).not.toBeInTheDocument();
+ });
+
+ // The alert carries its SLO's name, so the generic "Delete {name}?" would
+ // read as deleting the SLO itself.
+ it('says the SLO stays when its alert is deleted', async () => {
+ renderMenu(
+ ,
+ );
+ await openMenu('alert-row-menu-alert-5');
+ await userEvent.click(screen.getByTestId('alert-delete-alert-5'));
+
+ expect(confirm).toHaveBeenCalledWith(
+ 'Delete the fast burn alert of Checkout availability? The SLO keeps tracking.',
+ 'Delete',
+ expect.objectContaining({ variant: 'danger' }),
+ );
+ expect(mutateAsync).toHaveBeenCalledWith('alert-5');
+ });
+
+ // With SLOs turned off there is no SLO page to edit it on, but it can still
+ // be deleted.
+ it('offers only delete for an SLO alert while SLOs are turned off', async () => {
+ setSlosEnabled(false);
+ try {
+ renderMenu();
+ await openMenu('alert-row-menu-alert-5');
+
+ expect(screen.getByTestId('alert-delete-alert-5')).toBeInTheDocument();
+ expect(
+ screen.queryByTestId('alert-edit-alert-5'),
+ ).not.toBeInTheDocument();
+ } finally {
+ setSlosEnabled(true);
+ }
+ });
+
it('offers Terraform export for a saved-search alert', async () => {
renderMenu();
await openMenu('alert-row-menu-alert-1');
diff --git a/packages/app/src/utils/__tests__/alerts.test.ts b/packages/app/src/utils/__tests__/alerts.test.ts
index efee2c398..de03a8094 100644
--- a/packages/app/src/utils/__tests__/alerts.test.ts
+++ b/packages/app/src/utils/__tests__/alerts.test.ts
@@ -183,6 +183,7 @@ describe('getAlertSourceLabel', () => {
'Dashboard tile',
);
expect(getAlertSourceLabel({ source: AlertSource.INLINE })).toBe('Chart');
+ expect(getAlertSourceLabel({ source: AlertSource.SLO })).toBe('SLO');
});
// The row's tooltip, the alerts-page filter and free-text search all read
@@ -293,6 +294,18 @@ describe('getAlertSourceUrl', () => {
).toBe('/chart?alertId=alert-1');
expect(getAlertSourceUrl(inlineAlert())).toBe('/chart?alertId=alert-1');
});
+
+ // The SLO is where its alert's state, history and settings live.
+ it('links an SLO alert to its SLO', () => {
+ expect(
+ getAlertSourceUrl(
+ inlineAlert({ source: AlertSource.SLO, sloId: 'slo-1' }),
+ ),
+ ).toBe('/slos/slo-1');
+ expect(getAlertSourceUrl(inlineAlert({ source: AlertSource.SLO }))).toBe(
+ '',
+ );
+ });
});
describe('buildInlineAlertPayload', () => {
diff --git a/packages/app/src/utils/alerts.ts b/packages/app/src/utils/alerts.ts
index ca3543325..16bf0b83e 100644
--- a/packages/app/src/utils/alerts.ts
+++ b/packages/app/src/utils/alerts.ts
@@ -21,6 +21,7 @@ import {
SavedChartConfig,
} from '@hyperdx/common-utils/dist/types';
+import { IS_SLOS_ENABLED } from '@/config';
import type { AlertsPageItem } from '@/types';
export function intervalToGranularity(interval: AlertInterval) {
@@ -261,6 +262,8 @@ export function getAlertSourceLabel(alert: {
return 'Saved search';
case AlertSource.INLINE:
return 'Chart';
+ case AlertSource.SLO:
+ return 'SLO';
default:
return 'Unknown source';
}
@@ -289,9 +292,9 @@ export const ALERT_STATE_FILTER_OPTIONS = [
].map(state => ({ value: state, label: ALERT_STATE_LABELS[state] }));
/** Options for the alerts-page source filter. */
-export const ALERT_SOURCE_FILTER_OPTIONS = Object.values(AlertSource).map(
- source => ({ value: source, label: getAlertSourceLabel({ source }) }),
-);
+export const ALERT_SOURCE_FILTER_OPTIONS = Object.values(AlertSource)
+ .filter(source => source !== AlertSource.SLO || IS_SLOS_ENABLED)
+ .map(source => ({ value: source, label: getAlertSourceLabel({ source }) }));
/**
* The name the server would derive if the alert had none of its own. Only for
@@ -337,6 +340,9 @@ export function getAlertSourceUrl(alert: AlertsPageItem): string {
if (alert.source === AlertSource.INLINE) {
return `/chart?alertId=${alert._id}`;
}
+ if (alert.source === AlertSource.SLO && alert.sloId) {
+ return `/slos/${alert.sloId}`;
+ }
return '';
}
diff --git a/packages/common-utils/src/types.ts b/packages/common-utils/src/types.ts
index 03bc2cffa..bdf3c6d98 100644
--- a/packages/common-utils/src/types.ts
+++ b/packages/common-utils/src/types.ts
@@ -828,6 +828,8 @@ export enum AlertSource {
* instead of referencing a saved search or tile.
*/
INLINE = 'inline',
+ /** Burn-rate alert owned by an SLO; managed only through the SLO. */
+ SLO = 'slo',
}
export const AlertIntervalSchema = z.union([
@@ -3206,6 +3208,10 @@ export const AlertsPageItemSchema = z.object({
dashboardId: z.string().optional(),
savedSearchId: z.string().optional(),
tileId: z.string().optional(),
+ // SLO alerts only: the SLO that owns the alert and is the place to change
+ // it, and which of its burn alerts this is ('fastBurn' or 'slowBurn').
+ sloId: z.string().optional(),
+ sloRule: z.enum(['fastBurn', 'slowBurn']).optional(),
// Tile alerts only: set when the tile this alert watches cannot be
// addressed in generated Terraform, so the row's export action is withheld.
// Server-computed — `dashboard.tiles` below carries only this alert's own