Skip to content

Commit a9ce803

Browse files
committed
[APM] Add transaction error rate alert
1 parent b733375 commit a9ce803

23 files changed

Lines changed: 642 additions & 280 deletions

File tree

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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
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+
import { EuiSelect, EuiExpression, EuiFieldNumber } from '@elastic/eui';
77
import { i18n } from '@kbn/i18n';
88
import { isFinite } from 'lodash';
99
import React from 'react';
1010
import { useParams } from 'react-router-dom';
1111
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
12-
import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
12+
import { ALERT_TYPES_CONFIG, AlertType } from '../../../../common/alert_types';
1313
import {
1414
ENVIRONMENT_ALL,
1515
getEnvironmentLabel,
@@ -19,20 +19,21 @@ import { useUrlParams } from '../../../hooks/useUrlParams';
1919
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
2020
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
2121

22-
export interface ErrorRateAlertTriggerParams {
22+
export interface AlertParams {
2323
windowSize: number;
2424
windowUnit: string;
2525
threshold: number;
26+
serviceName: string;
2627
environment: string;
2728
}
2829

2930
interface Props {
30-
alertParams: ErrorRateAlertTriggerParams;
31+
alertParams: AlertParams;
3132
setAlertParams: (key: string, value: any) => void;
3233
setAlertProperty: (key: string, value: any) => void;
3334
}
3435

35-
export function ErrorRateAlertTrigger(props: Props) {
36+
export function ErrorCountAlertTrigger(props: Props) {
3637
const { setAlertParams, setAlertProperty, alertParams } = props;
3738
const { serviceName } = useParams<{ serviceName?: string }>();
3839
const { urlParams } = useUrlParams();
@@ -54,6 +55,15 @@ export function ErrorRateAlertTrigger(props: Props) {
5455
const threshold = isFinite(params.threshold) ? params.threshold : '';
5556

5657
const fields = [
58+
<EuiExpression
59+
description={i18n.translate(
60+
'xpack.apm.transactionDurationAnomalyAlertTrigger.service',
61+
{
62+
defaultMessage: 'Service',
63+
}
64+
)}
65+
value={serviceName}
66+
/>,
5767
<PopoverExpression
5868
value={getEnvironmentLabel(params.environment)}
5969
title={i18n.translate('xpack.apm.errorRateAlertTrigger.environment', {
@@ -66,7 +76,7 @@ export function ErrorRateAlertTrigger(props: Props) {
6676
onChange={(e) =>
6777
setAlertParams(
6878
'environment',
69-
e.target.value as ErrorRateAlertTriggerParams['environment']
79+
e.target.value as AlertParams['environment']
7080
)
7181
}
7282
compressed
@@ -108,7 +118,7 @@ export function ErrorRateAlertTrigger(props: Props) {
108118

109119
return (
110120
<ServiceAlertTrigger
111-
alertTypeName={ALERT_TYPES_CONFIG['apm.error_rate'].name}
121+
alertTypeName={ALERT_TYPES_CONFIG[AlertType.ErrorCount].name}
112122
defaults={defaults}
113123
fields={fields}
114124
setAlertParams={setAlertParams}
@@ -120,4 +130,4 @@ export function ErrorRateAlertTrigger(props: Props) {
120130
// Default export is required for React.lazy loading
121131
//
122132
// eslint-disable-next-line import/no-default-export
123-
export default ErrorRateAlertTrigger;
133+
export default ErrorCountAlertTrigger;

x-pack/plugins/apm/public/components/shared/ServiceAlertTrigger/PopoverExpression/index.tsx renamed to x-pack/plugins/apm/public/components/alerting/ServiceAlertTrigger/PopoverExpression/index.tsx

File renamed without changes.

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

File renamed without changes.

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

File renamed without changes.

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

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
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+
import { EuiFieldNumber, EuiSelect, EuiExpression } from '@elastic/eui';
7+
import { useParams } from 'react-router-dom';
78
import { i18n } from '@kbn/i18n';
89
import { map } from 'lodash';
910
import React from 'react';
1011
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
11-
import {
12-
ALERT_TYPES_CONFIG,
13-
TRANSACTION_ALERT_AGGREGATION_TYPES,
14-
} from '../../../../common/alert_types';
12+
import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
1513
import { useEnvironments } from '../../../hooks/useEnvironments';
1614
import { useServiceTransactionTypes } from '../../../hooks/useServiceTransactionTypes';
1715
import { useUrlParams } from '../../../hooks/useUrlParams';
@@ -22,7 +20,7 @@ import {
2220
getEnvironmentLabel,
2321
} from '../../../../common/environment_filter_values';
2422

25-
interface Params {
23+
interface AlertParams {
2624
windowSize: number;
2725
windowUnit: string;
2826
threshold: number;
@@ -32,23 +30,42 @@ interface Params {
3230
environment: string;
3331
}
3432

33+
const TRANSACTION_ALERT_AGGREGATION_TYPES = {
34+
avg: i18n.translate(
35+
'xpack.apm.transactionDurationAlert.aggregationType.avg',
36+
{
37+
defaultMessage: 'Average',
38+
}
39+
),
40+
'95th': i18n.translate(
41+
'xpack.apm.transactionDurationAlert.aggregationType.95th',
42+
{
43+
defaultMessage: '95th percentile',
44+
}
45+
),
46+
'99th': i18n.translate(
47+
'xpack.apm.transactionDurationAlert.aggregationType.99th',
48+
{
49+
defaultMessage: '99th percentile',
50+
}
51+
),
52+
};
53+
3554
interface Props {
36-
alertParams: Params;
55+
alertParams: AlertParams;
3756
setAlertParams: (key: string, value: any) => void;
3857
setAlertProperty: (key: string, value: any) => void;
3958
}
4059

4160
export function TransactionDurationAlertTrigger(props: Props) {
4261
const { setAlertParams, alertParams, setAlertProperty } = props;
43-
const { serviceName } = alertParams;
4462
const { urlParams } = useUrlParams();
45-
4663
const transactionTypes = useServiceTransactionTypes(urlParams);
47-
48-
const { start, end } = urlParams;
64+
const { serviceName } = useParams<{ serviceName?: string }>();
65+
const { start, end, transactionType } = urlParams;
4966
const { environmentOptions } = useEnvironments({ serviceName, start, end });
5067

51-
if (!transactionTypes.length) {
68+
if (!transactionTypes.length || !serviceName) {
5269
return null;
5370
}
5471

@@ -57,7 +74,9 @@ export function TransactionDurationAlertTrigger(props: Props) {
5774
aggregationType: 'avg',
5875
windowSize: 5,
5976
windowUnit: 'm',
60-
transactionType: transactionTypes[0],
77+
78+
// use the current transaction type or default to the first in the list
79+
transactionType: transactionType || transactionTypes[0],
6180
environment: urlParams.environment || ENVIRONMENT_ALL.value,
6281
};
6382

@@ -67,6 +86,15 @@ export function TransactionDurationAlertTrigger(props: Props) {
6786
};
6887

6988
const fields = [
89+
<EuiExpression
90+
description={i18n.translate(
91+
'xpack.apm.transactionDurationAnomalyAlertTrigger.service',
92+
{
93+
defaultMessage: 'Service',
94+
}
95+
)}
96+
value={serviceName}
97+
/>,
7098
<PopoverExpression
7199
value={getEnvironmentLabel(params.environment)}
72100
title={i18n.translate(
@@ -80,7 +108,10 @@ export function TransactionDurationAlertTrigger(props: Props) {
80108
value={params.environment}
81109
options={environmentOptions}
82110
onChange={(e) =>
83-
setAlertParams('environment', e.target.value as Params['environment'])
111+
setAlertParams(
112+
'environment',
113+
e.target.value as AlertParams['environment']
114+
)
84115
}
85116
compressed
86117
/>
@@ -102,7 +133,7 @@ export function TransactionDurationAlertTrigger(props: Props) {
102133
onChange={(e) =>
103134
setAlertParams(
104135
'transactionType',
105-
e.target.value as Params['transactionType']
136+
e.target.value as AlertParams['transactionType']
106137
)
107138
}
108139
compressed
@@ -125,7 +156,7 @@ export function TransactionDurationAlertTrigger(props: Props) {
125156
onChange={(e) =>
126157
setAlertParams(
127158
'aggregationType',
128-
e.target.value as Params['aggregationType']
159+
e.target.value as AlertParams['aggregationType']
129160
)
130161
}
131162
compressed

x-pack/plugins/apm/public/components/shared/TransactionDurationAnomalyAlertTrigger/SelectAnomalySeverity.tsx renamed to x-pack/plugins/apm/public/components/alerting/TransactionDurationAnomalyAlertTrigger/SelectAnomalySeverity.tsx

File renamed without changes.

0 commit comments

Comments
 (0)