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][Resolver] Resolver query panel load more #79160

Conversation

kqualters-elastic
Copy link
Contributor

@kqualters-elastic kqualters-elastic commented Oct 1, 2020

Summary

This pr adds a load more feature to the events by type panel view of resolver. When a user clicks into the events by type panel, either from the graph directly or by drilling down, a request is made for the first 25 events in a category. If there are >25 total events, a cursor field is provided, a base64 encoded string of the id and timestamp of event 25, which is then provided in the next request for the 2nd page. Each response is appended to the list of events in the UI each time a user selects the "Load More Data" button. Once a response comes back without the nextEvent cursor, the button is hidden. An error message is shown for either the initial or paginated requests.

resolver_load_more
image

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@kqualters-elastic kqualters-elastic force-pushed the resolver-query-panel-load-more branch from 737c82e to 532332d Compare October 5, 2020 13:57
const nextState: DataState = {
...state,
nodeEventsInCategory: {
nodeID: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following the logic here.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're spreading in state.nodeEventsInCategory. You shouldn't need to add their nullish fields. What TS error are you getting?

@oatkiller
Copy link
Contributor

@kqualters-elastic kqualters-elastic force-pushed the resolver-query-panel-load-more branch from 52f4d19 to bef65d3 Compare October 5, 2020 20:43
@kqualters-elastic kqualters-elastic added v7.10.0 Feature:Resolver Security Solution Resolver feature release_note:skip Skip the PR/issue when compiling release notes labels Oct 5, 2020
@kqualters-elastic kqualters-elastic marked this pull request as ready for review October 5, 2020 20:49
@kqualters-elastic kqualters-elastic requested review from a team as code owners October 5, 2020 20:49
@kqualters-elastic kqualters-elastic changed the title Resolver query panel load more [Security Solution][Resolver] Resolver query panel load more Oct 5, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-app-team (Feature:Resolver)

} else if (action.type === 'userRequestedAdditionalRelatedEvents') {
const nodeEventsInCategory = state.data.nodeEventsInCategory;
if (nodeEventsInCategory !== undefined) {
api.dispatch({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do away with this action? The state should already know that loading is happening. Also, the initial request for data doesn't fire any action like this.

const handleLoadMore = useCallback(() => {
dispatch({
type: 'userRequestedAdditionalRelatedEvents',
payload: {},
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 remove the payload here.

{hasMore && (
<EuiFlexItem grow={false}>
<EuiButton color={'primary'} size="s" fill onClick={handleLoadMore} isLoading={isLoading}>
{'Load More Data'}
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 wrap this in i18n.

@@ -50,7 +52,7 @@ export function dataAccessLayerFactory(
after?: string
): Promise<ResolverPaginatedEvents> {
return context.services.http.post('/api/endpoint/resolver/events', {
query: { afterEvent: after },
query: { afterEvent: after, limit: relatedEventsPaginationSize },
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be specified on the BE as the 'default' instead of specifying it here. That way we don't have two places defining this value.

(event) => event.event?.category === category
);
if (after === undefined) {
events = eventsOfCategory.slice(0, relatedEventsPaginationSize);
Copy link
Contributor

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 mock should reference relatedEventsPaginationSize. I think you could redefine this here const relatedEventsPaginationSize = 25. I think you even use any arbitrary number you want. Is there some reason I'm missing?

() =>
simulator().testSubject('resolver:panel:node-events-in-category:event-link').length
)
).toYieldEqualTo(30);
Copy link
Contributor

Choose a reason for hiding this comment

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

The test says 31 but this checks for 30. can you correct the test message?

() => simulator().testSubject('resolver:nodeEventsInCategory:loadMore').length
)
).toYieldEqualTo(0);
await expect(
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 combine this expect with the one above it?

iconType="alert"
data-test-subj="resolver:nodeEventsInCategory:error"
>
<p>{'An error occurred when fetching the events.'}</p>
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 put this in i18n?

<NodeEventList eventCategory={eventCategory} nodeID={nodeID} events={events} />
{hasError ? (
<EuiCallOut
title="Unable to load events."
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 put this in i18n?

@@ -207,7 +254,7 @@ const NodeEventsInCategoryBreadcrumbs = memo(function ({
text: (
<FormattedMessage
id="xpack.securitySolution.endpoint.resolver.panel.relatedEventList.numberOfEvents"
values={{ totalCount: eventCount }}
values={{ totalCount: eventCount || '0' }}
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 instead hide this text when the event count hasn't loaded yet? Showing 0 during loading could be strange if the request is slow to come back.

for (let i = 0; i < eventsToGenerate; i++) {
const newEvent = mockEndpointEvent({
entityID: originID,
eventID: 'test',
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe make the eventID something like test-${i} in case we want to interact with the individual events on a page-by-page basis in the test we can, and verify the right event shows up at the right time

},
});
}
} else if (newParams.panelView === 'eventDetail') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

return (
<>
{eventCount === undefined || processEvent === null ? (
{isLoading || processEvent === null ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

)}
color="danger"
iconType="alert"
data-test-subj="resolver:nodeEventsInCategory:error"
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't really matter (nit?). I think we're hyphenating these node-events-in-category

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll add follow up ticket

<EuiSpacer size="l" />
<NodeEventList eventCategory={eventCategory} nodeID={nodeID} events={events} />
{hasError ? (
<EuiCallOut
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we migrate this to panel_content_error and expand from this to error, 404, and loading component to be used in the graph itself and the panel like @oatkiller suggested a while back

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.

Just tested it, looks good. Nice work! 💪

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
securitySolution 10.3MB 10.3MB +14.1KB

History

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

@kqualters-elastic kqualters-elastic merged commit 32d45b6 into elastic:master Oct 6, 2020
@kqualters-elastic kqualters-elastic deleted the resolver-query-panel-load-more branch October 6, 2020 01:43
kqualters-elastic added a commit to kqualters-elastic/kibana that referenced this pull request Oct 6, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 6, 2020
* master: (85 commits)
  Refactor attribute service (elastic#78414)
  [APM] Add default message to alerts. (elastic#78930)
  [Discover] Modify columns and sort when switching index pattern (elastic#74336)
  Document ts project references setup (elastic#78586)
  build all ts refs in single kbn:bootstrap (elastic#79438)
  [TSVB] Allow string fields on value count aggregation (elastic#79267)
  [SECURITY SOLUTION] Investigate EQL signal in timeline (elastic#79049)
  [Fleet] Add loading spinner to page headers (elastic#79568)
  [Security Solution][Resolver] Resolver query panel load more (elastic#79160)
  Add type row to monitor detail page. (elastic#79556)
  Remove license refresh from setup (elastic#79518)
  [docker] add reporting fonts (elastic#74806)
  [SECURITY_SOLUTION][ENDPOINT] Add info about trusted apps to the page subtitle + create flyout (elastic#79558)
  Trim Hash value before validating it (elastic#79545)
  Warn users when security is not configured (elastic#78545)
  update copy styling (elastic#79313)
  Update dependency @elastic/charts to v23.1.1 (elastic#78459)
  Introduce geo-threshold alerts (elastic#76285)
  elastic#76920 Show base breadcrumb when there is an error booting the app (elastic#79571)
  remove react-intl from kibana and keep it inside only i18n package (elastic#78956)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Resolver Security Solution Resolver feature release_note:skip Skip the PR/issue when compiling release notes v7.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants