Skip to content

Commit 531f849

Browse files
authored
Show warning message when attempting to create an APM alert in stack management (#111781)
Creating new rules in Stack Management does not work. Editing existing rules should work. If you enable editing rules, you also have to enable creating rules. Make it so when you attempt to create a rule in stack management it shows a warning telling you to go create the rule in APM.
1 parent d70ff6c commit 531f849

File tree

6 files changed

+100
-7
lines changed

6 files changed

+100
-7
lines changed

x-pack/plugins/apm/public/components/alerting/error_count_alert_trigger/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
import { i18n } from '@kbn/i18n';
99
import { defaults, omit } from 'lodash';
1010
import React from 'react';
11-
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1211
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
12+
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1313
import { asInteger } from '../../../../common/utils/formatters';
1414
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
1515
import { useFetcher } from '../../../hooks/use_fetcher';
1616
import { ChartPreview } from '../chart_preview';
1717
import { EnvironmentField, IsAboveField, ServiceField } from '../fields';
18-
import { AlertMetadata, getIntervalAndTimeRange, TimeUnit } from '../helper';
18+
import {
19+
AlertMetadata,
20+
getIntervalAndTimeRange,
21+
isNewApmRuleFromStackManagement,
22+
TimeUnit,
23+
} from '../helper';
24+
import { NewAlertEmptyPrompt } from '../new_alert_empty_prompt';
1925
import { ServiceAlertTrigger } from '../service_alert_trigger';
2026

2127
export interface AlertParams {
@@ -81,6 +87,10 @@ export function ErrorCountAlertTrigger(props: Props) {
8187
]
8288
);
8389

90+
if (isNewApmRuleFromStackManagement(alertParams, metadata)) {
91+
return <NewAlertEmptyPrompt />;
92+
}
93+
8494
const fields = [
8595
<ServiceField value={params.serviceName} />,
8696
<EnvironmentField

x-pack/plugins/apm/public/components/alerting/helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@ export function getIntervalAndTimeRange({
3636
end: new Date(end).toISOString(),
3737
};
3838
}
39+
40+
export function isNewApmRuleFromStackManagement(
41+
alertParams: any,
42+
metadata?: AlertMetadata
43+
) {
44+
return (
45+
alertParams !== undefined &&
46+
Object.keys(alertParams).length === 0 &&
47+
metadata === undefined
48+
);
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
/* eslint-disable @elastic/eui/href-or-on-click */
9+
10+
import { EuiButton, EuiEmptyPrompt } from '@elastic/eui';
11+
import { i18n } from '@kbn/i18n';
12+
import React, { MouseEvent } from 'react';
13+
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
14+
15+
export function NewAlertEmptyPrompt() {
16+
const { services } = useKibana();
17+
const apmUrl = services.http?.basePath.prepend('/app/apm');
18+
const navigateToUrl = services.application?.navigateToUrl;
19+
const handleClick = (event: MouseEvent<HTMLAnchorElement>) => {
20+
event.preventDefault();
21+
if (apmUrl && navigateToUrl) {
22+
navigateToUrl(apmUrl);
23+
}
24+
};
25+
26+
return (
27+
<EuiEmptyPrompt
28+
iconType="alert"
29+
body={i18n.translate('xpack.apm.NewAlertEmptyPrompt.bodyDescription', {
30+
defaultMessage:
31+
'APM rules cannot be created in Stack Management. Go to APM and use the "Alerts and rules" menu.',
32+
})}
33+
actions={[
34+
<EuiButton
35+
color="primary"
36+
fill={true}
37+
href={apmUrl}
38+
onClick={handleClick}
39+
>
40+
{i18n.translate('xpack.apm.NewAlertEmptyPrompt.goToApmLinkText', {
41+
defaultMessage: 'Go to APM',
42+
})}
43+
</EuiButton>,
44+
]}
45+
/>
46+
);
47+
}

x-pack/plugins/apm/public/components/alerting/transaction_duration_alert_trigger/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { EuiSelect } from '@elastic/eui';
99
import { i18n } from '@kbn/i18n';
1010
import { defaults, map, omit } from 'lodash';
1111
import React from 'react';
12-
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1312
import { CoreStart } from '../../../../../../../src/core/public';
1413
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
1514
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
15+
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1616
import { getDurationFormatter } from '../../../../common/utils/formatters';
1717
import { useServiceTransactionTypesFetcher } from '../../../context/apm_service/use_service_transaction_types_fetcher';
1818
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
@@ -29,7 +29,13 @@ import {
2929
ServiceField,
3030
TransactionTypeField,
3131
} from '../fields';
32-
import { AlertMetadata, getIntervalAndTimeRange, TimeUnit } from '../helper';
32+
import {
33+
AlertMetadata,
34+
getIntervalAndTimeRange,
35+
isNewApmRuleFromStackManagement,
36+
TimeUnit,
37+
} from '../helper';
38+
import { NewAlertEmptyPrompt } from '../new_alert_empty_prompt';
3339
import { ServiceAlertTrigger } from '../service_alert_trigger';
3440
import { PopoverExpression } from '../service_alert_trigger/popover_expression';
3541

@@ -154,6 +160,10 @@ export function TransactionDurationAlertTrigger(props: Props) {
154160
/>
155161
);
156162

163+
if (isNewApmRuleFromStackManagement(alertParams, metadata)) {
164+
return <NewAlertEmptyPrompt />;
165+
}
166+
157167
if (!params.serviceName) {
158168
return null;
159169
}

x-pack/plugins/apm/public/components/alerting/transaction_duration_anomaly_alert_trigger/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
ServiceField,
1818
TransactionTypeField,
1919
} from '../fields';
20-
import { AlertMetadata } from '../helper';
20+
import { AlertMetadata, isNewApmRuleFromStackManagement } from '../helper';
21+
import { NewAlertEmptyPrompt } from '../new_alert_empty_prompt';
2122
import { ServiceAlertTrigger } from '../service_alert_trigger';
2223
import { PopoverExpression } from '../service_alert_trigger/popover_expression';
2324
import {
@@ -73,6 +74,10 @@ export function TransactionDurationAnomalyAlertTrigger(props: Props) {
7374
end: metadata?.end,
7475
});
7576

77+
if (isNewApmRuleFromStackManagement(alertParams, metadata)) {
78+
return <NewAlertEmptyPrompt />;
79+
}
80+
7681
const fields = [
7782
<ServiceField value={params.serviceName} />,
7883
<TransactionTypeField

x-pack/plugins/apm/public/components/alerting/transaction_error_rate_alert_trigger/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
import { defaults, omit } from 'lodash';
99
import React from 'react';
10-
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1110
import { CoreStart } from '../../../../../../../src/core/public';
1211
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
1312
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
13+
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1414
import { asPercent } from '../../../../common/utils/formatters';
1515
import { useServiceTransactionTypesFetcher } from '../../../context/apm_service/use_service_transaction_types_fetcher';
1616
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
@@ -23,7 +23,13 @@ import {
2323
ServiceField,
2424
TransactionTypeField,
2525
} from '../fields';
26-
import { AlertMetadata, getIntervalAndTimeRange, TimeUnit } from '../helper';
26+
import {
27+
AlertMetadata,
28+
getIntervalAndTimeRange,
29+
isNewApmRuleFromStackManagement,
30+
TimeUnit,
31+
} from '../helper';
32+
import { NewAlertEmptyPrompt } from '../new_alert_empty_prompt';
2733
import { ServiceAlertTrigger } from '../service_alert_trigger';
2834

2935
interface AlertParams {
@@ -102,6 +108,10 @@ export function TransactionErrorRateAlertTrigger(props: Props) {
102108
]
103109
);
104110

111+
if (isNewApmRuleFromStackManagement(alertParams, metadata)) {
112+
return <NewAlertEmptyPrompt />;
113+
}
114+
105115
const fields = [
106116
<ServiceField value={params.serviceName} />,
107117
<TransactionTypeField

0 commit comments

Comments
 (0)