Skip to content

Commit a810701

Browse files
Merge branch '7.x' into backport/7.x/pr-65855
2 parents 45f45c5 + fcc230e commit a810701

File tree

26 files changed

+439
-234
lines changed

26 files changed

+439
-234
lines changed

x-pack/plugins/apm/public/components/app/ServiceDetails/AlertIntegrations/AlertingFlyout/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ interface Props {
1717

1818
export function AlertingFlyout(props: Props) {
1919
const { addFlyoutVisible, setAddFlyoutVisibility, alertType } = props;
20-
21-
return alertType ? (
22-
<AlertAdd
23-
addFlyoutVisible={addFlyoutVisible}
24-
setAddFlyoutVisibility={setAddFlyoutVisibility}
25-
consumer="apm"
26-
alertTypeId={alertType}
27-
canChangeTrigger={false}
28-
/>
29-
) : null;
20+
return (
21+
alertType && (
22+
<AlertAdd
23+
addFlyoutVisible={addFlyoutVisible}
24+
setAddFlyoutVisibility={setAddFlyoutVisibility}
25+
consumer="apm"
26+
alertTypeId={alertType}
27+
canChangeTrigger={false}
28+
/>
29+
)
30+
);
3031
}

x-pack/plugins/apm/public/components/shared/EnvironmentFilter/index.tsx

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { EuiSelect } from '@elastic/eui';
88
import { i18n } from '@kbn/i18n';
99
import React from 'react';
10-
import { useFetcher } from '../../../hooks/useFetcher';
1110
import { useLocation } from '../../../hooks/useLocation';
1211
import { useUrlParams } from '../../../hooks/useUrlParams';
1312
import { history } from '../../../utils/history';
@@ -16,6 +15,7 @@ import {
1615
ENVIRONMENT_ALL,
1716
ENVIRONMENT_NOT_DEFINED
1817
} from '../../../../common/environment_filter_values';
18+
import { useEnvironments, ALL_OPTION } from '../../../hooks/useEnvironments';
1919

2020
function updateEnvironmentUrl(
2121
location: ReturnType<typeof useLocation>,
@@ -32,13 +32,6 @@ function updateEnvironmentUrl(
3232
});
3333
}
3434

