-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Alerting] System action types and helpers #167871
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
@@ -185,6 +185,9 @@ export class RulesClientFactory { | |||
} | |||
return { apiKeysEnabled: false }; | |||
}, | |||
isSystemAction(actionId: string) { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'>; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
984b0f8
to
54fd67a
Compare
💔 Build FailedFailed CI Steps
Test Failures
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @cnasikas |
…#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 <[email protected]> Co-authored-by: Julia <[email protected]>
…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 <[email protected]> Co-authored-by: Julia Guskova <[email protected]>
In this PR:
isSystemAction
in the executor to determine if an action is a system actionisSystemConnector
utility function from the actions plugin to the rules factoryChecklist
Delete any items that are not applicable to this PR.
For maintainers