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] Optimize field formatting server side #130915

Merged
merged 10 commits into from
May 11, 2022

Conversation

stephmilovic
Copy link
Contributor

@stephmilovic stephmilovic commented Apr 25, 2022

Summary

Server side field formatting optimization

Combines the two iterative functions that added category, description, and indexes (index alias) to each field. Optimization tested on 15k fields, async function runtime goes from ~700ms to ~300ms

@stephmilovic stephmilovic added release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting Security Solution Threat Hunting Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. auto-backport Deprecated - use backport:version if exact versions are needed Team:Threat Hunting:Explore v8.3.0 labels Apr 25, 2022
@stephmilovic stephmilovic requested a review from a team as a code owner April 25, 2022 17:15
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@kqualters-elastic
Copy link
Contributor

kqualters-elastic commented Apr 25, 2022

@stephmilovic can you add more context about what you are optimizing and why? Maybe also describe other places in this bit of code that could be potentially slow and improved a la #129861 ?

@stephmilovic
Copy link
Contributor Author

@kqualters-elastic Basically we were mapping over the fields twice when it can be done in one go. I combined the logic from formatFirstFields and formatSecondFields so now we are only mapping over each field once instead of twice. It's not a huge performance boost, but does cut down iteration in this part of the code by half

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

const fields = await formatFirstFields(beatFields, responsesFieldSpec, indexesAlias);
const secondFields = await formatSecondFields(fields);
return secondFields;
return formatFirstFields(beatFields, responsesFieldSpec, indexesAlias);
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick question, what's the benefit of combining both of theses into one call?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore this. Saw the comment from Kevin above late. My bad ✋🏾

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

const fields = await formatFirstFields(beatFields, responsesFieldSpec, indexesAlias);
const secondFields = await formatSecondFields(fields);
return secondFields;
return formatFirstFields(beatFields, responsesFieldSpec, indexesAlias);
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 you can get rid of this and just call formatFirstFields directly where needed. Only seems to be used in this file right now anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • I don't think this is under the platform codeowners, but should it be under both? Would you consider it a part of sourcerer overall? If not, happy to leave it to @michaelolo24 :)

@stephmilovic, could you please include the codeowners file update to this PR?

I actually don't see this directory referenced in CODEOWNERS. Looking at the PR, it only pinged @elastic/security-threat-hunting-investigations. I think @yctercero might be confusing the ping from my other PR which is still awaiting platform review

Copy link
Contributor

Choose a reason for hiding this comment

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

Testing that other one now! I'd just been going through the both of your open PRs. It seems like this deals with fetching the data views/fields, so I wondered if it was part of the larger data views architecture. If it's purely timeline and not an area of code platform needs to worry about, then all good 👍🏽

Copy link
Contributor

@yctercero yctercero left a comment

Choose a reason for hiding this comment

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

Thanks so much for jumping into the performance stuff here, Steph! Pulled down and tested before and after with 27K fields. Like you already mentioned in your comments,
I didn't see a huge performance change but see the code is cleaner. Had a few notes going through it.

  • Could we add some background to the PR description as to why we made this change, performance before/after? In case we somehow find we're slower we can go back and remember what our theory was in making a performance related change.
  • I don't think this is under the platform codeowners, but should it be under both? Would you consider it a part of sourcerer overall? If not, happy to leave it to @michaelolo24 :)
  • Since we're in this file, could we add docs to each of the functions in the file, giving a high level description of what each accomplishes? That could help in understanding which parts of the app they may affect.

@YulNaumenko
Copy link
Contributor

YulNaumenko commented May 2, 2022

  • I don't think this is under the platform codeowners, but should it be under both? Would you consider it a part of sourcerer overall? If not, happy to leave it to @michaelolo24 :)

@stephmilovic, could you please include the codeowners file update to this PR?

@cla-checker-service
Copy link

cla-checker-service bot commented May 2, 2022

💚 CLA has been signed

@stephmilovic
Copy link
Contributor Author

cla/check

@stephmilovic stephmilovic force-pushed the first_second_fields branch from b133c79 to d68ab96 Compare May 2, 2022 21:13
@stephmilovic
Copy link
Contributor Author

Thanks so much for jumping into the performance stuff here, Steph! Pulled down and tested before and after with 27K fields. Like you already mentioned in your comments, I didn't see a huge performance change but see the code is cleaner. Had a few notes going through it.

  • Could we add some background to the PR description as to why we made this change, performance before/after? In case we somehow find we're slower we can go back and remember what our theory was in making a performance related change.
  • I don't think this is under the platform codeowners, but should it be under both? Would you consider it a part of sourcerer overall? If not, happy to leave it to @michaelolo24 :)
  • Since we're in this file, could we add docs to each of the functions in the file, giving a high level description of what each accomplishes? That could help in understanding which parts of the app they may affect.

@yctercero done!

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.

LGTM - #131452 (Confirming we're merging this through the integration branch)

@stephmilovic stephmilovic mentioned this pull request May 4, 2022
9 tasks
@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests / Inspect Hosts stats and tables "before all" hook for "inspects the All Hosts Table"

Metrics [docs]

✅ unchanged

History

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

@stephmilovic stephmilovic merged commit 9c8796a into elastic:main May 11, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 11, 2022
@kibanamachine
Copy link
Contributor

⚪ Backport skipped

The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.

Manual backport

To create the backport manually run:

node scripts/backport --pr 130915

Questions ?

Please refer to the Backport tool documentation

@stephmilovic stephmilovic added v8.2.1 and removed backport:skip This commit does not require backporting labels May 11, 2022
academo pushed a commit to academo/kibana that referenced this pull request May 12, 2022
@tylersmalley tylersmalley added ci:cloud-deploy Create or update a Cloud deployment and removed ci:deploy-cloud labels Aug 17, 2022
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 ci:cloud-deploy Create or update a Cloud deployment release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting:Explore Team:Threat Hunting Security Solution Threat Hunting Team v8.2.1 v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants