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

[Secutiy Solution] Timeline kpis #89210

Merged

Conversation

kqualters-elastic
Copy link
Contributor

@kqualters-elastic kqualters-elastic commented Jan 25, 2021

Summary

Adds a component to timeline that shows kpi statistics. Also adds a search strategy kpi query to power these statistics, along with a container component that uses a series of hooks to fetch data based on existing timeline filters.
kpi_demo

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@kqualters-elastic kqualters-elastic added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.12.0 Team:Threat Hunting Security Solution Threat Hunting Team labels Jan 25, 2021
@kqualters-elastic kqualters-elastic marked this pull request as ready for review January 26, 2021 08:06
@elasticmachine
Copy link
Contributor

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

export interface TimelineKpiStrategyResponse extends IEsSearchResponse {
destinationIpCount: Maybe<number>;
inspect?: Maybe<Inspect>;
hostCount: Maybe<number>;
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these should technically be optional since Maybe<T> = T | null

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I agree, you do not need the Maybe or the optional since you will have 0 or the value.

For history, the Maybe is coming from the graphql when we had both type at the same time


beforeEach(() => {
mockUseSourcererScope.mockImplementation(() => defaultMocks);
useKibanaMock().services.application.capabilities = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you leave a comment explaining what these are and why their needed?

const getStartSelector = useMemo(() => startSelector(), []);
const getEndSelector = useMemo(() => endSelector(), []);
const isActive = useMemo(() => timelineId === TimelineId.active, [timelineId]);
const from = useDeepEqualSelector((state) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't specific to your PR, but I wonder what the performance improvement we get for the useDeepEqual vs just useSelector. Like are all these deep checks more costly than just re-rendering? Also, maybe just combining all of them into one, so you're only doing one deep check? 🤷🏾‍♂️


useEffect(() => {
if (isBlankTimeline) {
timelineKpiSearch(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of making a request that'll just return null? Can you comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was an extra line from an earlier way of doing this that after some refactoring amounted to just a noop basically, good catch though removing.

}, [docValueFields, defaultIndex, timerange, filterQuery]);

useEffect(() => {
if (isBlankTimeline) {
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 we can simplify it just by doing that

if (!isBlankTimeline) {
  timelineKpiSearch(timelineKpiRequest);
}

@kqualters-elastic
Copy link
Contributor Author

@elasticmachine merge upstream

@michaelolo24
Copy link
Contributor

Only thing I noticed is when you clear the filters so there's nothing in the view the KPI's don't clear out.

Screen Shot 2021-02-02 at 8 28 59 AM

Also, given that case ^^ Does it make sense to have the KPI's visible in other views like the pinned events view (see image below)? Maybe that's a question for @XavierM

Screen Shot 2021-02-02 at 8 31 42 AM

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, nice work!

@@ -328,7 +328,7 @@ const FlyoutHeaderComponent: React.FC<FlyoutHeaderProps> = ({ timelineId }) => {
</EuiFlexItem>

<EuiFlexItem grow={1}>
<TimelineKPIs kpis={kpis} isLoading={loading} />
{activeTab === 'query' ? <TimelineKPIs kpis={kpis} isLoading={loading} /> : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you end up having to push any other changes there's an enum TimelineTabs.query that you can use here. Not necessary though

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2177 2179 +2

Async chunks

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

id before after diff
securitySolution 7.5MB 7.5MB +8.8KB

History

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

@kqualters-elastic kqualters-elastic merged commit 3da4c6b into elastic:master Feb 2, 2021
@kqualters-elastic kqualters-elastic deleted the siem-timeline-kpis branch February 2, 2021 23:30
kqualters-elastic added a commit that referenced this pull request Feb 3, 2021
* Stub kpi component

* search strategy scheleton timeline KPI

* search strategy scheleton timeline KPI

* Add timeline kpis component and search strategy container

* Use getEmptyValue in timeline kpis

* Prevent request from being made for blank timeline properly

* Add kpi search strategy api integration test

* Add jest tests for timeline kpis

* Clear mocks in afterAll

* Decouple some tests from EUI structure

* Combine some selector calls, change types to be more appropriate

* Simplify hook logic

* Set loading and response on blank timeline

* Only render kpi component when query is active tab

* Use TimelineTabs enum for query tab string

Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting Security Solution Threat Hunting Team v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants