Skip to content

Commit d909a96

Browse files
author
Tyler Smalley
committed
Revert "[APM] Alerting: Show preview as chart of threshold (#84080)"
This reverts commit 9986aff.
1 parent 12c40f7 commit d909a96

File tree

24 files changed

+43
-774
lines changed

24 files changed

+43
-774
lines changed

x-pack/plugins/apm/public/application/action_menu/alerting_popover_flyout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n';
1414
import React, { useState } from 'react';
1515
import { IBasePath } from '../../../../../../src/core/public';
1616
import { AlertType } from '../../../common/alert_types';
17-
import { AlertingFlyout } from '../../components/alerting/alerting_flyout';
17+
import { AlertingFlyout } from '../../components/alerting/AlertingFlyout';
1818

1919
const alertLabel = i18n.translate('xpack.apm.home.alertsMenu.alerts', {
2020
defaultMessage: 'Alerts',

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

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ import { i18n } from '@kbn/i18n';
88
import React from 'react';
99
import { useParams } from 'react-router-dom';
1010
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
11-
import { AlertType, ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
11+
import { ALERT_TYPES_CONFIG, AlertType } from '../../../../common/alert_types';
1212
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
13-
import { asInteger } from '../../../../common/utils/formatters';
14-
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
1513
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
16-
import { useFetcher } from '../../../hooks/use_fetcher';
17-
import { callApmApi } from '../../../services/rest/createCallApmApi';
18-
import { ChartPreview } from '../chart_preview';
19-
import { EnvironmentField, IsAboveField, ServiceField } from '../fields';
20-
import { getAbsoluteTimeRange } from '../helper';
21-
import { ServiceAlertTrigger } from '../service_alert_trigger';
14+
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
15+
import { EnvironmentField, ServiceField, IsAboveField } from '../fields';
16+
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
2217

2318
export interface AlertParams {
2419
windowSize: number;
@@ -45,23 +40,6 @@ export function ErrorCountAlertTrigger(props: Props) {
4540
end,
4641
});
4742

48-
const { threshold, windowSize, windowUnit, environment } = alertParams;
49-
50-
const { data } = useFetcher(() => {
51-
if (windowSize && windowUnit) {
52-
return callApmApi({
53-
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_error_count',
54-
params: {
55-
query: {
56-
...getAbsoluteTimeRange(windowSize, windowUnit),
57-
environment,
58-
serviceName,
59-
},
60-
},
61-
});
62-
}
63-
}, [windowSize, windowUnit, environment, serviceName]);
64-
6543
const defaults = {
6644
threshold: 25,
6745
windowSize: 1,
@@ -86,14 +64,14 @@ export function ErrorCountAlertTrigger(props: Props) {
8664
unit={i18n.translate('xpack.apm.errorCountAlertTrigger.errors', {
8765
defaultMessage: ' errors',
8866
})}
89-
onChange={(value) => setAlertParams('threshold', value || 0)}
67+
onChange={(value) => setAlertParams('threshold', value)}
9068
/>,
9169
<ForLastExpression
92-
onChangeWindowSize={(timeWindowSize) =>
93-
setAlertParams('windowSize', timeWindowSize || '')
70+
onChangeWindowSize={(windowSize) =>
71+
setAlertParams('windowSize', windowSize || '')
9472
}
95-
onChangeWindowUnit={(timeWindowUnit) =>
96-
setAlertParams('windowUnit', timeWindowUnit)
73+
onChangeWindowUnit={(windowUnit) =>
74+
setAlertParams('windowUnit', windowUnit)
9775
}
9876
timeWindowSize={params.windowSize}
9977
timeWindowUnit={params.windowUnit}
@@ -104,18 +82,13 @@ export function ErrorCountAlertTrigger(props: Props) {
10482
/>,
10583
];
10684

107-
const chartPreview = (
108-
<ChartPreview data={data} threshold={threshold} yTickFormat={asInteger} />
109-
);
110-
11185
return (
11286
<ServiceAlertTrigger
11387
alertTypeName={ALERT_TYPES_CONFIG[AlertType.ErrorCount].name}
11488
defaults={defaults}
11589
fields={fields}
11690
setAlertParams={setAlertParams}
11791
setAlertProperty={setAlertProperty}
118-
chartPreview={chartPreview}
11992
/>
12093
);
12194
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { EuiFlexGrid, EuiFlexItem, EuiSpacer } from '@elastic/eui';
87
import React, { useEffect } from 'react';
8+
import { EuiSpacer, EuiFlexGrid, EuiFlexItem } from '@elastic/eui';
99
import { useParams } from 'react-router-dom';
1010

1111
interface Props {
@@ -14,7 +14,6 @@ interface Props {
1414
setAlertProperty: (key: string, value: any) => void;
1515
defaults: Record<string, any>;
1616
fields: React.ReactNode[];
17-
chartPreview?: React.ReactNode;
1817
}
1918

2019
export function ServiceAlertTrigger(props: Props) {
@@ -26,7 +25,6 @@ export function ServiceAlertTrigger(props: Props) {
2625
setAlertProperty,
2726
alertTypeName,
2827
defaults,
29-
chartPreview,
3028
} = props;
3129

3230
const params: Record<string, any> = {
@@ -63,7 +61,6 @@ export function ServiceAlertTrigger(props: Props) {
6361
</EuiFlexItem>
6462
))}
6563
</EuiFlexGrid>
66-
{chartPreview}
6764
<EuiSpacer size="m" />
6865
</>
6966
);
Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { EuiSelect } 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';
10-
import { useParams } from 'react-router-dom';
11-
import { useFetcher } from '../../../../../observability/public';
1211
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
1312
import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
14-
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
15-
import { TimeSeries } from '../../../../typings/timeseries';
16-
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
17-
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
1813
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
19-
import { callApmApi } from '../../../services/rest/createCallApmApi';
20-
import { getResponseTimeTickFormatter } from '../../shared/charts/transaction_charts/helper';
21-
import { useFormatter } from '../../shared/charts/transaction_charts/use_formatter';
22-
import { ChartPreview } from '../chart_preview';
14+
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
15+
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
16+
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
17+
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
2318
import {
2419
EnvironmentField,
25-
IsAboveField,
2620
ServiceField,
2721
TransactionTypeField,
22+
IsAboveField,
2823
} from '../fields';
29-
import { getAbsoluteTimeRange } from '../helper';
30-
import { ServiceAlertTrigger } from '../service_alert_trigger';
31-
import { PopoverExpression } from '../service_alert_trigger/popover_expression';
24+
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
3225

3326
interface AlertParams {
3427
windowSize: number;
@@ -70,58 +63,14 @@ interface Props {
7063
export function TransactionDurationAlertTrigger(props: Props) {
7164
const { setAlertParams, alertParams, setAlertProperty } = props;
7265
const { urlParams } = useUrlParams();
73-
const { transactionTypes, transactionType } = useApmServiceContext();
66+
const { transactionTypes } = useApmServiceContext();
7467
const { serviceName } = useParams<{ serviceName?: string }>();
75-
const { start, end } = urlParams;
68+
const { start, end, transactionType } = urlParams;
7669
const { environmentOptions } = useEnvironmentsFetcher({
7770
serviceName,
7871
start,
7972
end,
8073
});
81-
const {
82-
aggregationType,
83-
environment,
84-
threshold,
85-
windowSize,
86-
windowUnit,
87-
} = alertParams;
88-
89-
const { data } = useFetcher(() => {
90-
if (windowSize && windowUnit) {
91-
return callApmApi({
92-
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_duration',
93-
params: {
94-
query: {
95-
...getAbsoluteTimeRange(windowSize, windowUnit),
96-
aggregationType,
97-
environment,
98-
serviceName,
99-
transactionType: alertParams.transactionType,
100-
},
101-
},
102-
});
103-
}
104-
}, [
105-
aggregationType,
106-
environment,
107-
serviceName,
108-
alertParams.transactionType,
109-
windowSize,
110-
windowUnit,
111-
]);
112-
113-
const { formatter } = useFormatter([{ data: data ?? [] } as TimeSeries]);
114-
const yTickFormat = getResponseTimeTickFormatter(formatter);
115-
// The threshold from the form is in ms. Convert to µs.
116-
const thresholdMs = threshold * 1000;
117-
118-
const chartPreview = (
119-
<ChartPreview
120-
data={data}
121-
threshold={thresholdMs}
122-
yTickFormat={yTickFormat}
123-
/>
124-
);
12574

12675
if (!transactionTypes.length || !serviceName) {
12776
return null;
@@ -132,7 +81,9 @@ export function TransactionDurationAlertTrigger(props: Props) {
13281
aggregationType: 'avg',
13382
windowSize: 5,
13483
windowUnit: 'm',
135-
transactionType,
84+
85+
// use the current transaction type or default to the first in the list
86+
transactionType: transactionType || transactionTypes[0],
13687
environment: urlParams.environment || ENVIRONMENT_ALL.value,
13788
};
13889

@@ -176,7 +127,7 @@ export function TransactionDurationAlertTrigger(props: Props) {
176127
unit={i18n.translate('xpack.apm.transactionDurationAlertTrigger.ms', {
177128
defaultMessage: 'ms',
178129
})}
179-
onChange={(value) => setAlertParams('threshold', value || 0)}
130+
onChange={(value) => setAlertParams('threshold', value)}
180131
/>,
181132
<ForLastExpression
182133
onChangeWindowSize={(timeWindowSize) =>
@@ -197,9 +148,8 @@ export function TransactionDurationAlertTrigger(props: Props) {
197148
return (
198149
<ServiceAlertTrigger
199150
alertTypeName={ALERT_TYPES_CONFIG['apm.transaction_duration'].name}
200-
chartPreview={chartPreview}
201-
defaults={defaults}
202151
fields={fields}
152+
defaults={defaults}
203153
setAlertParams={setAlertParams}
204154
setAlertProperty={setAlertProperty}
205155
/>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { ANOMALY_SEVERITY } from '../../../../../ml/common';
1111
import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
1212
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
1313
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
14-
import { ServiceAlertTrigger } from '../service_alert_trigger';
15-
import { PopoverExpression } from '../service_alert_trigger/popover_expression';
14+
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
15+
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
1616
import {
1717
AnomalySeverity,
1818
SelectAnomalySeverity,

0 commit comments

Comments
 (0)