Skip to content

[Actions] Connector Adapters MVP#166101

Merged
cnasikas merged 7 commits intoelastic:system_actions_mvpfrom
cnasikas:connector_adapters_mvp
Sep 12, 2023
Merged

[Actions] Connector Adapters MVP#166101
cnasikas merged 7 commits intoelastic:system_actions_mvpfrom
cnasikas:connector_adapters_mvp

Conversation

@cnasikas
Copy link
Copy Markdown
Member

@cnasikas cnasikas commented Sep 8, 2023

Summary

This PR implements Connector Adapters. Integrations tests will follow on this PR #161726 as we cannot create system actions through the API at the moment.

Issue: #160367
POC: #159866

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Feature:Actions Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// Feature:Actions/Framework Issues related to the Actions Framework v8.11.0 labels Sep 8, 2023
@cnasikas cnasikas requested a review from a team as a code owner September 8, 2023 16:17
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@cnasikas cnasikas self-assigned this Sep 8, 2023
params: RuleActionParams;
frequency?: RuleActionFrequency;
alertsFilter?: AlertsFilter;
type?: typeof RuleActionTypes.DEFAULT;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The system action will be

export interface RuleSystemAction {
  uuid: string;
  id: string;
  actionTypeId: string;
  params: RuleActionParams;
  type: typeof RuleActionTypes.SYSTEM;
}


type ActionTypeParams = Record<string, unknown>;

type Rule = Pick<SanitizedRule<RuleTypeParams>, 'id' | 'name' | 'tags'>;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For the MVP this should be enough. If a connector adapter needs more attributes from the rule we can extend it in the future.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: do we need to extend or can we pass-through SanitizedRule<RuleTypeParams>?

params: { spaceId, alertId: ruleId },
},
} = this;
if (executables.length === 0) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed the outer if and returned early. Better to view it with "Hide white spaces" enabled.

ruleRunMetricsStore.incrementNumberOfTriggeredActionsByConnectorType(actionTypeId);

if (summarizedAlerts && !isSystemAction(action)) {
const { actionsToEnqueueForExecution, actionsToLog } = await this.runSummarizedAction({
Copy link
Copy Markdown
Member Author

@cnasikas cnasikas Sep 8, 2023

Choose a reason for hiding this comment

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

Small refactor. I create one run*Action method for each possible execution and I move the logic inside the dedicated functions. The logic is the same as before.

Copy link
Copy Markdown
Member Author

@cnasikas cnasikas Sep 8, 2023

Choose a reason for hiding this comment

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

I moved the logic of running each action in a separate function. Each runner returns the actions to be bulk executed and the logged messages. Also, I moved the logic of bulk executing and logging into separate functions.

Copy link
Copy Markdown
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Left a few questions. Also wondering if we should be merging into a feature branch instead of main?

@cnasikas
Copy link
Copy Markdown
Member Author

cnasikas commented Sep 11, 2023

Left a few questions. Also wondering if we should be merging into a feature branch instead of main?

If fine with both. Whatever you think is best 🙂

@cnasikas cnasikas mentioned this pull request Sep 12, 2023
15 tasks
@ymao1
Copy link
Copy Markdown
Contributor

ymao1 commented Sep 12, 2023

Left a few questions. Also wondering if we should be merging into a feature branch instead of main?

If fine with both. Whatever you think is best 🙂

I think since we're treating main as prod now, this probably makes more sense to merge into a feature branch and only merge the feature branch when it is feature complete.

@cnasikas cnasikas changed the base branch from main to system_actions_mvp September 12, 2023 12:04
Copy link
Copy Markdown
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM. Mostly reviewed code changes in alerting execution handler.

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
alerting 762 766 +4
triggersActionsUi 550 551 +1
total +5

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
alerting 49 50 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
alerting 21.7KB 21.8KB +99.0B
Unknown metric groups

API count

id before after diff
alerting 793 798 +5
triggersActionsUi 576 577 +1
total +6

History

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

cc @cnasikas

@cnasikas cnasikas merged commit 29973e2 into elastic:system_actions_mvp Sep 12, 2023
@cnasikas cnasikas deleted the connector_adapters_mvp branch September 12, 2023 14:07
Copy link
Copy Markdown
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

I managed to go through this PR as discussed. Below are the questions I had and nitpicks.

Comment on lines +117 to +120
export const RuleActionTypes = {
DEFAULT: 'default' as const,
SYSTEM: 'system' as const,
} as const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: Do we have a follow up issue / task for the feature branch to split DEFAULT into two? (something that associates with each alert and something that associates with summaries).


type ActionTypeParams = Record<string, unknown>;

type Rule = Pick<SanitizedRule<RuleTypeParams>, 'id' | 'name' | 'tags'>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: do we need to extend or can we pass-through SanitizedRule<RuleTypeParams>?


export const generateActionHash = (action?: RuleAction) => {
if (action != null && isSystemAction(action)) {
return `system-action:${action?.actionTypeId || 'no-action-type-id'}:summary`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: No need for action?.actionTypeId || 'no-action-type-id' as it can be action.actionTypeId.

Comment on lines 299 to 301
this.logger.warn(
`Rule "${this.taskInstance.params.alertId}" skipped scheduling action "${action.id}" because it is disabled`
`Rule "${this.taskInstance.params.alertId}" skipped scheduling system action "${action.id}" because no connector adapter is configured`
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: should we throw an error instead similar to when a connector doesn't exist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Actions/Framework Issues related to the Actions Framework Feature:Actions release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.11.0

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

5 participants