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

[Security Solution] Open alerts with an associated template in the template view #123333

Merged

Conversation

kqualters-elastic
Copy link
Contributor

@kqualters-elastic kqualters-elastic commented Jan 19, 2022

Summary

Resolves #123300 resolves #120898 and resolves #123370 alerts with an associated timeline template now use the derived notes, filters, data providers and query with the other defaults.

image

image

Checklist

@kqualters-elastic kqualters-elastic added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed Team:Threat Hunting:Investigations Security Solution Investigations Team v8.0.1 labels Jan 19, 2022
@kqualters-elastic kqualters-elastic requested a review from a team as a code owner January 19, 2022 01:11
@kqualters-elastic kqualters-elastic marked this pull request as draft January 19, 2022 01:14
const alertGroupId = alertGroupIdField?.length
? alertGroupIdField[0]
: 'unknown-group-id';
const alertGroupId = alertGroupIdField?.length ? alertGroupIdField : 'unknown-group-id';
Copy link
Contributor

Choose a reason for hiding this comment

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

alertGroupIdField ?? 'unknown-group-id'?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to @madirey suggestion.

@michaelolo24 michaelolo24 mentioned this pull request Jan 19, 2022
9 tasks
@kqualters-elastic kqualters-elastic marked this pull request as ready for review January 19, 2022 16:39
Copy link
Contributor

@michaelolo24 michaelolo24 left a comment

Choose a reason for hiding this comment

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

Thanks Kevin for getting these fixes in! Tested with an EQL Rule, Threshold Rule, Prepackaged Timeline Templates, and a custom template. All worked as expected! LGTM 🚀

dataProviders: [],
filters: buildAlertsKqlFilter('_id', alertsIds),
filters: [],
dataProviders: alertsIds.map((id) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 appreciate this, as it ensures the _id is populated in data providers vs filters (as before)

Copy link
Contributor

@madirey madirey left a comment

Choose a reason for hiding this comment

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

Thanks!!

const queryMatchField = getFieldKey(ecs, ALERT_GROUP_ID);
const alertGroupId = alertGroupIdField?.length ? alertGroupIdField[0] : 'unknown-group-id';
const alertGroupId = alertGroupIdField?.length ? alertGroupIdField : 'unknown-group-id';
Copy link
Contributor

Choose a reason for hiding this comment

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

If alertGroupIdField is not array any more, why we have this length check alertGroupIdField?.length?

@YulNaumenko
Copy link
Contributor

@kqualters-elastic thank you for the great work! Are there any chances to have some unit tests for x-pack/plugins/security_solution/public/helpers.tsx and x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx?

@@ -344,9 +359,7 @@ export const buildEqlDataProviderOrFilter = (
'signal.group.id',
Copy link
Contributor

@michaelolo24 michaelolo24 Jan 20, 2022

Choose a reason for hiding this comment

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

One more thing, can we update this to ALERT_GROUP_ID per the sync from yesterday? Thanks!

@MadameSheema
Copy link
Member

@elasticmachine merge upstream

if (!acc.includes(dateTimestamp.valueOf())) {
return [...acc, dateTimestamp.valueOf()];
}
const dateTimestamp = new Date(item.timestamp ?? '');
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok that new Date('') returns an Invalid Date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope

const alertGroupId = alertGroupIdField?.length
? alertGroupIdField[0]
: 'unknown-group-id';
const alertGroupId = !Array.isArray(alertGroupIdField)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider removing the negation via:

          const alertGroupId = Array.isArray(alertGroupIdField)
            ? alertGroupIdField[0]
            : alertGroupIdField;

@@ -137,12 +135,12 @@ export const determineToAndFrom = ({ ecs }: { ecs: Ecs[] | Ecs }) => {
const ecsData = ecs as Ecs;
const ruleFrom = getField(ecsData, ALERT_RULE_FROM);
const elapsedTimeRule = moment.duration(
moment().diff(dateMath.parse(ruleFrom != null ? ruleFrom[0] : 'now-0s'))
moment().diff(dateMath.parse(ruleFrom != null ? ruleFrom[0] : 'now-1d'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you

return {
dataProviders: [],
filters: buildAlertsKqlFilter(
'signal.group.id',
ALERT_GROUP_ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

const { to, from } = determineToAndFrom({ ecs });

// For now we do not want to populate the template timeline if we have alertIds
if (!isEmpty(timelineId) && isEmpty(alertIds)) {
if (!isEmpty(timelineId) && isThresholdRule(ecsData) === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

to ensure the template is applied to threshold rules, consider the following change suggested by @michaelolo24 :

if (!isEmpty(timelineId) && !isEmpty(alertIds)) {

Copy link
Contributor

@andrew-goldstein andrew-goldstein left a comment

Choose a reason for hiding this comment

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

Thanks for all the thought and effort you put into this fix @kqualters-elastic! 🙏
Desk tested locally
LGTM 🚀

Copy link
Contributor

@michaelolo24 michaelolo24 left a comment

Choose a reason for hiding this comment

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

Discussed recent changes offline. Re-approving. Thanks for the changes @kqualters-elastic! LGTM

For posterity: retested the following rule & rule - template matches and everything worked as expected

  • Query Rule no templates attached Works as expected
  • Query Rule with custom template attached Works as expected
  • Query Rule with network template attached Works as expected
  • Query Rule with process template attached Works as expected
  • Threshold Rule no template attached Works as expected
  • Threshold Rule with process template attached Works as expected
  • EQL Rule with no template attached Works as expected
  • EQL Rule with process template attached Works as expected

Regarding the non-alert views:

Hosts Page (Events, External Alerts)
Network Page (External Alerts)

Tested and they properly load an event in the timeline and fill the query builder.

Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

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

LGTM!

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 4.6MB 4.6MB +360.0B

Page load bundle

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

id before after diff
securitySolution 245.7KB 245.6KB -62.0B

History

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

@kqualters-elastic kqualters-elastic merged commit cef886f into elastic:main Jan 25, 2022
@kqualters-elastic kqualters-elastic deleted the open-in-timeline-cleanup branch January 25, 2022 06:39
@kibanamachine
Copy link
Contributor

The following labels were identified as gaps in your version labels and will be added automatically:

  • v8.1.0

If any of these should not be on your pull request, please manually remove them.

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 25, 2022
…mplate view (elastic#123333)

* Open alerts with a template, with a template

* Add default values back instead of template derived ones

* Use data providers over filters always, set timeline description to alert id

* Remove prepopulated description from non threshold alerts

* Open any event in timeline, use correct timestamp

* Remove unneeded @timestamp, make sure alertsEcsData is not empty array

* Add basic getField tests

* Explicity check if alertGroupId is an array instead of using length

* Always use a valid date for time range

* Only use filter if more than 1 alert is present

* Possibly controversial change to calculate threshold time range with a template, fix test that should never have passed

* Create threshold timeline in separate function

* Use better type for createTimeline passed to createThresholdTimeline

* Invert negation as suggested in pr comment

* Use template timeline filters/query/data providers for threshold alerts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit cef886f)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.0

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 25, 2022
…mplate view (#123333) (#123689)

* Open alerts with a template, with a template

* Add default values back instead of template derived ones

* Use data providers over filters always, set timeline description to alert id

* Remove prepopulated description from non threshold alerts

* Open any event in timeline, use correct timestamp

* Remove unneeded @timestamp, make sure alertsEcsData is not empty array

* Add basic getField tests

* Explicity check if alertGroupId is an array instead of using length

* Always use a valid date for time range

* Only use filter if more than 1 alert is present

* Possibly controversial change to calculate threshold time range with a template, fix test that should never have passed

* Create threshold timeline in separate function

* Use better type for createTimeline passed to createThresholdTimeline

* Invert negation as suggested in pr comment

* Use template timeline filters/query/data providers for threshold alerts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit cef886f)

Co-authored-by: Kevin Qualters <56408403+kqualters-elastic@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting:Investigations Security Solution Investigations Team v8.0.0 v8.0.1 v8.1.0
Projects
None yet
8 participants