Skip to content

Commit

Permalink
[Security Solution] Fix timeline dynamic batching (#204034)
Browse files Browse the repository at this point in the history
## Summary

Handles :


### Issue with Batches
- #201405
- Timeline had a bug where if users fetched multiple batches and then if
user adds a new column, the value of this new columns will only be
fetched for the latest batch and not old batches.
- This PR fixes that ✅ by cumulatively fetching the data for old batches
till current batch `iff a new column has been added`.
- For example, if user has already fetched the 3rd batch, data for
1st,2nd and 3rd will be fetched together when a column has been added,
otherwise, data will be fetched incrementally.

### Issue with Elastic search limit

- Elastic search has a limit of 10K hits at max but we throw error at
10K which should be allowed.
    - Error should be thrown at anything `>10K`. 10001 for example.
    - ✅  This PR fixes that just for timeline by allowing 10K hits.

### Removal of obsolete code

Below files related to old Timeline code are removed as well:
-
x-pack/plugins/security_solution/public/timelines/components/timeline/footer/index.test.tsx
-
x-pack/plugins/security_solution/public/timelines/components/timeline/footer/index.tsx

---------

Co-authored-by: Philippe Oberti <[email protected]>
  • Loading branch information
logeekal and PhilippeOberti authored Jan 7, 2025
1 parent 47b19ba commit 088169f
Show file tree
Hide file tree
Showing 18 changed files with 796 additions and 1,027 deletions.
1 change: 0 additions & 1 deletion packages/kbn-babel-preset/styled_components_files.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40634,7 +40634,6 @@
"xpack.securitySolution.flyout.user.closeButton": "fermer",
"xpack.securitySolution.flyout.user.preview.viewDetailsLabel": "Afficher tous les détails de l'utilisateur",
"xpack.securitySolution.footer.autoRefreshActiveDescription": "Actualisation automatique active",
"xpack.securitySolution.footer.autoRefreshActiveTooltip": "Lorsque l'actualisation automatique est activée, la chronologie vous montrera les {numberOfItems} derniers événements correspondant à votre recherche.",
"xpack.securitySolution.footer.cancel": "Annuler",
"xpack.securitySolution.footer.data": "données",
"xpack.securitySolution.footer.events": "Événements",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40491,7 +40491,6 @@
"xpack.securitySolution.flyout.user.closeButton": "閉じる",
"xpack.securitySolution.flyout.user.preview.viewDetailsLabel": "すべてのユーザー詳細を表示",
"xpack.securitySolution.footer.autoRefreshActiveDescription": "自動更新アクション",
"xpack.securitySolution.footer.autoRefreshActiveTooltip": "自動更新が有効な間、タイムラインはクエリーに一致する最新の {numberOfItems} 件のイベントを表示します。",
"xpack.securitySolution.footer.cancel": "キャンセル",
"xpack.securitySolution.footer.data": "データ",
"xpack.securitySolution.footer.events": "イベント",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39895,7 +39895,6 @@
"xpack.securitySolution.flyout.user.closeButton": "关闭",
"xpack.securitySolution.flyout.user.preview.viewDetailsLabel": "显示全部用户详情",
"xpack.securitySolution.footer.autoRefreshActiveDescription": "自动刷新已启用",
"xpack.securitySolution.footer.autoRefreshActiveTooltip": "自动刷新已启用时,时间线将显示匹配查询的最近 {numberOfItems} 个事件。",
"xpack.securitySolution.footer.cancel": "取消",
"xpack.securitySolution.footer.data": "数据",
"xpack.securitySolution.footer.events": "事件",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export type OnColumnRemoved = (columnId: ColumnId) => void;

export type OnColumnResized = ({ columnId, delta }: { columnId: ColumnId; delta: number }) => void;

/** Invoked when a user clicks to load more item */
export type OnFetchMoreRecords = (nextPage: number) => void;
/** Invoked when a user clicks to load next batch */
export type OnFetchMoreRecords = VoidFunction;

/** Invoked when a user checks/un-checks a row */
export type OnRowSelected = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { mockTimelineData } from './mock_timeline_data';

const mockEvents = structuredClone(mockTimelineData);

/*
* This helps to mock `data.search.search` method to mock the timeline data
* */
export const getMockTimelineSearchSubscription = () => {
const mockSearchWithArgs = jest.fn();

const mockTimelineSearchSubscription = jest.fn().mockImplementation((args) => {
mockSearchWithArgs(args);
return {
subscribe: jest.fn().mockImplementation(({ next }) => {
const start = args.pagination.activePage * args.pagination.querySize;
const end = start + args.pagination.querySize;
const timelineOut = setTimeout(() => {
next({
isRunning: false,
isPartial: false,
inspect: {
dsl: [],
response: [],
},
edges: mockEvents.map((item) => ({ node: item })).slice(start, end),
pageInfo: {
activePage: args.pagination.activePage,
querySize: args.pagination.querySize,
},
rawResponse: {},
totalCount: mockEvents.length,
});
}, 50);
return {
unsubscribe: jest.fn(() => {
clearTimeout(timelineOut);
}),
};
}),
};
});

return { mockTimelineSearchSubscription, mockSearchWithArgs };
};

This file was deleted.

Loading

0 comments on commit 088169f

Please sign in to comment.