Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UUID to RuleAction #148038

Merged
merged 86 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
6730ec6
Add UUID to RuleAction
ersin-erdal Dec 23, 2022
aeb5c52
Add Normalised RuleAction with optional uuid
ersin-erdal Dec 26, 2022
7d06388
Merge branch 'main' into action-uuid
ersin-erdal Dec 29, 2022
9f5f08b
[CI] Auto-commit changed files from 'node scripts/ts_project_linter -…
kibanamachine Dec 29, 2022
b465b41
fix synthetics
ersin-erdal Dec 29, 2022
ebf16e2
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Dec 29, 2022
71856db
fix synthetics
ersin-erdal Dec 29, 2022
e998913
refactor uuid creation
ersin-erdal Dec 30, 2022
98640a9
[CI] Auto-commit changed files from 'node scripts/ts_project_linter -…
kibanamachine Dec 31, 2022
81064d2
fix synthetics
ersin-erdal Dec 29, 2022
5e2d374
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Dec 31, 2022
27a8c78
fix functional tests
ersin-erdal Jan 1, 2023
f125d45
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 1, 2023
0439879
remove uuid from legacy
ersin-erdal Jan 1, 2023
33aae24
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Jan 1, 2023
8c5714a
remove uuid from legacy
ersin-erdal Jan 1, 2023
2752ca1
Merge branch 'main' into action-uuid
ersin-erdal Jan 2, 2023
0cd5b88
add migration script
ersin-erdal Jan 3, 2023
a82b962
remove filter from migrations
ersin-erdal Jan 3, 2023
b2456fb
merge main
ersin-erdal Jan 16, 2023
5e3176f
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 16, 2023
e13b491
fix check type
ersin-erdal Jan 16, 2023
100a61d
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Jan 16, 2023
2d81fa7
fix check type
ersin-erdal Jan 16, 2023
3aebc97
move uuid creation to rules_client
ersin-erdal Jan 17, 2023
2161600
fix test
ersin-erdal Jan 17, 2023
9b7c782
Merge branch 'main' into action-uuid
ersin-erdal Jan 23, 2023
7c54564
enable migration
ersin-erdal Jan 23, 2023
bbee16b
increase limit
ersin-erdal Jan 24, 2023
7f8a13c
fix migration tests
ersin-erdal Jan 24, 2023
a5aba90
remove NormalizedAlertActionOptionalUuid
ersin-erdal Jan 24, 2023
dd7efb2
Merge branch 'main' into action-uuid
ersin-erdal Jan 25, 2023
325b904
Merge branch 'main' into action-uuid
ersin-erdal Jan 25, 2023
af4be1c
Merge branch 'main' into action-uuid
ersin-erdal Jan 25, 2023
8cf70a6
Merge branch 'main' into action-uuid
ersin-erdal Jan 27, 2023
4ec5a9e
fix nits and add unit tests for bulk_edit and update
ersin-erdal Jan 28, 2023
1468812
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Jan 28, 2023
ebdd607
merge main
ersin-erdal Jan 28, 2023
214f464
fix legacy_types
ersin-erdal Jan 28, 2023
1b5a553
fix nit
ersin-erdal Jan 29, 2023
2274b8f
Remove type castings
ersin-erdal Jan 31, 2023
b6fe2d4
Remove validation step from legacy APIs
ersin-erdal Feb 1, 2023
3a26996
merge main
ersin-erdal Feb 1, 2023
2c14ebb
Merge branch 'main' into action-uuid
ersin-erdal Feb 1, 2023
5f00b81
fix expect type
ersin-erdal Feb 1, 2023
7e250ea
make uuid optional in create rule
ersin-erdal Feb 1, 2023
a2a93db
fix tests
ersin-erdal Feb 1, 2023
defabcd
Merge branch 'main' into action-uuid
ersin-erdal Feb 2, 2023
343f75e
reset security solutions changes
ersin-erdal Feb 5, 2023
eaa1130
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Feb 5, 2023
3565146
reset security solutions changes
ersin-erdal Feb 5, 2023
f2b8c44
Merge branch 'main' into action-uuid
ersin-erdal Feb 5, 2023
6d0e948
reset security solutions changes
ersin-erdal Feb 5, 2023
b78c692
Merge branch 'main' into action-uuid
kibanamachine Feb 6, 2023
d65f165
merge main
ersin-erdal Feb 6, 2023
53510eb
fix tests after merge
ersin-erdal Feb 6, 2023
0ce1393
Merge branch 'main' into action-uuid
ersin-erdal Feb 6, 2023
c1ff478
remove the redundant interface
ersin-erdal Feb 7, 2023
961fe22
make uuid optional in RuleAction
ersin-erdal Feb 7, 2023
1e551ad
merge main
ersin-erdal Feb 7, 2023
a8c214e
Merge branch 'main' into action-uuid
ersin-erdal Feb 7, 2023
3af6a0e
Merge branch 'main' into action-uuid
ersin-erdal Feb 7, 2023
d5f0090
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Feb 7, 2023
04be440
merge main
ersin-erdal Feb 7, 2023
b3512a5
alert SO hash
ersin-erdal Feb 7, 2023
d05d417
Merge branch 'main' into action-uuid
ersin-erdal Feb 8, 2023
aceb74f
merge main
ersin-erdal Feb 10, 2023
1e27d27
alert SO hash
ersin-erdal Feb 10, 2023
5f7863c
Merge branch 'main' into action-uuid
ersin-erdal Feb 14, 2023
a15c6ed
Merge branch 'main' into action-uuid
ersin-erdal Feb 16, 2023
b958d93
fix failing functional test
ersin-erdal Feb 16, 2023
e20ca02
remove unnecessary type casts
ersin-erdal Feb 16, 2023
fe412e0
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 16, 2023
038d1c8
Merge branch 'main' into action-uuid
ersin-erdal Feb 17, 2023
7e0f4d2
remove unnecessary changes
ersin-erdal Feb 17, 2023
22df8d3
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Feb 17, 2023
e287eb6
Merge branch 'main' into action-uuid
ersin-erdal Feb 20, 2023
885c82d
check that the uuid is not an empty string after migration
ersin-erdal Feb 20, 2023
90bb572
Merge remote-tracking branch 'origin/action-uuid' into action-uuid
ersin-erdal Feb 20, 2023
d5d3a78
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
edbed26
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
f26f451
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
76b3cd3
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
ace3a6a
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
fcae7c6
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
a0ca778
Merge branch 'main' into action-uuid
ersin-erdal Feb 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { NonEmptyString } from '@kbn/securitysolution-io-ts-types';

