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

[Response Ops][Rule Form V2] Prepare Rule Form V2 Action Form Dependencies #186490

Merged
merged 34 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0c08c14
Initial commit
JiaweiWu May 13, 2024
557b271
Revert rule-data-utils
JiaweiWu May 13, 2024
3cf8e5e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine May 13, 2024
21e65be
Fix sandbox
JiaweiWu May 13, 2024
4143a3c
Merge branch 'main' into rule-form-v2-rule-definition
JiaweiWu May 13, 2024
27f519d
Initial commit
JiaweiWu May 14, 2024
934935c
Remove semicolon
JiaweiWu May 14, 2024
2d056f8
Add reducer
JiaweiWu May 15, 2024
958450f
Add edit/create page
JiaweiWu May 21, 2024
828fc87
Update examples
JiaweiWu May 21, 2024
17c6886
Add nav
JiaweiWu May 22, 2024
4560553
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine May 22, 2024
d174f6a
fix multi consumer
JiaweiWu May 23, 2024
5842cf5
Add circuit breaker error and no actions modal
JiaweiWu May 23, 2024
bc5a0ac
Merge conflicts
JiaweiWu Jun 6, 2024
775c6a1
Fix checks
JiaweiWu Jun 6, 2024
ae2fe3a
Merge conflicts
JiaweiWu Jun 13, 2024
a24c872
Tests
JiaweiWu Jun 18, 2024
3e9bd8d
Merge branch 'main' into rule-form-v2-create-edit
kibanamachine Jun 18, 2024
6aefc7f
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 18, 2024
d2734de
Fix CI
JiaweiWu Jun 18, 2024
fde46b9
Fix tests
JiaweiWu Jun 18, 2024
591fde8
Prepare dependency for action form
JiaweiWu Jun 20, 2024
7f7ab67
Fix merge conflicts
JiaweiWu Jul 5, 2024
b34b8fe
Fix CI
JiaweiWu Jul 5, 2024
487cdc9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 5, 2024
29b1415
Remove unused translations
JiaweiWu Jul 8, 2024
9854163
Merge branch 'main' into rule-form-v2-action-form-dependencies
JiaweiWu Jul 8, 2024
5431750
Fix tests
JiaweiWu Jul 8, 2024
987c710
Address comments
JiaweiWu Jul 11, 2024
d8d5a9d
Merge branch 'main' into rule-form-v2-action-form-dependencies
elasticmachine Jul 11, 2024
ccc1348
Merge conflicts
JiaweiWu Jul 17, 2024
4ea6607
Merge branch 'main' into rule-form-v2-action-form-dependencies
JiaweiWu Jul 18, 2024
4997e94
Address comments
JiaweiWu Jul 19, 2024
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
20 changes: 20 additions & 0 deletions packages/kbn-actions-types/action_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { LicenseType } from '@kbn/licensing-plugin/common/types';

