-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Response Ops][Rule Form V2] Move dependencies from triggers actions …
…UI to shared package (#184977) ## Summary Issue: #179105 Related PR: #180539 Part 2.5/3 PRs of the new rule form. This PR acts as the foundation PR for the main rule form PR by moving a lot of the dependencies needed by the rules form to a shared package. So no new features added, just moving stuff around. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
4afcc0a
commit a25ccec
Showing
97 changed files
with
1,914 additions
and
631 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/kbn-alerting-types/alerting_framework_health_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export enum HealthStatus { | ||
OK = 'ok', | ||
Warning = 'warn', | ||
Error = 'error', | ||
} | ||
|
||
export interface AlertsHealth { | ||
decryptionHealth: { | ||
status: HealthStatus; | ||
timestamp: string; | ||
}; | ||
executionHealth: { | ||
status: HealthStatus; | ||
timestamp: string; | ||
}; | ||
readHealth: { | ||
status: HealthStatus; | ||
timestamp: string; | ||
}; | ||
} | ||
|
||
export interface AlertingFrameworkHealth { | ||
isSufficientlySecure: boolean; | ||
hasPermanentEncryptionKey: boolean; | ||
alertingFrameworkHealth: AlertsHealth; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/kbn-alerts-ui-shared/src/common/apis/create_rule/create_rule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { HttpSetup } from '@kbn/core/public'; | ||
import type { AsApiContract } from '@kbn/actions-types'; | ||
import type { Rule } from '../../types'; | ||
import { CreateRuleBody, transformCreateRuleBody } from '.'; | ||
import { BASE_ALERTING_API_PATH } from '../../constants'; | ||
import { transformRule } from '../../transformations'; | ||
|
||
export async function createRule({ | ||
http, | ||
rule, | ||
}: { | ||
http: HttpSetup; | ||
rule: CreateRuleBody; | ||
}): Promise<Rule> { | ||
const res = await http.post<AsApiContract<Rule>>(`${BASE_ALERTING_API_PATH}/rule`, { | ||
body: JSON.stringify(transformCreateRuleBody(rule)), | ||
}); | ||
return transformRule(res); | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/kbn-alerts-ui-shared/src/common/apis/create_rule/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './types'; | ||
export * from './create_rule'; | ||
export * from './transform_create_rule_body'; |
103 changes: 103 additions & 0 deletions
103
packages/kbn-alerts-ui-shared/src/common/apis/create_rule/transform_create_rule_body.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { transformCreateRuleBody } from './transform_create_rule_body'; | ||
import type { RuleTypeParams } from '../../types'; | ||
import type { CreateRuleBody } from './types'; | ||
|
||
const ruleToCreate: CreateRuleBody<RuleTypeParams> = { | ||
params: { | ||
aggType: 'count', | ||
termSize: 5, | ||
thresholdComparator: '>', | ||
timeWindowSize: 5, | ||
timeWindowUnit: 'm', | ||
groupBy: 'all', | ||
threshold: [1000], | ||
index: ['.kibana'], | ||
timeField: 'alert.executionStatus.lastExecutionDate', | ||
}, | ||
consumer: 'alerts', | ||
schedule: { interval: '1m' }, | ||
tags: [], | ||
name: 'test', | ||
enabled: true, | ||
throttle: null, | ||
ruleTypeId: '.index-threshold', | ||
actions: [ | ||
{ | ||
group: 'threshold met', | ||
id: '83d4d860-9316-11eb-a145-93ab369a4461', | ||
params: { | ||
level: 'info', | ||
message: 'test-message', | ||
}, | ||
actionTypeId: '.server-log', | ||
frequency: { | ||
notifyWhen: 'onActionGroupChange', | ||
throttle: null, | ||
summary: false, | ||
}, | ||
useAlertDataForTemplate: true, | ||
}, | ||
{ | ||
id: '.test-system-action', | ||
params: {}, | ||
actionTypeId: '.system-action', | ||
}, | ||
], | ||
notifyWhen: 'onActionGroupChange', | ||
alertDelay: { | ||
active: 10, | ||
}, | ||
}; | ||
|
||
describe('transformCreateRuleBody', () => { | ||
test('should transform create rule body', () => { | ||
expect(transformCreateRuleBody(ruleToCreate)).toEqual({ | ||
params: { | ||
aggType: 'count', | ||
termSize: 5, | ||
thresholdComparator: '>', | ||
timeWindowSize: 5, | ||
timeWindowUnit: 'm', | ||
groupBy: 'all', | ||
threshold: [1000], | ||
index: ['.kibana'], | ||
timeField: 'alert.executionStatus.lastExecutionDate', | ||
}, | ||
consumer: 'alerts', | ||
schedule: { interval: '1m' }, | ||
tags: [], | ||
name: 'test', | ||
enabled: true, | ||
throttle: null, | ||
notifyWhen: 'onActionGroupChange', | ||
rule_type_id: '.index-threshold', | ||
actions: [ | ||
{ | ||
group: 'threshold met', | ||
id: '83d4d860-9316-11eb-a145-93ab369a4461', | ||
params: { | ||
level: 'info', | ||
message: 'test-message', | ||
}, | ||
frequency: { | ||
notify_when: 'onActionGroupChange', | ||
summary: false, | ||
throttle: null, | ||
}, | ||
use_alert_data_for_template: true, | ||
}, | ||
{ id: '.test-system-action', params: {} }, | ||
], | ||
|
||
alert_delay: { active: 10 }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/kbn-alerts-ui-shared/src/common/apis/create_rule/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Rule, RuleTypeParams } from '../../types'; | ||
|
||
export interface CreateRuleBody<Params extends RuleTypeParams = RuleTypeParams> { | ||
name: Rule<Params>['name']; | ||
ruleTypeId: Rule<Params>['ruleTypeId']; | ||
enabled: Rule<Params>['enabled']; | ||
consumer: Rule<Params>['consumer']; | ||
tags: Rule<Params>['tags']; | ||
throttle?: Rule<Params>['throttle']; | ||
params: Rule<Params>['params']; | ||
schedule: Rule<Params>['schedule']; | ||
actions: Rule<Params>['actions']; | ||
notifyWhen?: Rule<Params>['notifyWhen']; | ||
alertDelay?: Rule<Params>['alertDelay']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.