import * as t from 'io-ts';
import { saved_object_attributes } from '../saved_object_attributes';
Expand All @@ -18,6 +19,9 @@ export const RuleActionId = t.string;
export type RuleActionTypeId = t.TypeOf<typeof RuleActionTypeId>;
export const RuleActionTypeId = t.string;

export type RuleActionUuid = t.TypeOf<typeof RuleActionUuid>;
export const RuleActionUuid = NonEmptyString;

/**
* Params is an "object", since it is a type of RuleActionParams which is action templates.
* @see x-pack/plugins/alerting/common/rule.ts
Expand All @@ -27,25 +31,31 @@ export const RuleActionParams = saved_object_attributes;

export type RuleAction = t.TypeOf<typeof RuleAction>;
export const RuleAction = t.exact(
t.type({
group: RuleActionGroup,
id: RuleActionId,
action_type_id: RuleActionTypeId,
params: RuleActionParams,
})
t.intersection([
t.type({
group: RuleActionGroup,
id: RuleActionId,
action_type_id: RuleActionTypeId,
params: RuleActionParams,
}),
t.partial({ uuid: RuleActionUuid }),
])
);

export type RuleActionArray = t.TypeOf<typeof RuleActionArray>;
export const RuleActionArray = t.array(RuleAction);

export type RuleActionCamel = t.TypeOf<typeof RuleActionCamel>;
export const RuleActionCamel = t.exact(
t.type({
group: RuleActionGroup,
id: RuleActionId,
actionTypeId: RuleActionTypeId,
params: RuleActionParams,
})
t.intersection([
t.type({
group: RuleActionGroup,
id: RuleActionId,
actionTypeId: RuleActionTypeId,
params: RuleActionParams,
}),
t.partial({ uuid: RuleActionUuid }),
])
);

export type RuleActionArrayCamel = t.TypeOf<typeof RuleActionArrayCamel>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
Object {
"action": "6cfc277ed3211639e37546ac625f4a68f2494215",
"action_task_params": "db2afea7d78e00e725486b791554d0d4e81956ef",
"alert": "f81ad957a7936522482e4539c7a96a963ebdbc3e",
"alert": "2568bf6d8ba0876441c61c9e58e08016c1dc1617",
"api_key_pending_invalidation": "16e7bcf8e78764102d7f525542d5b616809a21ee",
"apm-indices": "d19dd7fb51f2d2cbc1f8769481721e0953f9a6d2",
"apm-server-schema": "1d42f17eff9ec6c16d3a9324d9539e2d123d0a9a",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/common/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type RuleActionParams = SavedObjectAttributes;
export type RuleActionParam = SavedObjectAttribute;

export interface RuleAction {
uuid?: string;
group: string;
id: string;
actionTypeId: string;
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerting/public/alert_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('loadRule', () => {
"params": Object {
"message": "alert 37: {{context.message}}",
},
"uuid": "123-456",
},
],
"alertTypeId": ".index-threshold",
Expand Down Expand Up @@ -278,6 +279,7 @@ function getApiRule() {
},
group: 'threshold met',
id: '3619a0d0-582b-11ec-8995-2b1578a3bc5d',
uuid: '123-456',
},
],
params: { x: 42 },
Expand Down Expand Up @@ -319,6 +321,7 @@ function getRule(): Rule<{ x: number }> {
},
group: 'threshold met',
id: '3619a0d0-582b-11ec-8995-2b1578a3bc5d',
uuid: '123-456',
},
],
params: { x: 42 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('common_transformations', () => {
group: 'some group',
id: 'some-connector-id',
params: { foo: 'car', bar: [1, 2, 3] },
uuid: '123-456',
},
],
params: { bar: 'foo', numbers: { 1: [2, 3] } } as never,
Expand Down Expand Up @@ -108,6 +109,7 @@ describe('common_transformations', () => {
],
"foo": "car",
},
"uuid": "123-456",
},
],
"alertTypeId": "some-rule-type",
Expand Down Expand Up @@ -213,6 +215,7 @@ describe('common_transformations', () => {
group: 'some group',
id: 'some-connector-id',
params: {},
uuid: '123-456',
},
],
params: {} as never,
Expand Down Expand Up @@ -277,6 +280,7 @@ describe('common_transformations', () => {
"group": "some group",
"id": "some-connector-id",
"params": Object {},
"uuid": "123-456",
},
],
"alertTypeId": "some-rule-type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('bulkEditInternalRulesRoute', () => {
params: {
foo: true,
},
uuid: '123-456',
},
],
consumer: 'bar',
Expand Down Expand Up @@ -111,6 +112,7 @@ describe('bulkEditInternalRulesRoute', () => {
params: {
foo: true,
},
uuid: '123-456',
},
],
}),
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/routes/bulk_edit_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ruleActionSchema = schema.object({
group: schema.string(),
id: schema.string(),
params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
uuid: schema.maybe(schema.string()),
});

const operationsSchema = schema.arrayOf(
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/clone_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('cloneRuleRoute', () => {
params: {
foo: true,
},
uuid: '123-456',
},
],
enabled: true,
Expand Down Expand Up @@ -97,6 +98,7 @@ describe('cloneRuleRoute', () => {
{
...ruleToClone.actions[0],
connector_type_id: 'test',
uuid: '123-456',
},
],
};
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/create_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createRuleRoute', () => {
params: {
foo: true,
},
uuid: '123-456',
},
],
enabled: true,
Expand Down Expand Up @@ -100,6 +101,7 @@ describe('createRuleRoute', () => {
{
...ruleToCreate.actions[0],
connector_type_id: 'test',
uuid: '123-456',
},
],
};
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/get_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('getRuleRoute', () => {
params: {
foo: true,
},
uuid: '123-456',
},
],
consumer: 'bar',
Expand Down Expand Up @@ -85,6 +86,7 @@ describe('getRuleRoute', () => {
id: mockedAlert.actions[0].id,
params: mockedAlert.actions[0].params,
connector_type_id: mockedAlert.actions[0].actionTypeId,
uuid: mockedAlert.actions[0].uuid,
},
],
};
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/routes/get_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
last_execution_date: executionStatus.lastExecutionDate,
last_duration: executionStatus.lastDuration,
},
actions: actions.map(({ group, id, actionTypeId, params, frequency }) => ({
actions: actions.map(({ group, id, actionTypeId, params, frequency, uuid }) => ({
group,
id,
params,
Expand All @@ -72,6 +72,7 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
throttle: frequency.throttle,
}
: undefined,
...(uuid && { uuid }),
})),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const actionsSchema = schema.arrayOf(
throttle: schema.nullable(schema.string({ validate: validateDurationSchema })),
})
),
uuid: schema.maybe(schema.string()),
banderror marked this conversation as resolved.
Show resolved Hide resolved
}),
{ defaultValue: [] }
);
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/routes/lib/rewrite_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const rewriteRule = ({
last_execution_date: executionStatus.lastExecutionDate,
last_duration: executionStatus.lastDuration,
},
actions: actions.map(({ group, id, actionTypeId, params, frequency }) => ({
actions: actions.map(({ group, id, actionTypeId, params, frequency, uuid }) => ({
group,
id,
params,
Expand All @@ -71,6 +71,7 @@ export const rewriteRule = ({
},
}
: {}),
...(uuid && { uuid }),
})),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/resolve_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('resolveRuleRoute', () => {
params: {
foo: true,
},
uuid: '123-456',
},
],
consumer: 'bar',
Expand Down Expand Up @@ -97,6 +98,7 @@ describe('resolveRuleRoute', () => {
id: mockedRule.actions[0].id,
params: mockedRule.actions[0].params,
connector_type_id: mockedRule.actions[0].actionTypeId,
uuid: mockedRule.actions[0].uuid,
},
],
outcome: 'aliasMatch',
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerting/server/routes/update_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('updateRuleRoute', () => {
updatedAt: new Date(),
actions: [
{
uuid: '1234-5678',
group: 'default',
id: '2',
actionTypeId: 'test',
Expand All @@ -58,6 +59,7 @@ describe('updateRuleRoute', () => {
notify_when: mockedAlert.notifyWhen,
actions: [
{
uuid: '1234-5678',
group: mockedAlert.actions[0].group,
id: mockedAlert.actions[0].id,
params: mockedAlert.actions[0].params,
Expand Down Expand Up @@ -114,6 +116,7 @@ describe('updateRuleRoute', () => {
"params": Object {
"baz": true,
},
"uuid": "1234-5678",
},
],
"name": "abc",
Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugins/alerting/server/rules_client/lib/add_uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 { v4 } from 'uuid';
import { NormalizedAlertAction, NormalizedAlertActionWithUuid } from '..';

export function addUuid(actions: NormalizedAlertAction[] = []): NormalizedAlertActionWithUuid[] {
return actions.map((action) => ({
...action,
uuid: action.uuid || v4(),
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import { SavedObjectReference } from '@kbn/core/server';
import { RawRule } from '../../types';
import { preconfiguredConnectorActionRefPrefix } from '../common/constants';
import { RulesClientContext } from '../types';
import { NormalizedAlertAction } from '../types';
import { NormalizedAlertActionWithUuid, RulesClientContext } from '../types';

export async function denormalizeActions(
context: RulesClientContext,
alertActions: NormalizedAlertAction[]
alertActions: NormalizedAlertActionWithUuid[]
): Promise<{ actions: RawRule['actions']; references: SavedObjectReference[] }> {
const references: SavedObjectReference[] = [];
const actions: RawRule['actions'] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { SavedObjectReference } from '@kbn/core/server';
import { RawRule, RuleTypeParams } from '../../types';
import { UntypedNormalizedRuleType } from '../../rule_type_registry';
import { NormalizedAlertAction } from '../types';
import { NormalizedAlertActionWithUuid } from '../types';
import { extractedSavedObjectParamReferenceNamePrefix } from '../common/constants';
import { RulesClientContext } from '../types';
import { denormalizeActions } from './denormalize_actions';
Expand All @@ -19,7 +19,7 @@ export async function extractReferences<
>(
context: RulesClientContext,
ruleType: UntypedNormalizedRuleType,
ruleActions: NormalizedAlertAction[],
ruleActions: NormalizedAlertActionWithUuid[],
ruleParams: Params
): Promise<{
actions: RawRule['actions'];
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/rules_client/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { checkAuthorizationAndGetTotal } from './check_authorization_and_get_tot
export { scheduleTask } from './schedule_task';
export { createNewAPIKeySet } from './create_new_api_key_set';
export { recoverRuleAlerts } from './recover_rule_alerts';
export { addUuid } from './add_uuid';
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export async function validateActions(

const errors = [];

const uniqueActions = new Set(actions.map((action) => action.uuid));
if (uniqueActions.size < actions.length) {
errors.push(
i18n.translate('xpack.alerting.rulesClient.validateActions.hasDuplicatedUuid', {
defaultMessage: 'Actions have duplicated UUIDs',
})
);
}

// check for actions using connectors with missing secrets
const actionsClient = await context.getActionsClient();
const actionIds = [...new Set(actions.map((action) => action.id))];
Expand Down
Loading