Skip to content

Commit

Permalink
Add description and documentation link in alert flyout (elastic#81526)
Browse files Browse the repository at this point in the history
* Add description and documentation URL in alert flyout

* Add unit tests

* Fix type check

* Add horizontal rule

* Design fixes

* Fix uptime alert link

* Fix uptime urls

* Add anchor tag

* Fix jest test failures

* Fix monitoring links
  • Loading branch information
mikecote committed Nov 6, 2020
1 parent a7832ff commit 8bffb19
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function getAlertType(): AlertTypeModel {
name: 'Always Fires',
description: 'Alert when called',
iconClass: 'bolt',
documentationUrl: null,
alertParamsExpression: AlwaysFiringExpression,
validate: (alertParams: AlwaysFiringParamsProps['alertParams']) => {
const { instances } = alertParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function getAlertType(): AlertTypeModel {
name: 'People Are In Space Right Now',
description: 'Alert when people are in space right now',
iconClass: 'globe',
documentationUrl: null,
alertParamsExpression: PeopleinSpaceExpression,
validate: (alertParams: PeopleinSpaceParamsProps['alertParams']) => {
const { outerSpaceCapacity, craft, op } = alertParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function registerApmAlerts(
'Alert when the number of errors in a service exceeds a defined threshold.',
}),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/apm-alerts.html`;
},
alertParamsExpression: lazy(() => import('./ErrorCountAlertTrigger')),
validate: () => ({
errors: [],
Expand Down Expand Up @@ -53,6 +56,9 @@ export function registerApmAlerts(
}
),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/apm-alerts.html`;
},
alertParamsExpression: lazy(
() => import('./TransactionDurationAlertTrigger')
),
Expand Down Expand Up @@ -87,6 +93,9 @@ export function registerApmAlerts(
}
),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/apm-alerts.html`;
},
alertParamsExpression: lazy(
() => import('./TransactionErrorRateAlertTrigger')
),
Expand Down Expand Up @@ -121,6 +130,9 @@ export function registerApmAlerts(
}
),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/apm-alerts.html`;
},
alertParamsExpression: lazy(
() => import('./TransactionDurationAnomalyAlertTrigger')
),
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/infra/public/alerting/inventory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function createInventoryMetricAlertType(): AlertTypeModel {
defaultMessage: 'Alert when the inventory exceeds a defined threshold.',
}),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/observability/${docLinks.DOC_LINK_VERSION}/infrastructure-threshold-alert.html`;
},
alertParamsExpression: React.lazy(() => import('./components/expression')),
validate: validateMetricThreshold,
defaultActionMessage: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export function getAlertType(): AlertTypeModel {
defaultMessage: 'Alert when the log aggregation exceeds the threshold.',
}),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/observability/${docLinks.DOC_LINK_VERSION}/logs-threshold-alert.html`;
},
alertParamsExpression: React.lazy(() => import('./components/expression_editor/editor')),
validate: validateExpression,
defaultActionMessage: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function createMetricThresholdAlertType(): AlertTypeModel {
defaultMessage: 'Alert when the metrics aggregation exceeds the threshold.',
}),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/observability/${docLinks.DOC_LINK_VERSION}/metrics-threshold-alert.html`;
},
alertParamsExpression: React.lazy(() => import('./components/expression')),
validate: validateMetricThreshold,
defaultActionMessage: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export function createCpuUsageAlertType(): AlertTypeModel {
name: ALERT_DETAILS[ALERT_CPU_USAGE].label,
description: ALERT_DETAILS[ALERT_CPU_USAGE].description,
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/kibana-alerts.html#kibana-alerts-cpu-threshold`;
},
alertParamsExpression: (props: Props) => (
<Expression {...props} paramDetails={ALERT_DETAILS[ALERT_CPU_USAGE].paramDetails} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function createDiskUsageAlertType(): AlertTypeModel {
name: ALERT_DETAILS[ALERT_DISK_USAGE].label,
description: ALERT_DETAILS[ALERT_DISK_USAGE].description,
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/kibana-alerts.html#kibana-alerts-disk-usage-threshold`;
},
alertParamsExpression: (props: Props) => (
<Expression {...props} paramDetails={ALERT_DETAILS[ALERT_DISK_USAGE].paramDetails} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function createLegacyAlertTypes(): AlertTypeModel[] {
name: LEGACY_ALERT_DETAILS[legacyAlert].label,
description: LEGACY_ALERT_DETAILS[legacyAlert].description,
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/cluster-alerts.html`;
},
alertParamsExpression: () => (
<Fragment>
<EuiSpacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function createMemoryUsageAlertType(): AlertTypeModel {
name: ALERT_DETAILS[ALERT_MEMORY_USAGE].label,
description: ALERT_DETAILS[ALERT_MEMORY_USAGE].description,
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/kibana-alerts.html#kibana-alerts-jvm-memory-threshold`;
},
alertParamsExpression: (props: Props) => (
<Expression {...props} paramDetails={ALERT_DETAILS[ALERT_MEMORY_USAGE].paramDetails} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export function createMissingMonitoringDataAlertType(): AlertTypeModel {
name: ALERT_DETAILS[ALERT_MISSING_MONITORING_DATA].label,
description: ALERT_DETAILS[ALERT_MISSING_MONITORING_DATA].description,
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/kibana-alerts.html#kibana-alerts-missing-monitoring-data`;
},
alertParamsExpression: (props: any) => (
<Expression
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function createThreadPoolRejectionsAlertType(
name: threadPoolAlertDetails.label,
description: threadPoolAlertDetails.description,
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/kibana-alerts.html`;
},
alertParamsExpression: (props: Props) => (
<>
<EuiSpacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export function getAlertType(): AlertTypeModel<GeoThresholdAlertParams, AlertsCo
defaultMessage: 'Alert when an entity enters or leaves a geo boundary.',
}),
iconClass: 'globe',
// TODO: Add documentation for geo threshold alert
documentationUrl: null,
alertParamsExpression: lazy(() => import('./query_builder')),
validate: validateExpression,
requiresAppContext: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<AlertTyp
<EuiSpacer />
</Fragment>
) : null}
<EuiSpacer size="l" />
<EuiTitle size="xs">
<h5>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function getAlertType(): AlertTypeModel<IndexThresholdAlertParams, Alerts
defaultMessage: 'Alert when an aggregated query meets the threshold.',
}),
iconClass: 'alert',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/alert-types.html#alert-type-index-threshold`;
},
alertParamsExpression: lazy(() => import('./expression')),
validate: validateExpression,
requiresAppContext: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('alert_add', () => {
iconClass: 'test',
name: 'test-alert',
description: 'test',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('alert_edit', () => {
iconClass: 'test',
name: 'test-alert',
description: 'test',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('alert_form', () => {
id: 'my-alert-type',
iconClass: 'test',
name: 'test-alert',
description: 'test',
description: 'Alert when testing',
documentationUrl: 'https://localhost.local/docs',
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down Expand Up @@ -59,6 +60,7 @@ describe('alert_form', () => {
iconClass: 'test',
name: 'non edit alert',
description: 'test',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down Expand Up @@ -182,6 +184,22 @@ describe('alert_form', () => {
);
expect(alertTypeSelectOptions.exists()).toBeFalsy();
});

it('renders alert type description', async () => {
await setup();
wrapper.find('[data-test-subj="my-alert-type-SelectOption"]').first().simulate('click');
const alertDescription = wrapper.find('[data-test-subj="alertDescription"]');
expect(alertDescription.exists()).toBeTruthy();
expect(alertDescription.first().text()).toContain('Alert when testing');
});

it('renders alert type documentation link', async () => {
await setup();
wrapper.find('[data-test-subj="my-alert-type-SelectOption"]').first().simulate('click');
const alertDocumentationLink = wrapper.find('[data-test-subj="alertDocumentationLink"]');
expect(alertDocumentationLink.exists()).toBeTruthy();
expect(alertDocumentationLink.first().prop('href')).toBe('https://localhost.local/docs');
});
});

describe('alert_form create alert non alerting consumer and producer', () => {
Expand Down Expand Up @@ -244,6 +262,7 @@ describe('alert_form', () => {
iconClass: 'test',
name: 'test-alert',
description: 'test',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand All @@ -255,6 +274,7 @@ describe('alert_form', () => {
iconClass: 'test',
name: 'test-alert',
description: 'test',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down Expand Up @@ -423,5 +443,19 @@ describe('alert_form', () => {
const throttleFieldAfterUpdate = wrapper.find('[data-test-subj="throttleInput"]');
expect(throttleFieldAfterUpdate.at(1).prop('value')).toEqual(newThrottle);
});

it('renders alert type description', async () => {
await setup();
const alertDescription = wrapper.find('[data-test-subj="alertDescription"]');
expect(alertDescription.exists()).toBeTruthy();
expect(alertDescription.first().text()).toContain('Alert when testing');
});

it('renders alert type documentation link', async () => {
await setup();
const alertDocumentationLink = wrapper.find('[data-test-subj="alertDocumentationLink"]');
expect(alertDocumentationLink.exists()).toBeTruthy();
expect(alertDocumentationLink.first().prop('href')).toBe('https://localhost.local/docs');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
EuiHorizontalRule,
EuiLoadingSpinner,
EuiEmptyPrompt,
EuiLink,
EuiText,
} from '@elastic/eui';
import { some, filter, map, fold } from 'fp-ts/lib/Option';
import { pipe } from 'fp-ts/lib/pipeable';
Expand Down Expand Up @@ -247,6 +249,33 @@ export const AlertForm = ({
</EuiFlexItem>
) : null}
</EuiFlexGroup>
{alertTypeModel?.description && (
<EuiFlexGroup>
<EuiFlexItem>
<EuiText color="subdued" size="s" data-test-subj="alertDescription">
{alertTypeModel.description}&nbsp;
{alertTypeModel?.documentationUrl && (
<EuiLink
external
target="_blank"
data-test-subj="alertDocumentationLink"
href={
typeof alertTypeModel.documentationUrl === 'function'
? alertTypeModel.documentationUrl(docLinks)
: alertTypeModel.documentationUrl
}
>
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertForm.documentationLabel"
defaultMessage="Documentation"
/>
</EuiLink>
)}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
)}
<EuiHorizontalRule />
{AlertParamsExpressionComponent ? (
<Suspense fallback={<CenterJustifiedSpinner />}>
<AlertParamsExpressionComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const alertType = {
name: 'some alert type',
description: 'test',
iconClass: 'test',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getTestAlertType = (id?: string, name?: string, iconClass?: string) => {
name: name || 'Test alert type',
description: 'Test description',
iconClass: iconClass || 'icon',
documentationUrl: null,
validate: (): ValidationResult => {
return { errors: {} };
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/triggers_actions_ui/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export interface AlertTypeModel<AlertParamsType = any, AlertsContextValue = any>
name: string | JSX.Element;
description: string;
iconClass: string;
documentationUrl: string | ((docLinks: DocLinksStart) => string) | null;
validate: (alertParams: AlertParamsType) => ValidationResult;
alertParamsExpression:
| React.FunctionComponent<any>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ describe('monitor status alert type', () => {
"alertParamsExpression": [Function],
"defaultActionMessage": "Monitor {{state.monitorName}} with url {{{state.monitorUrl}}} is {{state.statusMessage}} from {{state.observerLocation}}. The latest error message is {{{state.latestErrorMessage}}}",
"description": "Alert when a monitor is down or an availability threshold is breached.",
"documentationUrl": [Function],
"iconClass": "uptimeApp",
"id": "xpack.uptime.alerts.monitorStatus",
"name": <FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const initDurationAnomalyAlertType: AlertTypeInitializer = ({
}): AlertTypeModel => ({
id: CLIENT_ALERT_TYPES.DURATION_ANOMALY,
iconClass: 'uptimeApp',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/uptime/${docLinks.DOC_LINK_VERSION}/uptime-alerting.html`;
},
alertParamsExpression: (params: unknown) => (
<DurationAnomalyAlert core={core} plugins={plugins} params={params} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const initMonitorStatusAlertType: AlertTypeInitializer = ({
),
description,
iconClass: 'uptimeApp',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/uptime/${docLinks.DOC_LINK_VERSION}/uptime-alerting.html#_monitor_status_alerts`;
},
alertParamsExpression: (params: any) => (
<MonitorStatusAlert core={core} plugins={plugins} params={params} />
),
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/uptime/public/lib/alert_types/tls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const TLSAlert = React.lazy(() => import('./lazy_wrapper/tls_alert'));
export const initTlsAlertType: AlertTypeInitializer = ({ core, plugins }): AlertTypeModel => ({
id: CLIENT_ALERT_TYPES.TLS,
iconClass: 'uptimeApp',
documentationUrl(docLinks) {
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/uptime/${docLinks.DOC_LINK_VERSION}/uptime-alerting.html#_tls_alerts`;
},
alertParamsExpression: (params: any) => (
<TLSAlert core={core} plugins={plugins} params={params} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamp
name: 'Test Always Firing',
description: 'Always fires',
iconClass: 'alert',
documentationUrl: null,
alertParamsExpression: () => React.createElement('div', null, 'Test Always Firing'),
validate: () => {
return { errors: {} };
Expand All @@ -43,6 +44,7 @@ export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamp
name: 'Test Noop',
description: `Doesn't do anything`,
iconClass: 'alert',
documentationUrl: null,
alertParamsExpression: () => React.createElement('div', null, 'Test Noop'),
validate: () => {
return { errors: {} };
Expand Down

0 comments on commit 8bffb19

Please sign in to comment.