Skip to content

Commit 051be28

Browse files
committed
Revert "[Alerting] Enforces typing of Alert's ActionGroups (#86761)"
This reverts commit 76b8c49.
1 parent 7ed089c commit 051be28

File tree

69 files changed

+328
-1006
lines changed

Some content is hidden

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

69 files changed

+328
-1006
lines changed

x-pack/examples/alerting_example/common/constants.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ export const ALERTING_EXAMPLE_APP_ID = 'AlertingExample';
1010

1111
// always firing
1212
export const DEFAULT_INSTANCES_TO_GENERATE = 5;
13-
export interface AlwaysFiringThresholds {
14-
small?: number;
15-
medium?: number;
16-
large?: number;
17-
}
1813
export interface AlwaysFiringParams extends AlertTypeParams {
1914
instances?: number;
20-
thresholds?: AlwaysFiringThresholds;
15+
thresholds?: {
16+
small?: number;
17+
medium?: number;
18+
large?: number;
19+
};
2120
}
22-
export type AlwaysFiringActionGroupIds = keyof AlwaysFiringThresholds;
21+
export type AlwaysFiringActionGroupIds = keyof AlwaysFiringParams['thresholds'];
2322

2423
// Astros
2524
export enum Craft {

x-pack/examples/alerting_example/public/alert_types/always_firing.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ export const AlwaysFiringExpression: React.FunctionComponent<
133133
};
134134

135135
interface TShirtSelectorProps {
136-
actionGroup?: ActionGroupWithCondition<number, AlwaysFiringActionGroupIds>;
137-
setTShirtThreshold: (
138-
actionGroup: ActionGroupWithCondition<number, AlwaysFiringActionGroupIds>
139-
) => void;
136+
actionGroup?: ActionGroupWithCondition<number>;
137+
setTShirtThreshold: (actionGroup: ActionGroupWithCondition<number>) => void;
140138
}
141139
const TShirtSelector = ({ actionGroup, setTShirtThreshold }: TShirtSelectorProps) => {
142140
const [isOpen, setIsOpen] = useState(false);

x-pack/examples/alerting_example/server/alert_types/always_firing.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
DEFAULT_INSTANCES_TO_GENERATE,
1212
ALERTING_EXAMPLE_APP_ID,
1313
AlwaysFiringParams,
14-
AlwaysFiringActionGroupIds,
1514
} from '../../common/constants';
1615

1716
type ActionGroups = 'small' | 'medium' | 'large';
@@ -40,8 +39,7 @@ export const alertType: AlertType<
4039
AlwaysFiringParams,
4140
{ count?: number },
4241
{ triggerdOnCycle: number },
43-
never,
44-
AlwaysFiringActionGroupIds
42+
never
4543
> = {
4644
id: 'example.always-firing',
4745
name: 'Always firing',

x-pack/examples/alerting_example/server/alert_types/astros.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ function getCraftFilter(craft: string) {
4141
export const alertType: AlertType<
4242
{ outerSpaceCapacity: number; craft: string; op: string },
4343
{ peopleInSpace: number },
44-
{ craft: string },
45-
never,
46-
'default',
47-
'hasLandedBackOnEarth'
44+
{ craft: string }
4845
> = {
4946
id: 'example.people-in-space',
5047
name: 'People In Space Right Now',

x-pack/plugins/alerts/README.md

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -142,41 +142,8 @@ This example receives server and threshold as parameters. It will read the CPU u
142142

143143
```typescript
144144
import { schema } from '@kbn/config-schema';
145-
import {
146-
Alert,
147-
AlertTypeParams,
148-
AlertTypeState,
149-
AlertInstanceState,
150-
AlertInstanceContext
151-
} from 'x-pack/plugins/alerts/common';
152145
...
153-
interface MyAlertTypeParams extends AlertTypeParams {
154-
server: string;
155-
threshold: number;
156-
}
157-
158-
interface MyAlertTypeState extends AlertTypeState {
159-
lastChecked: number;
160-
}
161-
162-
interface MyAlertTypeInstanceState extends AlertInstanceState {
163-
cpuUsage: number;
164-
}
165-
166-
interface MyAlertTypeInstanceContext extends AlertInstanceContext {
167-
server: string;
168-
hasCpuUsageIncreased: boolean;
169-
}
170-
171-
type MyAlertTypeActionGroups = 'default' | 'warning';
172-
173-
const myAlertType: AlertType<
174-
MyAlertTypeParams,
175-
MyAlertTypeState,
176-
MyAlertTypeInstanceState,
177-
MyAlertTypeInstanceContext,
178-
MyAlertTypeActionGroups
179-
> = {
146+
server.newPlatform.setup.plugins.alerts.registerType({
180147
id: 'my-alert-type',
181148
name: 'My alert type',
182149
validate: {
@@ -213,7 +180,7 @@ const myAlertType: AlertType<
213180
services,
214181
params,
215182
state,
216-
}: AlertExecutorOptions<MyAlertTypeParams, MyAlertTypeState, MyAlertTypeInstanceState, MyAlertTypeInstanceContext, MyAlertTypeActionGroups>) {
183+
}: AlertExecutorOptions) {
217184
// Let's assume params is { server: 'server_1', threshold: 0.8 }
218185
const { server, threshold } = params;
219186

@@ -252,9 +219,7 @@ const myAlertType: AlertType<
252219
};
253220
},
254221
producer: 'alerting',
255-
};
256-
257-
server.newPlatform.setup.plugins.alerts.registerType(myAlertType);
222+
});
258223
```
259224

260225
This example only receives threshold as a parameter. It will read the CPU usage of all the servers and schedule individual actions if the reading for a server is greater than the threshold. This is a better implementation than above as only one query is performed for all the servers instead of one query per server.

x-pack/plugins/alerts/common/alert_type.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,19 @@
55
*/
66

77
import { LicenseType } from '../../licensing/common/types';
8-
import { RecoveredActionGroupId, DefaultActionGroupId } from './builtin_action_groups';
98

10-
export interface AlertType<
11-
ActionGroupIds extends Exclude<string, RecoveredActionGroupId> = DefaultActionGroupId,
12-
RecoveryActionGroupId extends string = RecoveredActionGroupId
13-
> {
9+
export interface AlertType {
1410
id: string;
1511
name: string;
16-
actionGroups: Array<ActionGroup<ActionGroupIds>>;
17-
recoveryActionGroup: ActionGroup<RecoveryActionGroupId>;
12+
actionGroups: ActionGroup[];
13+
recoveryActionGroup: ActionGroup;
1814
actionVariables: string[];
19-
defaultActionGroupId: ActionGroupIds;
15+
defaultActionGroupId: ActionGroup['id'];
2016
producer: string;
2117
minimumLicenseRequired: LicenseType;
2218
}
2319

24-
export interface ActionGroup<ActionGroupIds extends string> {
25-
id: ActionGroupIds;
20+
export interface ActionGroup {
21+
id: string;
2622
name: string;
2723
}
28-
29-
export type ActionGroupIdsOf<T> = T extends ActionGroup<infer groups>
30-
? groups
31-
: T extends Readonly<ActionGroup<infer groups>>
32-
? groups
33-
: never;

x-pack/plugins/alerts/common/builtin_action_groups.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,13 @@
66
import { i18n } from '@kbn/i18n';
77
import { ActionGroup } from './alert_type';
88

9-
export type DefaultActionGroupId = 'default';
10-
11-
export type RecoveredActionGroupId = typeof RecoveredActionGroup['id'];
12-
export const RecoveredActionGroup: Readonly<ActionGroup<'recovered'>> = Object.freeze({
9+
export const RecoveredActionGroup: Readonly<ActionGroup> = {
1310
id: 'recovered',
1411
name: i18n.translate('xpack.alerts.builtinActionGroups.recovered', {
1512
defaultMessage: 'Recovered',
1613
}),
17-
});
18-
19-
export type ReservedActionGroups<RecoveryActionGroupId extends string> =
20-
| RecoveryActionGroupId
21-
| RecoveredActionGroupId;
22-
23-
export type WithoutReservedActionGroups<
24-
ActionGroupIds extends string,
25-
RecoveryActionGroupId extends string
26-
> = ActionGroupIds extends ReservedActionGroups<RecoveryActionGroupId> ? never : ActionGroupIds;
14+
};
2715

28-
export function getBuiltinActionGroups<RecoveryActionGroupId extends string>(
29-
customRecoveryGroup?: ActionGroup<RecoveryActionGroupId>
30-
): [ActionGroup<ReservedActionGroups<RecoveryActionGroupId>>] {
31-
return [customRecoveryGroup ?? RecoveredActionGroup];
16+
export function getBuiltinActionGroups(customRecoveryGroup?: ActionGroup): ActionGroup[] {
17+
return [customRecoveryGroup ?? Object.freeze(RecoveredActionGroup)];
3218
}

0 commit comments

Comments
 (0)