export interface ActionType {
id: string;
name: string;
enabled: boolean;
enabledInConfig: boolean;
enabledInLicense: boolean;
minimumLicenseRequired: LicenseType;
supportedFeatureIds: string[];
isSystemActionType: boolean;
}
1 change: 1 addition & 0 deletions packages/kbn-actions-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export * from './rewrite_request_case_types';
export * from './action_types';
4 changes: 3 additions & 1 deletion packages/kbn-actions-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"exclude": [
"target/**/*"
],
"kbn_references": []
"kbn_references": [
"@kbn/licensing-plugin",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
/*
* 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 {
ActionContextVariablesFlatten,
ActionVariable,
SummaryActionContextVariablesFlatten,
} from '@kbn/alerting-types';
import { i18n } from '@kbn/i18n';

export enum AlertProvidedActionVariables {
ruleId = 'rule.id',
ruleName = 'rule.name',
ruleSpaceId = 'rule.spaceId',
ruleTags = 'rule.tags',
ruleType = 'rule.type',
ruleUrl = 'rule.url',
ruleParams = 'rule.params',
date = 'date',
alertId = 'alert.id',
alertUuid = 'alert.uuid',
alertActionGroup = 'alert.actionGroup',
alertActionGroupName = 'alert.actionGroupName',
alertActionSubgroup = 'alert.actionSubgroup',
alertFlapping = 'alert.flapping',
kibanaBaseUrl = 'kibanaBaseUrl',
alertConsecutiveMatches = 'alert.consecutiveMatches',
}

export enum LegacyAlertProvidedActionVariables {
alertId = 'alertId',
alertName = 'alertName',
alertInstanceId = 'alertInstanceId',
alertActionGroup = 'alertActionGroup',
alertActionGroupName = 'alertActionGroupName',
alertActionSubgroup = 'alertActionSubgroup',
tags = 'tags',
spaceId = 'spaceId',
params = 'params',
}

export enum SummaryAlertProvidedActionVariables {
newAlertsCount = 'alerts.new.count',
newAlertsData = 'alerts.new.data',
ongoingAlertsCount = 'alerts.ongoing.count',
ongoingAlertsData = 'alerts.ongoing.data',
recoveredAlertsCount = 'alerts.recovered.count',
recoveredAlertsData = 'alerts.recovered.data',
allAlertsCount = 'alerts.all.count',
allAlertsData = 'alerts.all.data',
}

type ActionVariablesWithoutName = Omit<ActionVariable, 'name'>;

export const AlertProvidedActionVariableDescriptions: Record<
ActionContextVariablesFlatten,
ActionVariablesWithoutName
> = Object.freeze({
[LegacyAlertProvidedActionVariables.alertId]: {
description: i18n.translate('alertsUIShared.actionVariables.legacyAlertIdLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleId,
},
}),
deprecated: true,
},
[LegacyAlertProvidedActionVariables.alertName]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacyAlertNameLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleName,
},
}),
},
[LegacyAlertProvidedActionVariables.alertInstanceId]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacyAlertInstanceIdLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertId,
},
}),
},
[LegacyAlertProvidedActionVariables.alertActionGroup]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacyAlertActionGroupLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertActionGroup,
},
}),
},
[LegacyAlertProvidedActionVariables.alertActionGroupName]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacyAlertActionGroupNameLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertActionGroupName,
},
}),
},
[LegacyAlertProvidedActionVariables.tags]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacyTagsLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleTags,
},
}),
},
[LegacyAlertProvidedActionVariables.spaceId]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacySpaceIdLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleSpaceId,
},
}),
},
[LegacyAlertProvidedActionVariables.params]: {
deprecated: true,
description: i18n.translate('alertsUIShared.actionVariables.legacyParamsLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleParams,
},
}),
},
[AlertProvidedActionVariables.date]: {
description: i18n.translate('alertsUIShared.actionVariables.dateLabel', {
defaultMessage: 'The date the rule scheduled the action.',
}),
},
[AlertProvidedActionVariables.kibanaBaseUrl]: {
description: i18n.translate('alertsUIShared.actionVariables.kibanaBaseUrlLabel', {
defaultMessage:
'The configured server.publicBaseUrl value or empty string if not configured.',
}),
},
[AlertProvidedActionVariables.ruleId]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleIdLabel', {
defaultMessage: 'The ID of the rule.',
}),
},
[AlertProvidedActionVariables.ruleName]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleNameLabel', {
defaultMessage: 'The name of the rule.',
}),
},
[AlertProvidedActionVariables.ruleSpaceId]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleSpaceIdLabel', {
defaultMessage: 'The space ID of the rule.',
}),
},
[AlertProvidedActionVariables.ruleType]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleTypeLabel', {
defaultMessage: 'The type of rule.',
}),
},
[AlertProvidedActionVariables.ruleTags]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleTagsLabel', {
defaultMessage: 'The tags of the rule.',
}),
},
[AlertProvidedActionVariables.ruleParams]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleParamsLabel', {
defaultMessage: 'The parameters of the rule.',
}),
},
[AlertProvidedActionVariables.ruleUrl]: {
description: i18n.translate('alertsUIShared.actionVariables.ruleUrlLabel', {
defaultMessage:
'The URL to the rule that generated the alert. This will be an empty string if the server.publicBaseUrl is not configured.',
}),
usesPublicBaseUrl: true,
},
[AlertProvidedActionVariables.alertId]: {
description: i18n.translate('alertsUIShared.actionVariables.alertIdLabel', {
defaultMessage: 'The ID of the alert that scheduled actions for the rule.',
}),
},
[AlertProvidedActionVariables.alertUuid]: {
description: i18n.translate('alertsUIShared.actionVariables.alertUuidLabel', {
defaultMessage: 'The UUID of the alert that scheduled actions for the rule.',
}),
},
[AlertProvidedActionVariables.alertActionGroup]: {
description: i18n.translate('alertsUIShared.actionVariables.alertActionGroupLabel', {
defaultMessage: 'The action group of the alert that scheduled actions for the rule.',
}),
},
[AlertProvidedActionVariables.alertActionGroupName]: {
description: i18n.translate('alertsUIShared.actionVariables.alertActionGroupNameLabel', {
defaultMessage:
'The human readable name of the action group of the alert that scheduled actions for the rule.',
}),
},
[AlertProvidedActionVariables.alertFlapping]: {
description: i18n.translate('alertsUIShared.actionVariables.alertFlappingLabel', {
defaultMessage:
'A flag on the alert that indicates whether the alert status is changing repeatedly.',
}),
},
[AlertProvidedActionVariables.alertConsecutiveMatches]: {
description: i18n.translate('alertsUIShared.actionVariables.alertConsecutiveMatchesLabel', {
defaultMessage: 'The number of consecutive runs that meet the rule conditions.',
}),
},
});

export const SummarizedAlertProvidedActionVariableDescriptions: Record<
SummaryActionContextVariablesFlatten,
Omit<ActionVariable, 'name'>
> = Object.freeze({
...AlertProvidedActionVariableDescriptions,
[SummaryAlertProvidedActionVariables.allAlertsCount]: {
description: i18n.translate('alertsUIShared.actionVariables.allAlertsCountLabel', {
defaultMessage: 'The count of all alerts.',
}),
},
[SummaryAlertProvidedActionVariables.allAlertsData]: {
description: i18n.translate('alertsUIShared.actionVariables.allAlertsDataLabel', {
defaultMessage: 'An array of objects for all alerts.',
}),
},
[SummaryAlertProvidedActionVariables.newAlertsCount]: {
description: i18n.translate('alertsUIShared.actionVariables.newAlertsCountLabel', {
defaultMessage: 'The count of new alerts.',
}),
},
[SummaryAlertProvidedActionVariables.newAlertsData]: {
description: i18n.translate('alertsUIShared.actionVariables.newAlertsDataLabel', {
defaultMessage: 'An array of objects for new alerts.',
}),
},
[SummaryAlertProvidedActionVariables.ongoingAlertsCount]: {
description: i18n.translate('alertsUIShared.actionVariables.ongoingAlertsCountLabel', {
defaultMessage: 'The count of ongoing alerts.',
}),
},
[SummaryAlertProvidedActionVariables.ongoingAlertsData]: {
description: i18n.translate('alertsUIShared.actionVariables.ongoingAlertsDataLabel', {
defaultMessage: 'An array of objects for ongoing alerts.',
}),
},
[SummaryAlertProvidedActionVariables.recoveredAlertsCount]: {
description: i18n.translate('alertsUIShared.actionVariables.recoveredAlertsCountLabel', {
defaultMessage: 'The count of recovered alerts.',
}),
},
[SummaryAlertProvidedActionVariables.recoveredAlertsData]: {
description: i18n.translate('alertsUIShared.actionVariables.recoveredAlertsDataLabel', {
defaultMessage: 'An array of objects for recovered alerts.',
}),
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 { partition } from 'lodash';
import { ActionVariable } from '@kbn/alerting-types';
import { ActionGroupWithMessageVariables, ActionVariables } from '@kbn/triggers-actions-ui-types';
import { transformActionVariables } from './transforms';

export const getAvailableActionVariables = (
actionVariables: ActionVariables,
summaryActionVariables?: ActionVariables,
actionGroup?: ActionGroupWithMessageVariables,
isSummaryAction?: boolean
) => {
const transformedActionVariables: ActionVariable[] = transformActionVariables(
actionVariables,
summaryActionVariables,
actionGroup?.omitMessageVariables,
isSummaryAction
);

// partition deprecated items so they show up last
const partitionedActionVariables = partition(
transformedActionVariables,
(v) => v.deprecated !== true
);
return partitionedActionVariables.reduce((acc, curr) => {
return [
...acc,
...curr.sort((a, b) => a.name.toUpperCase().localeCompare(b.name.toUpperCase())),
];
}, []);
};
11 changes: 11 additions & 0 deletions packages/kbn-alerts-ui-shared/src/action_variables/index.ts
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 './action_variables';
export * from './get_available_action_variables';
export * from './transforms';
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* 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.
* 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 { RuleType, ActionVariables } from '../../types';
import { transformActionVariables } from './action_variables';
import { ALERTING_FEATURE_ID } from '@kbn/alerting-plugin/common';
import { ActionVariables, RuleType } from '@kbn/triggers-actions-ui-types';
JiaweiWu marked this conversation as resolved.
Show resolved Hide resolved
import { transformActionVariables } from './transforms';
import { ALERTING_FEATURE_ID } from '../rule_form';

beforeEach(() => jest.resetAllMocks());

Expand Down
Loading