mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-17 13:51:10 +00:00
Compare commits
1 Commits
feat/input
...
fix/alert-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd91657857 |
@@ -55,7 +55,7 @@ function ErrorInPlace({
|
||||
height,
|
||||
padding: typeof padding === 'number' ? `${padding}px` : padding,
|
||||
backgroundColor: background,
|
||||
border: bordered ? '1px solid var(--bg-slate-400, #374151)' : 'none',
|
||||
border: bordered ? '1px solid var(--l1-border)' : 'none',
|
||||
borderRadius: bordered ? '4px' : '0',
|
||||
overflow: 'auto',
|
||||
...style,
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--l1-border);
|
||||
box-shadow: none;
|
||||
color: var(--l2-foreground);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ function ErrorModal({
|
||||
onClick={handleClose}
|
||||
data-testid="close-button"
|
||||
>
|
||||
<X size={16} color={Color.BG_VANILLA_400} />
|
||||
<X size={16} />
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -176,6 +176,10 @@
|
||||
0px 4px 9px 0px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
&__scroll-hint-icon {
|
||||
color: var(--l1-foreground);
|
||||
}
|
||||
|
||||
&__scroll-hint-text {
|
||||
color: var(--l1-foreground);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import { Button } from 'antd';
|
||||
import ErrorIcon from 'assets/Error';
|
||||
import OverlayScrollbar from 'components/OverlayScrollbar/OverlayScrollbar';
|
||||
@@ -93,11 +92,7 @@ function ErrorContent({ error, icon }: ErrorContentProps): JSX.Element {
|
||||
</OverlayScrollbar>
|
||||
{errorMessages?.length > 10 && (
|
||||
<div className="error-content__scroll-hint">
|
||||
<ChevronsDown
|
||||
size={16}
|
||||
color={Color.BG_VANILLA_100}
|
||||
className="error-content__scroll-hint-icon"
|
||||
/>
|
||||
<ChevronsDown size={16} className="error-content__scroll-hint-icon" />
|
||||
<span className="error-content__scroll-hint-text">Scroll for more</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
background-color: var(--card);
|
||||
}
|
||||
|
||||
.previewMessage {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.chartCardBody {
|
||||
height: 57vh;
|
||||
padding: var(--spacing-12) 0;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { RuletypesRuleTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { useAppLocation } from 'lib/router/useAppLocation';
|
||||
import ErrorInPlace from 'components/ErrorInPlace/ErrorInPlace';
|
||||
import { RotateCw, TriangleAlert } from '@signozhq/icons';
|
||||
import QueryCancelledPlaceholder from 'components/QueryCancelledPlaceholder';
|
||||
import Spinner from 'components/Spinner';
|
||||
import WarningPopover from 'components/WarningPopover/WarningPopover';
|
||||
@@ -33,12 +33,13 @@ import { navigate } from 'lib/router/navigation';
|
||||
import { LegendPosition } from 'lib/uPlotV2/components/types';
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import { useIsAnomalyDetectionAvailable } from 'container/CreateAlert/useIsAnomalyDetectionAvailable';
|
||||
import PanelMessage from 'pages/DashboardPage/DashboardContainer/Panels/components/PanelMessage/PanelMessage';
|
||||
import PanelStatusPopover from 'pages/DashboardPage/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelStatus/PanelStatusPopover';
|
||||
import { useTimezone } from 'providers/Timezone';
|
||||
import { UpdateTimeInterval } from 'store/actions';
|
||||
import { AppState } from 'store/reducers';
|
||||
import { Warning } from 'types/api';
|
||||
import { AlertDef } from 'types/api/alerts/def';
|
||||
import APIError from 'types/api/error';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||
@@ -47,7 +48,7 @@ import { getSortedSeriesData } from 'utils/getSortedSeriesData';
|
||||
import { getTimeRange } from 'utils/getTimeRange';
|
||||
|
||||
import ChartContent from './ChartContent';
|
||||
import { getThresholds } from './utils';
|
||||
import { getPreviewErrorDetail, getThresholds } from './utils';
|
||||
|
||||
import styles from './ChartPreview.module.scss';
|
||||
import './ChartPreview.styles.scss';
|
||||
@@ -290,6 +291,11 @@ function ChartPreview({
|
||||
|
||||
const isWarning = !isEmpty(queryResponse.data?.warning);
|
||||
|
||||
const errorDetail = useMemo(
|
||||
() => (isCancelled ? null : getPreviewErrorDetail(queryResponse.error)),
|
||||
[isCancelled, queryResponse.error],
|
||||
);
|
||||
|
||||
const chartWidth = containerDimensions?.width
|
||||
? containerDimensions.width - CHART_PREVIEW_CONTAINER_PADDING
|
||||
: 0;
|
||||
@@ -303,6 +309,13 @@ function ChartPreview({
|
||||
<div className={styles.chartCardBody}>
|
||||
<div className="chart-preview-header">
|
||||
{headline}
|
||||
{errorDetail && (
|
||||
<PanelStatusPopover
|
||||
variant="error"
|
||||
detail={errorDetail}
|
||||
testId="alert-preview-error-status"
|
||||
/>
|
||||
)}
|
||||
{isWarning && (
|
||||
<WarningPopover warningData={queryResponse.data?.warning as Warning} />
|
||||
)}
|
||||
@@ -312,8 +325,23 @@ function ChartPreview({
|
||||
{queryResponse.isLoading && (
|
||||
<Spinner size="large" tip="Loading..." height="100%" />
|
||||
)}
|
||||
{(queryResponse?.isError || queryResponse?.error) && !isCancelled && (
|
||||
<ErrorInPlace error={queryResponse.error as APIError} />
|
||||
{errorDetail && (
|
||||
<div className={styles.previewMessage}>
|
||||
<PanelMessage
|
||||
icon={<TriangleAlert size={18} />}
|
||||
tone="danger"
|
||||
title="Couldn’t load preview data"
|
||||
description={errorDetail.message}
|
||||
action={{
|
||||
label: 'Retry',
|
||||
onClick: (): void => {
|
||||
void queryResponse.refetch();
|
||||
},
|
||||
icon: <RotateCw size={14} />,
|
||||
}}
|
||||
data-testid="alert-preview-error"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isCancelled && !queryResponse.isLoading && !hasResultData && (
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { DataFormats } from 'constants/formats/types';
|
||||
|
||||
import { covertIntoDataFormats } from './utils';
|
||||
import APIError from 'types/api/error';
|
||||
|
||||
import { covertIntoDataFormats, getPreviewErrorDetail } from './utils';
|
||||
|
||||
describe('Convert One Unit to another unit', () => {
|
||||
it('should convert from BitsIEC to BytesIEC', () => {
|
||||
@@ -103,3 +105,44 @@ describe('Convert One Unit to another unit', () => {
|
||||
expect(result).toBe(-1024);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPreviewErrorDetail', () => {
|
||||
it('returns null without an error', () => {
|
||||
expect(getPreviewErrorDetail(null)).toBeNull();
|
||||
});
|
||||
|
||||
it('maps an API error to the panel status shape', () => {
|
||||
const error = new APIError({
|
||||
httpStatusCode: 400,
|
||||
error: {
|
||||
code: 'invalid_input',
|
||||
message: 'Found 1 syntax errors while parsing the search expression.',
|
||||
url: 'https://signoz.io/docs',
|
||||
errors: [{ message: "line 1:21 expecting one of {'(', ')'}" }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(getPreviewErrorDetail(error)).toStrictEqual({
|
||||
code: 'invalid_input',
|
||||
message: 'Found 1 syntax errors while parsing the search expression.',
|
||||
docsUrl: 'https://signoz.io/docs',
|
||||
messages: ["line 1:21 expecting one of {'(', ')'}"],
|
||||
});
|
||||
});
|
||||
|
||||
it('drops an empty docs url', () => {
|
||||
const error = new APIError({
|
||||
httpStatusCode: 500,
|
||||
error: { code: 'internal', message: 'boom', url: '', errors: [] },
|
||||
});
|
||||
|
||||
expect(getPreviewErrorDetail(error)?.docsUrl).toBeUndefined();
|
||||
});
|
||||
|
||||
it('falls back to the message of a plain error', () => {
|
||||
expect(getPreviewErrorDetail(new Error('Network Error'))).toStrictEqual({
|
||||
message: 'Network Error',
|
||||
messages: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,7 +27,9 @@ import {
|
||||
import { UPlotConfigBuilder } from 'lib/uPlotV2/config/UPlotConfigBuilder';
|
||||
import { hasSingleVisiblePoint } from 'lib/uPlotV2/utils/dataUtils';
|
||||
import { get } from 'lodash-es';
|
||||
import APIError from 'types/api/error';
|
||||
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
|
||||
import type { PanelStatusDetail } from 'pages/DashboardPage/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelStatus/types';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
|
||||
import {
|
||||
@@ -269,3 +271,23 @@ export const buildAlertChartConfig = ({
|
||||
|
||||
export const buildChartId = (id?: string): string =>
|
||||
id ? `${CHART_ID_PREFIX}_${id}` : CHART_ID_PREFIX;
|
||||
|
||||
export const getPreviewErrorDetail = (
|
||||
error: APIError | Error | null | undefined,
|
||||
): PanelStatusDetail | null => {
|
||||
if (!error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(error instanceof APIError)) {
|
||||
return { message: error.message, messages: [] };
|
||||
}
|
||||
|
||||
const { code, message, url, errors } = error.getErrorDetails().error;
|
||||
return {
|
||||
code,
|
||||
message,
|
||||
docsUrl: url || undefined,
|
||||
messages: (errors ?? []).map((e) => e.message),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
import { rest } from 'msw';
|
||||
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { choiceControl, countControl } from '@/storybook/controls/controls';
|
||||
import { defineStoryMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import {
|
||||
alertRuleByIdResponse,
|
||||
@@ -25,7 +25,10 @@ import {
|
||||
alertFieldValuesResponse,
|
||||
alertMetricMetadataResponse,
|
||||
alertMetricsResponse,
|
||||
alertPreviewInvalidQueryError,
|
||||
alertPreviewSeries,
|
||||
PREVIEW_QUERY_CHOICES,
|
||||
type PreviewQueryChoice,
|
||||
} from '../../stories/__story_mockdata__/alertQuery';
|
||||
|
||||
const STORY_RULE_ID = 'rule-1';
|
||||
@@ -70,6 +73,13 @@ export const alertOverviewMocks = defineStoryMocks({
|
||||
value: 3,
|
||||
max: 6,
|
||||
}),
|
||||
previewQuery: choiceControl<PreviewQueryChoice>('Preview query', {
|
||||
group: PREVIEW,
|
||||
description:
|
||||
'`invalid` makes `query_range` answer with the 400 a filter that does not parse gets, so the preview shows its error.',
|
||||
options: PREVIEW_QUERY_CHOICES,
|
||||
value: 'valid',
|
||||
}),
|
||||
testNotification: choiceControl<TestNotification>('Test notification', {
|
||||
group: 'Alert overview · rule',
|
||||
description:
|
||||
@@ -120,9 +130,12 @@ export const alertOverviewMocks = defineStoryMocks({
|
||||
response.json(() => notificationChannelsResponse(values.channels)),
|
||||
),
|
||||
|
||||
rest.post(
|
||||
'http://localhost/api/v5/query_range',
|
||||
response.json(async (req) => alertPreviewSeries(values.previewSeries, req)),
|
||||
rest.post('http://localhost/api/v5/query_range', (req, res, ctx) =>
|
||||
values.previewQuery === 'invalid'
|
||||
? res(ctx.status(400), ctx.json(alertPreviewInvalidQueryError()))
|
||||
: response.json(async (request) =>
|
||||
alertPreviewSeries(values.previewSeries, request),
|
||||
)(req, res, ctx),
|
||||
),
|
||||
|
||||
rest.get(
|
||||
@@ -161,21 +174,9 @@ export const alertOverviewMocks = defineStoryMocks({
|
||||
}),
|
||||
});
|
||||
|
||||
export const clickFooterButton = async (
|
||||
canvasElement: HTMLElement,
|
||||
testId: string,
|
||||
): Promise<void> => {
|
||||
// The footer stays disabled, and remounts, until the rule has loaded.
|
||||
const button = await waitFor(
|
||||
() => {
|
||||
const element = within(canvasElement).getByTestId(testId);
|
||||
export type AlertOverviewArgs = PageStoryArgs<typeof alertOverviewMocks>;
|
||||
|
||||
expect(element).toBeEnabled();
|
||||
expect(element).not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
return element;
|
||||
},
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
await userEvent.click(button);
|
||||
};
|
||||
// The page renders nothing past the rule request, so a failed or pending rule
|
||||
// leaves no preview to fail.
|
||||
export const showsInvalidQueryError = (args: AlertOverviewArgs): boolean =>
|
||||
args.previewQuery === 'invalid' && args.dataState === 'loaded';
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import {
|
||||
alertOverviewMocks,
|
||||
clickFooterButton,
|
||||
type AlertOverviewArgs,
|
||||
} from './AlertOverview.stories.mocks';
|
||||
import {
|
||||
openAlertActionsMenu,
|
||||
openPreviewErrorDetails,
|
||||
pickAnomalySeries,
|
||||
saveAlertRule,
|
||||
sendTestNotification,
|
||||
} from './__story_mockdata__/alertOverview.play';
|
||||
|
||||
import AlertList from '../../index';
|
||||
|
||||
type AlertOverviewArgs = PageStoryArgs<typeof alertOverviewMocks>;
|
||||
|
||||
const pageStory = storyMocks(alertOverviewMocks, { layout: 'app' });
|
||||
|
||||
/**
|
||||
@@ -53,14 +56,7 @@ export const AnomalyRule: Story = {
|
||||
*/
|
||||
export const AnomalyRuleForecastBand: Story = {
|
||||
args: { ruleKind: 'anomaly' },
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const [firstSeries] = await within(canvasElement).findAllByTestId(
|
||||
'anomaly-series-option',
|
||||
undefined,
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
await userEvent.click(firstSeries);
|
||||
},
|
||||
play: pickAnomalySeries,
|
||||
};
|
||||
|
||||
/** A rule someone turned off: the toggle in the header is what turns it back on. */
|
||||
@@ -73,6 +69,22 @@ export const NoPreviewData: Story = {
|
||||
args: { previewSeries: 0 },
|
||||
};
|
||||
|
||||
/**
|
||||
* The rule's filter no longer parses: the preview says it could not load, with
|
||||
* a retry, and the error icon beside the title holds the server's message.
|
||||
*/
|
||||
export const PreviewQueryError: Story = {
|
||||
args: { previewQuery: 'invalid' },
|
||||
parameters: { allowConsoleErrors: true },
|
||||
};
|
||||
|
||||
/** The preview's error icon, hovered: the code, message, docs link and parser output. */
|
||||
export const PreviewQueryErrorDetails: Story = {
|
||||
args: { previewQuery: 'invalid' },
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: openPreviewErrorDetails,
|
||||
};
|
||||
|
||||
/** The rule id in the URL does not resolve, which is where the page gives up. */
|
||||
export const RuleNotFound: Story = {
|
||||
args: { dataState: 'error' },
|
||||
@@ -86,44 +98,21 @@ export const RuleNotFound: Story = {
|
||||
* it, or delete it.
|
||||
*/
|
||||
export const AlertActionsMenu: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByTestId(
|
||||
'alert-actions-menu',
|
||||
{},
|
||||
{ timeout: 10000 },
|
||||
),
|
||||
);
|
||||
await screen.findByRole('menu');
|
||||
},
|
||||
play: openAlertActionsMenu,
|
||||
};
|
||||
|
||||
/** The rule saved unchanged from the footer: the toast raised once the PUT answers. */
|
||||
export const AlertRuleUpdatedToast: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await clickFooterButton(canvasElement, 'save-alert-rule-button');
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/alert rule updated successfully/i)).toBeVisible(),
|
||||
);
|
||||
},
|
||||
play: saveAlertRule,
|
||||
};
|
||||
|
||||
/** Test Notification from the footer. */
|
||||
export const TestNotificationSentToast: Story = {
|
||||
play: async ({ canvasElement, args }): Promise<void> => {
|
||||
await clickFooterButton(canvasElement, 'test-notification-button');
|
||||
if (args.testNotification === 'sent') {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByText(/test notification sent successfully/i),
|
||||
).toBeVisible(),
|
||||
);
|
||||
}
|
||||
},
|
||||
play: sendTestNotification,
|
||||
};
|
||||
|
||||
/** Test Notification finding nothing to alert on: the error toast. */
|
||||
export const TestNotificationNoAlertsToast: Story = {
|
||||
args: { testNotification: 'no-alerts' },
|
||||
play: TestNotificationSentToast.play,
|
||||
play: sendTestNotification,
|
||||
};
|
||||
|
||||
101
frontend/src/pages/AlertList/AlertOverview/stories/__story_mockdata__/alertOverview.play.ts
generated
Normal file
101
frontend/src/pages/AlertList/AlertOverview/stories/__story_mockdata__/alertOverview.play.ts
generated
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import {
|
||||
type AlertOverviewArgs,
|
||||
showsInvalidQueryError,
|
||||
} from '../AlertOverview.stories.mocks';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
args: AlertOverviewArgs;
|
||||
}
|
||||
|
||||
const untilLoaded = { timeout: 15_000 };
|
||||
|
||||
const clickFooterButton = async (
|
||||
canvasElement: HTMLElement,
|
||||
testId: string,
|
||||
): Promise<void> => {
|
||||
// The footer stays disabled, and remounts, until the rule has loaded.
|
||||
const button = await waitFor(async () => {
|
||||
const element = within(canvasElement).getByTestId(testId);
|
||||
|
||||
await expect(element).toBeEnabled();
|
||||
await expect(element).not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
return element;
|
||||
}, untilLoaded);
|
||||
await userEvent.click(button);
|
||||
};
|
||||
|
||||
export const pickAnomalySeries = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const [firstSeries] = await within(canvasElement).findAllByTestId(
|
||||
'anomaly-series-option',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await userEvent.click(firstSeries);
|
||||
};
|
||||
|
||||
export const openAlertActionsMenu = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByTestId(
|
||||
'alert-actions-menu',
|
||||
{},
|
||||
{ timeout: 10000 },
|
||||
),
|
||||
);
|
||||
await screen.findByRole('menu');
|
||||
};
|
||||
|
||||
export const saveAlertRule = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await clickFooterButton(canvasElement, 'save-alert-rule-button');
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/alert rule updated successfully/i)).toBeVisible(),
|
||||
);
|
||||
};
|
||||
|
||||
export const sendTestNotification = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await clickFooterButton(canvasElement, 'test-notification-button');
|
||||
if (args.testNotification === 'sent') {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByText(/test notification sent successfully/i),
|
||||
).toBeVisible(),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const openPreviewErrorDetails = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!showsInvalidQueryError(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await userEvent.hover(
|
||||
await within(canvasElement).findByTestId(
|
||||
'alert-preview-error-status',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('panel-status-content')).toBeVisible(),
|
||||
);
|
||||
};
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
type GetMetricMetadata200,
|
||||
type ListMetrics200,
|
||||
type MetricsexplorertypesListMetricDTO,
|
||||
type RenderErrorResponseDTO,
|
||||
type TelemetrytypesTelemetryFieldKeyDTO,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import type {
|
||||
@@ -299,3 +300,26 @@ export const alertFieldValuesResponse = (
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const PREVIEW_QUERY_CHOICES = ['valid', 'invalid'] as const;
|
||||
|
||||
export type PreviewQueryChoice = (typeof PREVIEW_QUERY_CHOICES)[number];
|
||||
|
||||
/** The 400 `query_range` answers when the filter expression does not parse. */
|
||||
export const alertPreviewInvalidQueryError = (): RenderErrorResponseDTO => ({
|
||||
status: 'error',
|
||||
error: {
|
||||
code: 'invalid_input',
|
||||
type: 'invalid_input',
|
||||
message: 'Found 1 syntax errors while parsing the search expression.',
|
||||
url: 'https://signoz.io/docs/userguide/search-troubleshooting/',
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
"line 1:24 expecting one of {'(', ')', AND, NOT, OR, EOF} but got 'AND'",
|
||||
suggestions: [],
|
||||
},
|
||||
],
|
||||
suggestions: [],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,18 +7,21 @@ import { RuletypesRuleTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { rest } from 'msw';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
import { AlertTypes } from 'types/api/alerts/alertTypes';
|
||||
|
||||
import { choiceControl, countControl } from '@/storybook/controls/controls';
|
||||
import { defineStoryMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import {
|
||||
alertFieldKeysResponse,
|
||||
alertFieldValuesResponse,
|
||||
alertMetricMetadataResponse,
|
||||
alertMetricsResponse,
|
||||
alertPreviewInvalidQueryError,
|
||||
alertPreviewSeries,
|
||||
PREVIEW_QUERY_CHOICES,
|
||||
type PreviewQueryChoice,
|
||||
} from '../../AlertList/stories/__story_mockdata__/alertQuery';
|
||||
import {
|
||||
notificationChannelsResponse,
|
||||
@@ -93,6 +96,13 @@ export const createAlertMocks = defineStoryMocks({
|
||||
value: 3,
|
||||
max: 6,
|
||||
}),
|
||||
previewQuery: choiceControl<PreviewQueryChoice>('Preview query', {
|
||||
group: FORM,
|
||||
description:
|
||||
'`invalid` makes `query_range` answer with the 400 a filter that does not parse gets, so the preview shows its error.',
|
||||
options: PREVIEW_QUERY_CHOICES,
|
||||
value: 'valid',
|
||||
}),
|
||||
testNotification: choiceControl<TestNotification>('Test notification', {
|
||||
group: 'Create alert · form',
|
||||
description:
|
||||
@@ -124,9 +134,12 @@ export const createAlertMocks = defineStoryMocks({
|
||||
response.json(() => notificationChannelsResponse(values.channels)),
|
||||
),
|
||||
|
||||
rest.post(
|
||||
'http://localhost/api/v5/query_range',
|
||||
response.json(async (req) => alertPreviewSeries(values.previewSeries, req)),
|
||||
rest.post('http://localhost/api/v5/query_range', (req, res, ctx) =>
|
||||
values.previewQuery === 'invalid'
|
||||
? res(ctx.status(400), ctx.json(alertPreviewInvalidQueryError()))
|
||||
: response.json(async (request) =>
|
||||
alertPreviewSeries(values.previewSeries, request),
|
||||
)(req, res, ctx),
|
||||
),
|
||||
|
||||
rest.get(
|
||||
@@ -163,37 +176,7 @@ export const createAlertMocks = defineStoryMocks({
|
||||
config: (values) => ({ route: routeFor(values.alertMode) }),
|
||||
});
|
||||
|
||||
const untilLoaded = { timeout: 15_000 };
|
||||
export type CreateAlertArgs = PageStoryArgs<typeof createAlertMocks>;
|
||||
|
||||
export const fillValidAlert = async (
|
||||
canvasElement: HTMLElement,
|
||||
): Promise<void> => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await userEvent.type(
|
||||
await canvas.findByTestId('alert-name-input', undefined, untilLoaded),
|
||||
'Toast alert',
|
||||
);
|
||||
const channels = await canvas.findByTestId(
|
||||
'threshold-notification-channel-select',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
|
||||
await userEvent.click(within(channels).getByRole('combobox'));
|
||||
await userEvent.click(await screen.findByTitle('ops-slack'));
|
||||
await userEvent.keyboard('{Escape}');
|
||||
};
|
||||
|
||||
export const clickFooterButton = async (
|
||||
canvasElement: HTMLElement,
|
||||
testId: string,
|
||||
): Promise<void> => {
|
||||
const button = await within(canvasElement).findByTestId(testId);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(button).toBeEnabled();
|
||||
expect(button).not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
await userEvent.click(button);
|
||||
};
|
||||
export const showsInvalidQueryError = (args: CreateAlertArgs): boolean =>
|
||||
args.previewQuery === 'invalid' && args.alertMode !== 'select-type';
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import {
|
||||
clickFooterButton,
|
||||
createAlertMocks,
|
||||
fillValidAlert,
|
||||
type CreateAlertArgs,
|
||||
} from './CreateAlert.stories.mocks';
|
||||
import {
|
||||
enableRoutingPolicies,
|
||||
holdMatchTypeTooltip,
|
||||
openPreviewErrorDetails,
|
||||
saveAlertRule,
|
||||
sendTestNotification,
|
||||
} from './__story_mockdata__/createAlert.play';
|
||||
|
||||
import CreateAlertPage from '../index';
|
||||
|
||||
type CreateAlertArgs = PageStoryArgs<typeof createAlertMocks>;
|
||||
|
||||
const pageStory = storyMocks(createAlertMocks, { layout: 'app' });
|
||||
|
||||
/**
|
||||
@@ -51,6 +53,22 @@ export const LogsAlert: Story = {
|
||||
args: { alertMode: 'logs' },
|
||||
};
|
||||
|
||||
/**
|
||||
* A filter that does not parse: the preview says it could not load, with a
|
||||
* retry, and the error icon beside the title holds the server's message.
|
||||
*/
|
||||
export const PreviewQueryError: Story = {
|
||||
args: { alertMode: 'logs', previewQuery: 'invalid' },
|
||||
parameters: { allowConsoleErrors: true },
|
||||
};
|
||||
|
||||
/** The preview's error icon, hovered: the code, message, docs link and parser output. */
|
||||
export const PreviewQueryErrorDetails: Story = {
|
||||
args: { alertMode: 'logs', previewQuery: 'invalid' },
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: openPreviewErrorDetails,
|
||||
};
|
||||
|
||||
/**
|
||||
* Anomaly detection: the condition is a number of deviations from the seasonal
|
||||
* forecast instead of a fixed threshold, and only builder metric queries apply.
|
||||
@@ -65,20 +83,7 @@ export const AnomalyAlert: Story = {
|
||||
*/
|
||||
export const AnomalyAlertRoutingPolicies: Story = {
|
||||
args: { alertMode: 'anomaly' },
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await userEvent.click(
|
||||
await canvas.findByTestId('routing-policies-switch', undefined, {
|
||||
timeout: 15_000,
|
||||
}),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
canvas.queryByTestId('threshold-notification-channel-select'),
|
||||
).not.toBeInTheDocument(),
|
||||
);
|
||||
},
|
||||
play: enableRoutingPolicies,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -91,52 +96,21 @@ export const AnomalyAlertRoutingPolicies: Story = {
|
||||
*/
|
||||
export const Tooltips: Story = {
|
||||
args: { tooltipsOpen: true },
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const select = await within(canvasElement).findByTestId(
|
||||
'alert-threshold-match-type-select',
|
||||
undefined,
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
|
||||
// The select opens off a mousedown on its inner selector, so a click on
|
||||
// the wrapper the test id sits on reaches nothing.
|
||||
await userEvent.click(within(select).getByRole('combobox'));
|
||||
|
||||
await userEvent.hover(
|
||||
await screen.findByText('ALL THE TIME', undefined, { timeout: 15_000 }),
|
||||
);
|
||||
await screen.findByText('Example:', undefined, { timeout: 15_000 });
|
||||
},
|
||||
play: holdMatchTypeTooltip,
|
||||
};
|
||||
|
||||
/** A valid rule saved from the footer: the toast raised once the POST answers. */
|
||||
export const AlertRuleCreatedToast: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await fillValidAlert(canvasElement);
|
||||
await clickFooterButton(canvasElement, 'save-alert-rule-button');
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/alert rule created successfully/i)).toBeVisible(),
|
||||
);
|
||||
},
|
||||
play: saveAlertRule,
|
||||
};
|
||||
|
||||
/** Test Notification on a rule whose condition fires: the success toast. */
|
||||
export const TestNotificationSentToast: Story = {
|
||||
play: async ({ canvasElement, args }): Promise<void> => {
|
||||
await fillValidAlert(canvasElement);
|
||||
await clickFooterButton(canvasElement, 'test-notification-button');
|
||||
if (args.testNotification === 'sent') {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByText(/test notification sent successfully/i),
|
||||
).toBeVisible(),
|
||||
);
|
||||
}
|
||||
},
|
||||
play: sendTestNotification,
|
||||
};
|
||||
|
||||
/** Test Notification on a rule that finds nothing to alert on: the error toast. */
|
||||
export const TestNotificationNoAlertsToast: Story = {
|
||||
args: { testNotification: 'no-alerts' },
|
||||
play: TestNotificationSentToast.play,
|
||||
play: sendTestNotification,
|
||||
};
|
||||
|
||||
128
frontend/src/pages/CreateAlert/stories/__story_mockdata__/createAlert.play.ts
generated
Normal file
128
frontend/src/pages/CreateAlert/stories/__story_mockdata__/createAlert.play.ts
generated
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import {
|
||||
type CreateAlertArgs,
|
||||
showsInvalidQueryError,
|
||||
} from '../CreateAlert.stories.mocks';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
args: CreateAlertArgs;
|
||||
}
|
||||
|
||||
const untilLoaded = { timeout: 15_000 };
|
||||
|
||||
const fillValidAlert = async (canvasElement: HTMLElement): Promise<void> => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await userEvent.type(
|
||||
await canvas.findByTestId('alert-name-input', undefined, untilLoaded),
|
||||
'Toast alert',
|
||||
);
|
||||
const channels = await canvas.findByTestId(
|
||||
'threshold-notification-channel-select',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
|
||||
await userEvent.click(within(channels).getByRole('combobox'));
|
||||
await userEvent.click(await screen.findByTitle('ops-slack'));
|
||||
await userEvent.keyboard('{Escape}');
|
||||
};
|
||||
|
||||
const clickFooterButton = async (
|
||||
canvasElement: HTMLElement,
|
||||
testId: string,
|
||||
): Promise<void> => {
|
||||
const button = await within(canvasElement).findByTestId(testId);
|
||||
|
||||
await waitFor(async () => {
|
||||
await expect(button).toBeEnabled();
|
||||
await expect(button).not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
await userEvent.click(button);
|
||||
};
|
||||
|
||||
export const enableRoutingPolicies = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await userEvent.click(
|
||||
await canvas.findByTestId('routing-policies-switch', undefined, untilLoaded),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
canvas.queryByTestId('threshold-notification-channel-select'),
|
||||
).not.toBeInTheDocument(),
|
||||
);
|
||||
};
|
||||
|
||||
export const holdMatchTypeTooltip = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const select = await within(canvasElement).findByTestId(
|
||||
'alert-threshold-match-type-select',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
|
||||
// The select opens off a mousedown on its inner selector, so a click on
|
||||
// the wrapper the test id sits on reaches nothing.
|
||||
await userEvent.click(within(select).getByRole('combobox'));
|
||||
|
||||
await userEvent.hover(
|
||||
await screen.findByText('ALL THE TIME', undefined, untilLoaded),
|
||||
);
|
||||
await screen.findByText('Example:', undefined, untilLoaded);
|
||||
};
|
||||
|
||||
export const saveAlertRule = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await fillValidAlert(canvasElement);
|
||||
await clickFooterButton(canvasElement, 'save-alert-rule-button');
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/alert rule created successfully/i)).toBeVisible(),
|
||||
);
|
||||
};
|
||||
|
||||
export const sendTestNotification = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await fillValidAlert(canvasElement);
|
||||
await clickFooterButton(canvasElement, 'test-notification-button');
|
||||
if (args.testNotification === 'sent') {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByText(/test notification sent successfully/i),
|
||||
).toBeVisible(),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const openPreviewErrorDetails = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!showsInvalidQueryError(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await userEvent.hover(
|
||||
await within(canvasElement).findByTestId(
|
||||
'alert-preview-error-status',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('panel-status-content')).toBeVisible(),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user