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

[CTI] ensures isThreatIntelModuleEnabled query for Overview page is made only once #104523

Merged
merged 4 commits into from
Jul 7, 2021

Conversation

ecezalp
Copy link
Contributor

@ecezalp ecezalp commented Jul 6, 2021

Summary

The initial query to check whether the Threat Intel module is enabled was being made multiple times (on the Overview page) as the CTI Dashboard Links component rerendered. This is an undesired behavior considering the answer would never change during those rerenders, and the query should be made only once.

@ecezalp ecezalp requested a review from a team as a code owner July 6, 2021 18:15
@ecezalp ecezalp self-assigned this Jul 6, 2021
@ecezalp ecezalp added release_note:skip Skip the PR/issue when compiling release notes v7.14.0 auto-backport Deprecated - use backport:version if exact versions are needed Team: CTI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Jul 6, 2021
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

Some minor nits, but LGTM.

This might be easy to add a regression unit test for: mock the hook, pass the component the expected props, and verify that the hook is only called once?

@@ -18,7 +18,7 @@ export const useCtiEventCounts = ({
from,
setQuery,
to,
}: ThreatIntelLinkPanelProps) => {
}: Omit<ThreatIntelLinkPanelProps, 'isThreatIntelModuleEnabled'>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might be trying too hard here to reuse these types; if this hook and the component that share(d) props have independent use cases, they should each declare their own props.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

declared a new type for CtiEnabledModuleProps, which is the same Omit<ThreatIntelLinkPanelProps, 'isThreatIntelModuleEnabled'> it's used in 2 places and a bit more readable IMHO, let me know what you think

export const ThreatIntelLinkPanel = React.memo(ThreatIntelLinkPanelComponent);
export const ThreatIntelLinkPanel = React.memo(
ThreatIntelLinkPanelComponent,
(prevProps, nextProps) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function implicitly excluding some prop from the comparison? If it is, a comment to that effect would be good for posterity. If it's not, then we can probably do away with this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -23,7 +23,7 @@ const warning = (

export const CtiNoEventsComponent = ({ to, from }: { to: string; from: string }) => {
const { buttonHref, listItems, isDashboardPluginDisabled } = useCtiDashboardLinks(
{ ...emptyEventCountsByDataset },
emptyEventCountsByDataset,
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this the cause of many rerenders, or just an unnecessary spread you also noticed? Hard to tell from the PR.

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 have a hard time reproducing so I wasn't sure if this one was the cause or the other one (non-empty eventCountsByDataset) but I think it's a good idea to ensure that the first arg of useCtiDashboardLinks is identical in this case, and compared via lodash in the case of cti_with_events.tsx

@ecezalp
Copy link
Contributor Author

ecezalp commented Jul 7, 2021

latest changes:

  • added unit test that expects useThreatIntelModuleEnabledMock toHaveBeenCalledTimes(1)
  • removed unnecessary equality comparison from overview_cti_links/index
  • declared new type CtiEnabledModuleProps

@spalger spalger added the v7.15.0 label Jul 7, 2021
@kibanamachine
Copy link
Contributor

💚 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 6.3MB 6.3MB +349.0B

History

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

cc @ecezalp

@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.14
7.x

The backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jul 7, 2021
…ade only once (#104523) (#104711)

Co-authored-by: Ece Özalp <ozale272@newschool.edu>
kibanamachine added a commit that referenced this pull request Jul 7, 2021
…ade only once (#104523) (#104710)

Co-authored-by: Ece Özalp <ozale272@newschool.edu>
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: CTI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.14.0 v7.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants