-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathindex.ts
More file actions
89 lines (80 loc) · 2.49 KB
/
Copy pathindex.ts
File metadata and controls
89 lines (80 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ApiKeyType } from '../task_runner/types';
import type { RawAlertInstance } from '../../common';
import type { AlertingConfig } from '../config';
export { getRulesClientMockParams } from './rules_client_mock';
export type { RulesClientMock } from './rules_client_mock';
interface Resolvable<T> {
resolve: (arg: T) => void;
}
/**
* Creates a promise which can be resolved externally, useful for
* coordinating async tests.
*/
export function resolvable<T>(): Promise<T> & Resolvable<T> {
let resolve: (arg: T) => void;
return Object.assign(new Promise<T>((r) => (resolve = r)), {
resolve(arg: T) {
return setTimeout(() => resolve(arg), 0);
},
});
}
// Used to convert a raw Rule's UUID to something that can be used
// to compare with a jest snapshot.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function alertWithAnyUUID(rawAlert: Record<string, any>): Record<string, any> {
if (!rawAlert?.meta?.uuid) return rawAlert;
const newAlert = JSON.parse(JSON.stringify(rawAlert));
newAlert.meta.uuid = expect.any(String);
return newAlert;
}
export function alertsWithAnyUUID(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
rawAlerts: Record<string, any>
): Record<string, RawAlertInstance> {
const newAlerts: Record<string, RawAlertInstance> = {};
for (const id of Object.keys(rawAlerts)) {
newAlerts[id] = alertWithAnyUUID(rawAlerts[id]);
}
return newAlerts;
}
export function generateAlertingConfig(overwrites: Partial<AlertingConfig> = {}): AlertingConfig {
return {
healthCheck: {
interval: '5m',
},
enableFrameworkAlerts: false,
alertsService: {
totalFieldsLimit: 2800,
coordinateInstallation: true,
},
ruleChangeTracking: {
scope: ['security'],
},
invalidateApiKeysTask: {
interval: '5m',
removalDelay: '1h',
},
cancelAlertsOnRuleTimeout: true,
rules: {
maxScheduledPerMinute: 10000,
minimumScheduleInterval: { value: '1m', enforce: false },
run: {
actions: {
max: 1000,
},
alerts: {
max: 1000,
},
},
apiKeyType: ApiKeyType.ES,
},
rulesSettings: { enabled: true, cacheInterval: 60000 },
...overwrites,
};
}