Skip to content

Commit 5f36a27

Browse files
authored
[Alerting] Moves the Index & Geo Threshold UIs into the Stack Alerts Public Plugin (#82951) (#83316)
This PR includes the following refactors: 1. Moves the Index Pattern Api from _Stack Alerts_ to the _Server_ plugin of _Trigger Actions UI_. This fixes a potential bug where a user could disable the _Stack Alerts_ plugin and inadvertently break the UI of the _ES Index _ action type. 2. Extracts the UI components for _Index Threshold_ and _Geo Threshold_ from the _Trigger Actions UI_ plugin and moves them into _Stack Alerts_. # Conflicts: # packages/kbn-optimizer/limits.yml
1 parent b9de2c8 commit 5f36a27

File tree

78 files changed

+1212
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1212
-896
lines changed

.eslintrc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,19 @@ module.exports = {
10391039
* Alerting Services overrides
10401040
*/
10411041
{
1042-
// typescript only for front and back end
1042+
// typescript for front and back end
10431043
files: ['x-pack/plugins/{alerts,stack_alerts,actions,task_manager,event_log}/**/*.{ts,tsx}'],
10441044
rules: {
10451045
'@typescript-eslint/no-explicit-any': 'error',
10461046
},
10471047
},
1048+
{
1049+
// typescript only for back end
1050+
files: ['x-pack/plugins/triggers_actions_ui/server/**/*.ts'],
1051+
rules: {
1052+
'@typescript-eslint/no-explicit-any': 'error',
1053+
},
1054+
},
10481055

10491056
/**
10501057
* Lens overrides

packages/kbn-optimizer/limits.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,4 @@ pageLoadAssetSize:
102102
visualizations: 295169
103103
visualize: 57433
104104
watcher: 43742
105+
stackAlerts: 29684

x-pack/plugins/stack_alerts/server/config.ts renamed to x-pack/plugins/stack_alerts/common/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { schema, TypeOf } from '@kbn/config-schema';
88

99
export const configSchema = schema.object({
1010
enabled: schema.boolean({ defaultValue: true }),
11+
enableGeoTrackingThresholdAlert: schema.boolean({ defaultValue: false }),
1112
});
1213

1314
export type Config = TypeOf<typeof configSchema>;

x-pack/plugins/stack_alerts/common/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
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-
6+
export * from './config';
77
export const STACK_ALERTS_FEATURE_ID = 'stackAlerts';

x-pack/plugins/stack_alerts/kibana.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"server": true,
44
"version": "8.0.0",
55
"kibanaVersion": "kibana",
6-
"requiredPlugins": ["alerts", "features"],
6+
"requiredPlugins": ["alerts", "features", "triggersActionsUi", "kibanaReact"],
77
"configPath": ["xpack", "stack_alerts"],
8-
"ui": false
8+
"ui": true
99
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
*/
66
import { lazy } from 'react';
77
import { i18n } from '@kbn/i18n';
8-
import { AlertTypeModel } from '../../../../types';
98
import { validateExpression } from './validation';
109
import { GeoThresholdAlertParams } from './types';
11-
import { AlertsContextValue } from '../../../context/alerts_context';
10+
import { AlertTypeModel, AlertsContextValue } from '../../../../triggers_actions_ui/public';
1211

1312
export function getAlertType(): AlertTypeModel<GeoThresholdAlertParams, AlertsContextValue> {
1413
return {
1514
id: '.geo-threshold',
16-
name: i18n.translate('xpack.triggersActionsUI.geoThreshold.name.trackingThreshold', {
15+
name: i18n.translate('xpack.stackAlerts.geoThreshold.name.trackingThreshold', {
1716
defaultMessage: 'Tracking threshold',
1817
}),
19-
description: i18n.translate('xpack.triggersActionsUI.geoThreshold.descriptionText', {
18+
description: i18n.translate('xpack.stackAlerts.geoThreshold.descriptionText', {
2019
defaultMessage: 'Alert when an entity enters or leaves a geo boundary.',
2120
}),
2221
iconClass: 'globe',
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
import React, { Fragment, FunctionComponent, useEffect, useRef } from 'react';
88
import { EuiFormRow } from '@elastic/eui';
99
import { i18n } from '@kbn/i18n';
10-
import { IErrorObject } from '../../../../../../types';
10+
import { IErrorObject, AlertsContextValue } from '../../../../../../triggers_actions_ui/public';
1111
import { ES_GEO_SHAPE_TYPES, GeoThresholdAlertParams } from '../../types';
12-
import { AlertsContextValue } from '../../../../../context/alerts_context';
1312
import { GeoIndexPatternSelect } from '../util_components/geo_index_pattern_select';
1413
import { SingleFieldSelect } from '../util_components/single_field_select';
1514
import { ExpressionWithPopover } from '../util_components/expression_with_popover';
16-
import { IFieldType } from '../../../../../../../../../../src/plugins/data/common/index_patterns/fields';
17-
import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/common/index_patterns';
15+
import { IFieldType } from '../../../../../../../../src/plugins/data/common/index_patterns/fields';
16+
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns';
1817

1918
interface Props {
2019
alertParams: GeoThresholdAlertParams;
@@ -117,12 +116,12 @@ export const BoundaryIndexExpression: FunctionComponent<Props> = ({
117116
<EuiFormRow
118117
id="geoField"
119118
fullWidth
120-
label={i18n.translate('xpack.triggersActionsUI.geoThreshold.geofieldLabel', {
119+
label={i18n.translate('xpack.stackAlerts.geoThreshold.geofieldLabel', {
121120
defaultMessage: 'Geospatial field',
122121
})}
123122
>
124123
<SingleFieldSelect
125-
placeholder={i18n.translate('xpack.triggersActionsUI.geoThreshold.selectLabel', {
124+
placeholder={i18n.translate('xpack.stackAlerts.geoThreshold.selectLabel', {
126125
defaultMessage: 'Select geo field',
127126
})}
128127
value={boundaryGeoField}
@@ -133,12 +132,12 @@ export const BoundaryIndexExpression: FunctionComponent<Props> = ({
133132
<EuiFormRow
134133
id="boundaryNameFieldSelect"
135134
fullWidth
136-
label={i18n.translate('xpack.triggersActionsUI.geoThreshold.boundaryNameSelectLabel', {
135+
label={i18n.translate('xpack.stackAlerts.geoThreshold.boundaryNameSelectLabel', {
137136
defaultMessage: 'Human-readable boundary name (optional)',
138137
})}
139138
>
140139
<SingleFieldSelect
141-
placeholder={i18n.translate('xpack.triggersActionsUI.geoThreshold.boundaryNameSelect', {
140+
placeholder={i18n.translate('xpack.stackAlerts.geoThreshold.boundaryNameSelect', {
142141
defaultMessage: 'Select boundary name',
143142
})}
144143
value={boundaryNameField || null}
@@ -156,7 +155,7 @@ export const BoundaryIndexExpression: FunctionComponent<Props> = ({
156155
defaultValue={'Select an index pattern and geo shape field'}
157156
value={boundaryIndexPattern.title}
158157
popoverContent={indexPopover}
159-
expressionDescription={i18n.translate('xpack.triggersActionsUI.geoThreshold.indexLabel', {
158+
expressionDescription={i18n.translate('xpack.stackAlerts.geoThreshold.indexLabel', {
160159
defaultMessage: 'index',
161160
})}
162161
/>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import React, { FunctionComponent, useEffect, useRef } from 'react';
88
import { EuiFormRow } from '@elastic/eui';
99
import { i18n } from '@kbn/i18n';
1010
import _ from 'lodash';
11-
import { IErrorObject } from '../../../../../../types';
11+
import { IErrorObject } from '../../../../../../triggers_actions_ui/public';
1212
import { SingleFieldSelect } from '../util_components/single_field_select';
1313
import { ExpressionWithPopover } from '../util_components/expression_with_popover';
14-
import { IFieldType } from '../../../../../../../../../../src/plugins/data/common/index_patterns/fields';
14+
import { IFieldType } from '../../../../../../../../src/plugins/data/common/index_patterns/fields';
1515

1616
interface Props {
1717
errors: IErrorObject;
@@ -59,7 +59,7 @@ export const EntityByExpression: FunctionComponent<Props> = ({
5959
<EuiFormRow id="entitySelect" fullWidth error={errors.index}>
6060
<SingleFieldSelect
6161
placeholder={i18n.translate(
62-
'xpack.triggersActionsUI.geoThreshold.topHitsSplitFieldSelectPlaceholder',
62+
'xpack.stackAlerts.geoThreshold.topHitsSplitFieldSelectPlaceholder',
6363
{
6464
defaultMessage: 'Select entity field',
6565
}
@@ -77,7 +77,7 @@ export const EntityByExpression: FunctionComponent<Props> = ({
7777
value={entity}
7878
defaultValue={'Select entity field'}
7979
popoverContent={indexPopover}
80-
expressionDescription={i18n.translate('xpack.triggersActionsUI.geoThreshold.entityByLabel', {
80+
expressionDescription={i18n.translate('xpack.stackAlerts.geoThreshold.entityByLabel', {
8181
defaultMessage: 'by',
8282
})}
8383
/>
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import React, { Fragment, FunctionComponent, useEffect, useRef } from 'react';
88
import { EuiFormRow } from '@elastic/eui';
99
import { FormattedMessage } from '@kbn/i18n/react';
1010
import { i18n } from '@kbn/i18n';
11-
import { IErrorObject } from '../../../../../../types';
11+
import { IErrorObject, AlertsContextValue } from '../../../../../../triggers_actions_ui/public';
1212
import { ES_GEO_FIELD_TYPES } from '../../types';
13-
import { AlertsContextValue } from '../../../../../context/alerts_context';
1413
import { GeoIndexPatternSelect } from '../util_components/geo_index_pattern_select';
1514
import { SingleFieldSelect } from '../util_components/single_field_select';
1615
import { ExpressionWithPopover } from '../util_components/expression_with_popover';
17-
import { IFieldType } from '../../../../../../../../../../src/plugins/data/common/index_patterns/fields';
18-
import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/common/index_patterns';
16+
import { IFieldType } from '../../../../../../../../src/plugins/data/common/index_patterns/fields';
17+
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns';
1918

2019
interface Props {
2120
dateField: string;
@@ -105,13 +104,13 @@ export const EntityIndexExpression: FunctionComponent<Props> = ({
105104
fullWidth
106105
label={
107106
<FormattedMessage
108-
id="xpack.triggersActionsUI.geoThreshold.timeFieldLabel"
107+
id="xpack.stackAlerts.geoThreshold.timeFieldLabel"
109108
defaultMessage="Time field"
110109
/>
111110
}
112111
>
113112
<SingleFieldSelect
114-
placeholder={i18n.translate('xpack.triggersActionsUI.geoThreshold.selectTimeLabel', {
113+
placeholder={i18n.translate('xpack.stackAlerts.geoThreshold.selectTimeLabel', {
115114
defaultMessage: 'Select time field',
116115
})}
117116
value={timeField}
@@ -124,12 +123,12 @@ export const EntityIndexExpression: FunctionComponent<Props> = ({
124123
<EuiFormRow
125124
id="geoField"
126125
fullWidth
127-
label={i18n.translate('xpack.triggersActionsUI.geoThreshold.geofieldLabel', {
126+
label={i18n.translate('xpack.stackAlerts.geoThreshold.geofieldLabel', {
128127
defaultMessage: 'Geospatial field',
129128
})}
130129
>
131130
<SingleFieldSelect
132-
placeholder={i18n.translate('xpack.triggersActionsUI.geoThreshold.selectGeoLabel', {
131+
placeholder={i18n.translate('xpack.stackAlerts.geoThreshold.selectGeoLabel', {
133132
defaultMessage: 'Select geo field',
134133
})}
135134
value={geoField}
@@ -148,12 +147,9 @@ export const EntityIndexExpression: FunctionComponent<Props> = ({
148147
value={indexPattern.title}
149148
defaultValue={'Select an index pattern and geo shape/point field'}
150149
popoverContent={indexPopover}
151-
expressionDescription={i18n.translate(
152-
'xpack.triggersActionsUI.geoThreshold.entityIndexLabel',
153-
{
154-
defaultMessage: 'index',
155-
}
156-
)}
150+
expressionDescription={i18n.translate('xpack.stackAlerts.geoThreshold.entityIndexLabel', {
151+
defaultMessage: 'index',
152+
})}
157153
/>
158154
);
159155
};
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ import {
1919
} from '@elastic/eui';
2020
import { FormattedMessage } from '@kbn/i18n/react';
2121
import { i18n } from '@kbn/i18n';
22-
import { AlertTypeParamsExpressionProps } from '../../../../../types';
22+
import {
23+
AlertTypeParamsExpressionProps,
24+
getTimeOptions,
25+
AlertsContextValue,
26+
} from '../../../../../triggers_actions_ui/public';
2327
import { GeoThresholdAlertParams, TrackingEvent } from '../types';
24-
import { AlertsContextValue } from '../../../../context/alerts_context';
2528
import { ExpressionWithPopover } from './util_components/expression_with_popover';
2629
import { EntityIndexExpression } from './expressions/entity_index_expression';
2730
import { EntityByExpression } from './expressions/entity_by_expression';
2831
import { BoundaryIndexExpression } from './expressions/boundary_index_expression';
29-
import { IIndexPattern } from '../../../../../../../../../src/plugins/data/common/index_patterns';
30-
import { getTimeOptions } from '../../../../../common/lib/get_time_options';
32+
import { IIndexPattern } from '../../../../../../../src/plugins/data/common/index_patterns';
3133

3234
const DEFAULT_VALUES = {
3335
TRACKING_EVENT: '',
@@ -45,20 +47,20 @@ const DEFAULT_VALUES = {
4547
};
4648

4749
const conditionOptions = Object.keys(TrackingEvent).map((key) => ({
48-
text: (TrackingEvent as any)[key],
49-
value: (TrackingEvent as any)[key],
50+
text: TrackingEvent[key as TrackingEvent],
51+
value: TrackingEvent[key as TrackingEvent],
5052
}));
5153

5254
const labelForDelayOffset = (
5355
<>
5456
<FormattedMessage
55-
id="xpack.triggersActionsUI.geoThreshold.delayOffset"
57+
id="xpack.stackAlerts.geoThreshold.delayOffset"
5658
defaultMessage="Delayed evaluation offset"
5759
/>{' '}
5860
<EuiIconTip
5961
position="right"
6062
type="questionInCircle"
61-
content={i18n.translate('xpack.triggersActionsUI.geoThreshold.delayOffsetTooltip', {
63+
content={i18n.translate('xpack.stackAlerts.geoThreshold.delayOffsetTooltip', {
6264
defaultMessage: 'Evaluate alerts on a delayed cycle to adjust for data latency',
6365
})}
6466
/>
@@ -125,7 +127,7 @@ export const GeoThresholdAlertTypeExpression: React.FunctionComponent<AlertTypeP
125127

126128
const hasExpressionErrors = false;
127129
const expressionErrorMessage = i18n.translate(
128-
'xpack.triggersActionsUI.geoThreshold.fixErrorInExpressionBelowValidationMessage',
130+
'xpack.stackAlerts.geoThreshold.fixErrorInExpressionBelowValidationMessage',
129131
{
130132
defaultMessage: 'Expression contains errors.',
131133
}
@@ -180,7 +182,7 @@ export const GeoThresholdAlertTypeExpression: React.FunctionComponent<AlertTypeP
180182
<EuiTitle size="xs">
181183
<h5>
182184
<FormattedMessage
183-
id="xpack.triggersActionsUI.geoThreshold.selectOffset"
185+
id="xpack.stackAlerts.geoThreshold.selectOffset"
184186
defaultMessage="Select offset (optional)"
185187
/>
186188
</h5>
@@ -221,7 +223,7 @@ export const GeoThresholdAlertTypeExpression: React.FunctionComponent<AlertTypeP
221223
<EuiTitle size="xs">
222224
<h5>
223225
<FormattedMessage
224-
id="xpack.triggersActionsUI.geoThreshold.selectEntity"
226+
id="xpack.stackAlerts.geoThreshold.selectEntity"
225227
defaultMessage="Select entity"
226228
/>
227229
</h5>
@@ -251,7 +253,7 @@ export const GeoThresholdAlertTypeExpression: React.FunctionComponent<AlertTypeP
251253
<EuiTitle size="xs">
252254
<h5>
253255
<FormattedMessage
254-
id="xpack.triggersActionsUI.geoThreshold.selectIndex"
256+
id="xpack.stackAlerts.geoThreshold.selectIndex"
255257
defaultMessage="Define the condition"
256258
/>
257259
</h5>
@@ -280,19 +282,16 @@ export const GeoThresholdAlertTypeExpression: React.FunctionComponent<AlertTypeP
280282
</div>
281283
</EuiFormRow>
282284
}
283-
expressionDescription={i18n.translate(
284-
'xpack.triggersActionsUI.geoThreshold.whenEntityLabel',
285-
{
286-
defaultMessage: 'when entity',
287-
}
288-
)}
285+
expressionDescription={i18n.translate('xpack.stackAlerts.geoThreshold.whenEntityLabel', {
286+
defaultMessage: 'when entity',
287+
})}
289288
/>
290289

291290
<EuiSpacer size="l" />
292291
<EuiTitle size="xs">
293292
<h5>
294293
<FormattedMessage
295-
id="xpack.triggersActionsUI.geoThreshold.selectBoundaryIndex"
294+
id="xpack.stackAlerts.geoThreshold.selectBoundaryIndex"
296295
defaultMessage="Select boundary:"
297296
/>
298297
</h5>

0 commit comments

Comments
 (0)