35-
const ALL_OPTION = {
36-
value: ENVIRONMENT_ALL,
37-
text: i18n.translate('xpack.apm.filter.environment.allLabel', {
38-
defaultMessage: 'All'
39-
})
40-
};
41-
4235
const NOT_DEFINED_OPTION = {
4336
value: ENVIRONMENT_NOT_DEFINED,
4437
text: i18n.translate('xpack.apm.filter.environment.notDefinedLabel', {
@@ -74,27 +67,15 @@ function getOptions(environments: string[]) {
7467

7568
export const EnvironmentFilter: React.FC = () => {
7669
const location = useLocation();
77-
const { urlParams, uiFilters } = useUrlParams();
78-
const { start, end, serviceName } = urlParams;
70+
const { uiFilters, urlParams } = useUrlParams();
7971

8072
const { environment } = uiFilters;
81-
const { data: environments = [], status = 'loading' } = useFetcher(
82-
callApmApi => {
83-
if (start && end) {
84-
return callApmApi({
85-
pathname: '/api/apm/ui_filters/environments',
86-
params: {
87-
query: {
88-
start,
89-
end,
90-
serviceName
91-
}
92-
}
93-
});
94-
}
95-
},
96-
[start, end, serviceName]
97-
);
73+
const { serviceName, start, end } = urlParams;
74+
const { environments, status = 'loading' } = useEnvironments({
75+
serviceName,
76+
start,
77+
end
78+
});
9879

9980
return (
10081
<EuiSelect

x-pack/plugins/apm/public/components/shared/ErrorRateAlertTrigger/index.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ import React from 'react';
77
import { EuiFieldNumber } from '@elastic/eui';
88
import { i18n } from '@kbn/i18n';
99
import { isFinite } from 'lodash';
10+
import { EuiSelect } from '@elastic/eui';
1011
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
1112
import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
1213
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
1314
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
15+
import { useEnvironments, ALL_OPTION } from '../../../hooks/useEnvironments';
16+
import { useUrlParams } from '../../../hooks/useUrlParams';
1417

1518
export interface ErrorRateAlertTriggerParams {
1619
windowSize: number;
1720
windowUnit: string;
1821
threshold: number;
22+
environment: string;
1923
}
2024

2125
interface Props {
@@ -27,10 +31,15 @@ interface Props {
2731
export function ErrorRateAlertTrigger(props: Props) {
2832
const { setAlertParams, setAlertProperty, alertParams } = props;
2933

34+
const { urlParams } = useUrlParams();
35+
const { serviceName, start, end } = urlParams;
36+
const { environmentOptions } = useEnvironments({ serviceName, start, end });
37+
3038
const defaults = {
3139
threshold: 25,
3240
windowSize: 1,
33-
windowUnit: 'm'
41+
windowUnit: 'm',
42+
environment: ALL_OPTION.value
3443
};
3544

3645
const params = {
@@ -41,6 +50,28 @@ export function ErrorRateAlertTrigger(props: Props) {
4150
const threshold = isFinite(params.threshold) ? params.threshold : '';
4251

4352
const fields = [
53+
<PopoverExpression
54+
value={
55+
params.environment === ALL_OPTION.value
56+
? ALL_OPTION.text
57+
: params.environment
58+
}
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>,
4475
<PopoverExpression
4576
title={i18n.translate('xpack.apm.errorRateAlertTrigger.isAbove', {
4677
defaultMessage: 'is above'

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
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 React from 'react';
7-
import { map } from 'lodash';
86
import { EuiFieldNumber, EuiSelect } from '@elastic/eui';
97
import { i18n } from '@kbn/i18n';
8+
import { map } from 'lodash';
9+
import React from 'react';
1010
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
1111
import {
12-
TRANSACTION_ALERT_AGGREGATION_TYPES,
13-
ALERT_TYPES_CONFIG
12+
ALERT_TYPES_CONFIG,
13+
TRANSACTION_ALERT_AGGREGATION_TYPES
1414
} from '../../../../common/alert_types';
15-
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
16-
import { useUrlParams } from '../../../hooks/useUrlParams';
15+
import { ALL_OPTION, useEnvironments } from '../../../hooks/useEnvironments';
1716
import { useServiceTransactionTypes } from '../../../hooks/useServiceTransactionTypes';
17+
import { useUrlParams } from '../../../hooks/useUrlParams';
18+
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
1819
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
1920

2021
interface Params {
@@ -24,6 +25,7 @@ interface Params {
2425
aggregationType: 'avg' | '95th' | '99th';
2526
serviceName: string;
2627
transactionType: string;
28+
environment: string;
2729
}
2830

2931
interface Props {
@@ -39,6 +41,9 @@ export function TransactionDurationAlertTrigger(props: Props) {
3941

4042
const transactionTypes = useServiceTransactionTypes(urlParams);
4143

44+
const { serviceName, start, end } = urlParams;
45+
const { environmentOptions } = useEnvironments({ serviceName, start, end });
46+
4247
if (!transactionTypes.length) {
4348
return null;
4449
}
@@ -48,7 +53,8 @@ export function TransactionDurationAlertTrigger(props: Props) {
4853
aggregationType: 'avg',
4954
windowSize: 5,
5055
windowUnit: 'm',
51-
transactionType: transactionTypes[0]
56+
transactionType: transactionTypes[0],
57+
environment: ALL_OPTION.value
5258
};
5359

5460
const params = {
@@ -57,6 +63,28 @@ export function TransactionDurationAlertTrigger(props: Props) {
5763
};
5864

5965
const fields = [
66+
<PopoverExpression
67+
value={
68+
params.environment === ALL_OPTION.value
69+
? ALL_OPTION.text
70+
: params.environment
71+
}
72+
title={i18n.translate(
73+
'xpack.apm.transactionDurationAlertTrigger.environment',
74+
{
75+
defaultMessage: 'Environment'
76+
}
77+
)}
78+
>
79+
<EuiSelect
80+
value={params.environment}
81+
options={environmentOptions}
82+
onChange={e =>
83+
setAlertParams('environment', e.target.value as Params['environment'])
84+
}
85+
compressed
86+
/>
87+
</PopoverExpression>,
6088
<PopoverExpression
6189
value={params.transactionType}
6290
title={i18n.translate('xpack.apm.transactionDurationAlertTrigger.type', {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { useMemo } from 'react';
8+
import { i18n } from '@kbn/i18n';
9+
import { useFetcher } from './useFetcher';
10+
import {
11+
ENVIRONMENT_NOT_DEFINED,
12+
ENVIRONMENT_ALL
13+
} from '../../common/environment_filter_values';
14+
import { callApmApi } from '../services/rest/createCallApmApi';
15+
16+
export const ALL_OPTION = {
17+
value: ENVIRONMENT_ALL,
18+
text: i18n.translate('xpack.apm.environment.allLabel', {
19+
defaultMessage: 'All'
20+
})
21+
};
22+
23+
function getEnvironmentOptions(environments: string[]) {
24+
const environmentOptions = environments
25+
.filter(env => env !== ENVIRONMENT_NOT_DEFINED)
26+
.map(environment => ({
27+
value: environment,
28+
text: environment
29+
}));
30+
31+
return [ALL_OPTION, ...environmentOptions];
32+
}
33+
34+
export function useEnvironments({
35+
serviceName,
36+
start,
37+
end
38+
}: {
39+
serviceName?: string;
40+
start?: string;
41+
end?: string;
42+
}) {
43+
const { data: environments = [], status = 'loading' } = useFetcher(() => {
44+
if (start && end) {
45+
return callApmApi({
46+
pathname: '/api/apm/ui_filters/environments',
47+
params: {
48+
query: {
49+
start,
50+
end,
51+
serviceName
52+
}
53+
}
54+
});
55+
}
56+
}, [start, end, serviceName]);
57+
58+
const environmentOptions = useMemo(
59+
() => getEnvironmentOptions(environments),
60+
[environments]
61+
);
62+
63+
return { environments, status, environmentOptions };
64+
}

x-pack/plugins/apm/server/lib/alerts/register_error_rate_alert_type.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import { schema, TypeOf } from '@kbn/config-schema';
88
import { Observable } from 'rxjs';
99
import { take } from 'rxjs/operators';
1010
import { i18n } from '@kbn/i18n';
11+
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
1112
import { AlertType, ALERT_TYPES_CONFIG } from '../../../common/alert_types';
1213
import {
1314
ESSearchResponse,
1415
ESSearchRequest
1516
} from '../../../typings/elasticsearch';
1617
import {
1718
PROCESSOR_EVENT,
18-
SERVICE_NAME
19+
SERVICE_NAME,
20+
SERVICE_ENVIRONMENT
1921
} from '../../../common/elasticsearch_fieldnames';
2022
import { AlertingPlugin } from '../../../../alerting/server';
2123
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
@@ -30,7 +32,8 @@ const paramsSchema = schema.object({
3032
serviceName: schema.string(),
3133
windowSize: schema.number(),
3234
windowUnit: schema.string(),
33-
threshold: schema.number()
35+
threshold: schema.number(),
36+
environment: schema.string()
3437
});
3538

3639
const alertTypeConfig = ALERT_TYPES_CONFIG[AlertType.ErrorRate];
@@ -70,6 +73,11 @@ export function registerErrorRateAlertType({
7073
savedObjectsClient: services.savedObjectsClient
7174
});
7275

76+
const environmentTerm =
77+
alertParams.environment === ENVIRONMENT_ALL
78+
? []
79+
: [{ term: { [SERVICE_ENVIRONMENT]: alertParams.environment } }];
80+
7381
const searchParams = {
7482
index: indices['apm_oss.errorIndices'],
7583
size: 0,
@@ -93,7 +101,8 @@ export function registerErrorRateAlertType({
93101
term: {
94102
[SERVICE_NAME]: alertParams.serviceName
95103
}
96-
}
104+
},
105+
...environmentTerm
97106
]
98107
}
99108
},

0 commit comments

Comments
 (0)