Skip to content

Commit fb62929

Browse files
authored
[APM] Add transaction error rate alert (#76933)
1 parent becb137 commit fb62929

File tree

26 files changed

+726
-438
lines changed

26 files changed

+726
-438
lines changed

x-pack/plugins/apm/common/alert_types.ts

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,82 +7,58 @@
77
import { i18n } from '@kbn/i18n';
88

99
export enum AlertType {
10-
ErrorRate = 'apm.error_rate',
10+
ErrorCount = 'apm.error_rate', // ErrorRate was renamed to ErrorCount but the key is kept as `error_rate` for backwards-compat.
11+
TransactionErrorRate = 'apm.transaction_error_rate',
1112
TransactionDuration = 'apm.transaction_duration',
1213
TransactionDurationAnomaly = 'apm.transaction_duration_anomaly',
1314
}
1415

16+
const THRESHOLD_MET_GROUP = {
17+
id: 'threshold_met',
18+
name: i18n.translate('xpack.apm.a.thresholdMet', {
19+
defaultMessage: 'Threshold met',
20+
}),
21+
};
22+
1523
export const ALERT_TYPES_CONFIG = {
16-
[AlertType.ErrorRate]: {
17-
name: i18n.translate('xpack.apm.errorRateAlert.name', {
18-
defaultMessage: 'Error rate',
24+
[AlertType.ErrorCount]: {
25+
name: i18n.translate('xpack.apm.errorCountAlert.name', {
26+
defaultMessage: 'Error count threshold',
1927
}),
20-
actionGroups: [
21-
{
22-
id: 'threshold_met',
23-
name: i18n.translate('xpack.apm.errorRateAlert.thresholdMet', {
24-
defaultMessage: 'Threshold met',
25-
}),
26-
},
27-
],
28+
actionGroups: [THRESHOLD_MET_GROUP],
2829
defaultActionGroupId: 'threshold_met',
2930
producer: 'apm',
3031
},
3132
[AlertType.TransactionDuration]: {
3233
name: i18n.translate('xpack.apm.transactionDurationAlert.name', {
33-
defaultMessage: 'Transaction duration',
34+
defaultMessage: 'Transaction duration threshold',
3435
}),
35-
actionGroups: [
36-
{
37-
id: 'threshold_met',
38-
name: i18n.translate(
39-
'xpack.apm.transactionDurationAlert.thresholdMet',
40-
{
41-
defaultMessage: 'Threshold met',
42-
}
43-
),
44-
},
45-
],
36+
actionGroups: [THRESHOLD_MET_GROUP],
4637
defaultActionGroupId: 'threshold_met',
4738
producer: 'apm',
4839
},
4940
[AlertType.TransactionDurationAnomaly]: {
5041
name: i18n.translate('xpack.apm.transactionDurationAnomalyAlert.name', {
5142
defaultMessage: 'Transaction duration anomaly',
5243
}),
53-
actionGroups: [
54-
{
55-
id: 'threshold_met',
56-
name: i18n.translate(
57-
'xpack.apm.transactionDurationAlert.thresholdMet',
58-
{
59-
defaultMessage: 'Threshold met',
60-
}
61-
),
62-
},
63-
],
44+
actionGroups: [THRESHOLD_MET_GROUP],
45+
defaultActionGroupId: 'threshold_met',
46+
producer: 'apm',
47+
},
48+
[AlertType.TransactionErrorRate]: {
49+
name: i18n.translate('xpack.apm.transactionErrorRateAlert.name', {
50+
defaultMessage: 'Transaction error rate threshold',
51+
}),
52+
actionGroups: [THRESHOLD_MET_GROUP],
6453
defaultActionGroupId: 'threshold_met',
6554
producer: 'apm',
6655
},
6756
};
6857

69-
export const TRANSACTION_ALERT_AGGREGATION_TYPES = {
70-
avg: i18n.translate(
71-
'xpack.apm.transactionDurationAlert.aggregationType.avg',
72-
{
73-
defaultMessage: 'Average',
74-
}
75-
),
76-
'95th': i18n.translate(
77-
'xpack.apm.transactionDurationAlert.aggregationType.95th',
78-
{
79-
defaultMessage: '95th percentile',
80-
}
81-
),
82-
'99th': i18n.translate(
83-
'xpack.apm.transactionDurationAlert.aggregationType.99th',
84-
{
85-
defaultMessage: '99th percentile',
86-
}
87-
),
88-
};
58+
// Server side registrations
59+
// x-pack/plugins/apm/server/lib/alerts/<alert>.ts
60+
// x-pack/plugins/apm/server/lib/alerts/register_apm_alerts.ts
61+
62+
// Client side registrations:
63+
// x-pack/plugins/apm/public/components/alerting/<alert>/index.tsx
64+
// x-pack/plugins/apm/public/components/alerting/register_apm_alerts

x-pack/plugins/apm/public/components/shared/ErrorRateAlertTrigger/index.stories.tsx renamed to x-pack/plugins/apm/public/components/alerting/ErrorCountAlertTrigger/index.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import { storiesOf } from '@storybook/react';
88
import React from 'react';
9-
import { ErrorRateAlertTrigger } from '.';
9+
import { ErrorCountAlertTrigger } from '.';
1010
import { ApmPluginContextValue } from '../../../context/ApmPluginContext';
1111
import {
1212
mockApmPluginContextValue,
1313
MockApmPluginContextWrapper,
1414
} from '../../../context/ApmPluginContext/MockApmPluginContext';
1515

16-
storiesOf('app/ErrorRateAlertTrigger', module).add(
16+
storiesOf('app/ErrorCountAlertTrigger', module).add(
1717
'example',
1818
() => {
1919
const params = {
@@ -26,7 +26,7 @@ storiesOf('app/ErrorRateAlertTrigger', module).add(
2626
value={(mockApmPluginContextValue as unknown) as ApmPluginContextValue}
2727
>
2828
<div style={{ width: 400 }}>
29-
<ErrorRateAlertTrigger
29+
<ErrorCountAlertTrigger
3030
alertParams={params as any}
3131
setAlertParams={() => undefined}
3232
setAlertProperty={() => undefined}
@@ -37,7 +37,7 @@ storiesOf('app/ErrorRateAlertTrigger', module).add(
3737
},
3838
{
3939
info: {
40-
propTablesExclude: [ErrorRateAlertTrigger, MockApmPluginContextWrapper],
40+
propTablesExclude: [ErrorCountAlertTrigger, MockApmPluginContextWrapper],
4141
source: false,
4242
},
4343
}

x-pack/plugins/apm/public/components/shared/ErrorRateAlertTrigger/index.tsx renamed to x-pack/plugins/apm/public/components/alerting/ErrorCountAlertTrigger/index.tsx

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,33 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import { EuiFieldNumber, EuiSelect } from '@elastic/eui';
6+
77
import { i18n } from '@kbn/i18n';
8-
import { isFinite } from 'lodash';
98
import React from 'react';
109
import { useParams } from 'react-router-dom';
1110
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
12-
import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
13-
import {
14-
ENVIRONMENT_ALL,
15-
getEnvironmentLabel,
16-
} from '../../../../common/environment_filter_values';
11+
import { ALERT_TYPES_CONFIG, AlertType } from '../../../../common/alert_types';
12+
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1713
import { useEnvironments } from '../../../hooks/useEnvironments';
1814
import { useUrlParams } from '../../../hooks/useUrlParams';
15+
import { EnvironmentField, ServiceField, IsAboveField } from '../fields';
1916
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
20-
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
2117

22-
export interface ErrorRateAlertTriggerParams {
18+
export interface AlertParams {
2319
windowSize: number;
2420
windowUnit: string;
2521
threshold: number;
22+
serviceName: string;
2623
environment: string;
2724
}
2825

2926
interface Props {
30-
alertParams: ErrorRateAlertTriggerParams;
27+
alertParams: AlertParams;
3128
setAlertParams: (key: string, value: any) => void;
3229
setAlertProperty: (key: string, value: any) => void;
3330
}
3431

35-
export function ErrorRateAlertTrigger(props: Props) {
32+
export function ErrorCountAlertTrigger(props: Props) {
3633
const { setAlertParams, setAlertProperty, alertParams } = props;
3734
const { serviceName } = useParams<{ serviceName?: string }>();
3835
const { urlParams } = useUrlParams();
@@ -51,45 +48,20 @@ export function ErrorRateAlertTrigger(props: Props) {
5148
...alertParams,
5249
};
5350

54-
const threshold = isFinite(params.threshold) ? params.threshold : '';
55-
5651
const fields = [
57-
<PopoverExpression
58-
value={getEnvironmentLabel(params.environment)}
59-
title={i18n.translate('xpack.apm.errorRateAlertTrigger.environment', {
60-
defaultMessage: 'Environment',
61-
})}
62-
>
63-
<EuiSelect
64-
value={params.environment}
65-
options={environmentOptions}
66-
onChange={(e) =>
67-
setAlertParams(
68-
'environment',
69-
e.target.value as ErrorRateAlertTriggerParams['environment']
70-
)
71-
}
72-
compressed
73-
/>
74-
</PopoverExpression>,
75-
<PopoverExpression
76-
title={i18n.translate('xpack.apm.errorRateAlertTrigger.isAbove', {
77-
defaultMessage: 'is above',
52+
<ServiceField value={serviceName} />,
53+
<EnvironmentField
54+
currentValue={params.environment}
55+
options={environmentOptions}
56+
onChange={(e) => setAlertParams('environment', e.target.value)}
57+
/>,
58+
<IsAboveField
59+
value={params.threshold}
60+
unit={i18n.translate('xpack.apm.errorCountAlertTrigger.errors', {
61+
defaultMessage: ' errors',
7862
})}
79-
value={threshold.toString()}
80-
>
81-
<EuiFieldNumber
82-
value={threshold}
83-
step={0}
84-
onChange={(e) =>
85-
setAlertParams('threshold', parseInt(e.target.value, 10))
86-
}
87-
compressed
88-
append={i18n.translate('xpack.apm.errorRateAlertTrigger.errors', {
89-
defaultMessage: 'errors',
90-
})}
91-
/>
92-
</PopoverExpression>,
63+
onChange={(value) => setAlertParams('threshold', value)}
64+
/>,
9365
<ForLastExpression
9466
onChangeWindowSize={(windowSize) =>
9567
setAlertParams('windowSize', windowSize || '')
@@ -108,7 +80,7 @@ export function ErrorRateAlertTrigger(props: Props) {
10880

10981
return (
11082
<ServiceAlertTrigger
111-
alertTypeName={ALERT_TYPES_CONFIG['apm.error_rate'].name}
83+
alertTypeName={ALERT_TYPES_CONFIG[AlertType.ErrorCount].name}
11284
defaults={defaults}
11385
fields={fields}
11486
setAlertParams={setAlertParams}
@@ -120,4 +92,4 @@ export function ErrorRateAlertTrigger(props: Props) {
12092
// Default export is required for React.lazy loading
12193
//
12294
// eslint-disable-next-line import/no-default-export
123-
export default ErrorRateAlertTrigger;
95+
export default ErrorCountAlertTrigger;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interface Props {
1515

1616
export function PopoverExpression(props: Props) {
1717
const { title, value, children } = props;
18-
1918
const [popoverOpen, setPopoverOpen] = useState(false);
2019

2120
return (

0 commit comments

Comments
 (0)