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

[Alerting] System action types and helpers #167871

Merged
merged 6 commits into from
Oct 19, 2023

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Oct 3, 2023

In this PR:

  • Creation of types for the system actions
  • Creation of a helper function to detect if it is a system action or not
  • Use the isSystemAction in the executor to determine if an action is a system action
  • Pass the isSystemConnector utility function from the actions plugin to the rules factory
  • Create test utils to help test system actions and connector adapters

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Feature:Alerting/RuleActions Issues related to the Actions attached to Rules on the Alerting Framework labels Oct 3, 2023
@cnasikas cnasikas self-assigned this Oct 3, 2023
@cnasikas cnasikas requested a review from a team as a code owner October 3, 2023 12:18
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

@cnasikas cnasikas changed the base branch from main to system_actions_mvp October 3, 2023 12:18
@cnasikas cnasikas added the release_note:skip Skip the PR/issue when compiling release notes label Oct 3, 2023
@@ -185,6 +185,9 @@ export class RulesClientFactory {
}
return { apiKeysEnabled: false };
},
isSystemAction(actionId: string) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named it isSystemAction and not isSystemActionConnector because the checks in the alerting plugin will be done upon rule actions.

@@ -52,6 +53,7 @@ import {
isSummaryActionThrottled,
} from './rule_action_helper';
import { ConnectorAdapter } from '../connector_adapters/types';
import { isSystemAction } from '../../common/system_actions/is_system_action';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use actions.isSystemActionConnector (exposed by the rule factory as isSystemAction) instead of using that helper function that checks only the type?

}

export type NormalizedAlertAction = Omit<RuleAction, 'actionTypeId'>;
export type NormalizedAlertAction = DistributiveOmit<RuleAction, 'actionTypeId'>;
export type NormalizedSystemAction = Omit<RuleSystemAction, 'actionTypeId'>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cnasikas Why in one case you use DistributiveOmit and in another Omit?

Copy link
Member Author

@cnasikas cnasikas Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that the RuleAction is the union RuleDefaultAction | RuleSystemAction. Normal Omit does not work with unions. If you need to remove a property from each item in the union you need to use DistributiveOmit. For RuleSystemAction is not needed because it is not a union.

@@ -125,7 +125,7 @@ interface AlertsFilterAttributes {

export interface RuleActionAttributes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we did not create here two types(system and default) instead of one?

Copy link
Member Author

@cnasikas cnasikas Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this type represents what is being saved in ES. The data in ES should not have the action's type so there is not need to distinguish (I don't think it is possible without the type) the two actions.

@@ -158,7 +159,12 @@ export function getPartialRuleFromRaw<Params extends RuleTypeParams>(

if (omitGeneratedValues) {
if (rule.actions) {
rule.actions = rule.actions.map((ruleAction) => omit(ruleAction, 'alertsFilter.query.dsl'));
rule.actions = rule.actions.map((ruleAction) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we're deprecating getAlertFromRaw in favor of transformRuleDomainToRuleAttributes, so let's make sure these changes are reflected there as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that analog of old getAlertFromRaw is a new transformRuleAttributesToRuleDomain. I think I've already added the smae type guard there as well: x-pack/plugins/alerting/server/application/rule/transforms/transform_rule_attributes_to_rule_domain.ts line 157.
Isn't what you meant?

Copy link
Member Author

@cnasikas cnasikas Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! This PR is the first of many. I modified transformRuleDomainToRuleAttributes in another PR https://github.com/elastic/kibana/pull/167884/files#diff-25071c31329de46443821b36fad591c9a13261fb61990cb1b3747aef429b808eR22. For transformRuleAttributesToRuleDomain in the same PR here https://github.com/elastic/kibana/pull/167884/files#diff-d5aa343d106a834626d085c1fd6e4a083b05af194c5c8a886c93ab316d4919f8R152. To keep the size small I choose to not do all the changes. My initial PR tried to accommodate everything and it got too big. I closed it in favor of smaller PRs that deliberately will not pass the CI and will get merged in a feature branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cnasikas I did not recognise your intention from the beginning and started to fix all types :-)
Now I see that you made some of this changes in follow up PRs. So I've deleted my commit for this PR.

@guskovaue guskovaue merged commit 6923ae2 into elastic:system_actions_mvp Oct 19, 2023
15 of 24 checks passed
@kibana-ci
Copy link
Collaborator

kibana-ci commented Oct 19, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] x-pack/test/alerting_api_integration/security_and_spaces/group2/config_non_dedicated_task_runner.ts / alerting api integration security and spaces enabled - Group 2 Alerts alerts alerts connector adapters should use connector adapters correctly on system actions
  • [job] [logs] x-pack/test/alerting_api_integration/security_and_spaces/group2/config.ts / alerting api integration security and spaces enabled - Group 2 Alerts alerts alerts connector adapters should use connector adapters correctly on system actions
  • [job] [logs] x-pack/test/alerting_api_integration/security_and_spaces/group2/config_non_dedicated_task_runner.ts / alerting api integration security and spaces enabled - Group 2 Alerts alerts alerts connector adapters should use connector adapters correctly on system actions
  • [job] [logs] x-pack/test/alerting_api_integration/security_and_spaces/group2/config.ts / alerting api integration security and spaces enabled - Group 2 Alerts alerts alerts connector adapters should use connector adapters correctly on system actions
  • [job] [logs] FTR Configs #11 / dashboard app - group 5 embed mode default URL params renders as expected
  • [job] [logs] FTR Configs #11 / dashboard app - group 5 embed mode default URL params renders as expected
  • [job] [logs] Jest Integration Tests #7 / Fleet preconfiguration reset Preconfigured cloud policy With a full preconfigured cloud policy Create correct .fleet-policies

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [b064eba]

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @cnasikas

guskovaue added a commit that referenced this pull request Oct 26, 2023
…#167884)

## Summary

This PR enables system actions only to the Create Rule API. Other PRs
will follow on a subsequent PR.

Depends on: #167871

### Checklist

Delete any items that are not applicable to this PR.

- [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

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Julia <iuliia.guskova@elastic.co>
guskovaue added a commit that referenced this pull request Oct 27, 2023
…API (#168226)

Summarize your PR. If it involves visual changes include a screenshot or
gif.

Depends on: #167871,
#167884

### Checklist

Delete any items that are not applicable to this PR.

- [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

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Julia Guskova <iuliia.guskova@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting/RuleActions Issues related to the Actions attached to Rules on the Alerting Framework Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

5 participants