Skip to content

Commit

Permalink
[8.10] [ML] AIOps: Fix render loop when using saved search. (#166934) (
Browse files Browse the repository at this point in the history
…#166956)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[ML] AIOps: Fix render loop when using saved search.
(#166934)](#166934)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Walter
Rafelsberger","email":"walter.rafelsberger@elastic.co"},"sourceCommit":{"committedDate":"2023-09-21T15:28:38Z","message":"[ML]
AIOps: Fix render loop when using saved search. (#166934)\n\n##
Summary\r\n\r\nFixes #166079.\r\n\r\nIf a user picked a saved search to
investigate, the log pattern analysis\r\npage would freeze with an
infinite render loop; the log rate analysis\r\npate wouldn't freeze but
repeatedly query for new data.\r\n\r\nThis PR fixes the issue by
memoizing the queries derived from the saved\r\nsearch information to
avoid it being a new instance every time.\r\n\r\n### Checklist\r\n\r\n-
[x] This was checked for breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"fabaa2f89ecc7737b744b1a352251dc654d564a8","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix",":ml","Feature:ML/AIOps","v8.11.0","v8.10.3"],"number":166934,"url":"https://github.com/elastic/kibana/pull/166934","mergeCommit":{"message":"[ML]
AIOps: Fix render loop when using saved search. (#166934)\n\n##
Summary\r\n\r\nFixes #166079.\r\n\r\nIf a user picked a saved search to
investigate, the log pattern analysis\r\npage would freeze with an
infinite render loop; the log rate analysis\r\npate wouldn't freeze but
repeatedly query for new data.\r\n\r\nThis PR fixes the issue by
memoizing the queries derived from the saved\r\nsearch information to
avoid it being a new instance every time.\r\n\r\n### Checklist\r\n\r\n-
[x] This was checked for breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"fabaa2f89ecc7737b744b1a352251dc654d564a8"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/166934","number":166934,"mergeCommit":{"message":"[ML]
AIOps: Fix render loop when using saved search. (#166934)\n\n##
Summary\r\n\r\nFixes #166079.\r\n\r\nIf a user picked a saved search to
investigate, the log pattern analysis\r\npage would freeze with an
infinite render loop; the log rate analysis\r\npate wouldn't freeze but
repeatedly query for new data.\r\n\r\nThis PR fixes the issue by
memoizing the queries derived from the saved\r\nsearch information to
avoid it being a new instance every time.\r\n\r\n### Checklist\r\n\r\n-
[x] This was checked for breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"fabaa2f89ecc7737b744b1a352251dc654d564a8"}},{"branch":"8.10","label":"v8.10.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Walter Rafelsberger <walter.rafelsberger@elastic.co>
  • Loading branch information
kibanamachine and walterra committed Sep 25, 2023
1 parent cb646e0 commit 12edeaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Expand Up @@ -71,7 +71,7 @@ export const LogCategorizationPage: FC = () => {
const [globalState, setGlobalState] = useUrlState('_g');
const [selectedField, setSelectedField] = useState<string | undefined>();
const [selectedCategory, setSelectedCategory] = useState<Category | null>(null);
const [selectedSavedSearch, setSelectedDataView] = useState(savedSearch);
const [selectedSavedSearch, setSelectedSavedSearch] = useState(savedSearch);
const [loading, setLoading] = useState(false);
const [totalCount, setTotalCount] = useState(0);
const [eventRate, setEventRate] = useState<EventRate>([]);
Expand All @@ -91,7 +91,7 @@ export const LogCategorizationPage: FC = () => {

useEffect(() => {
if (savedSearch) {
setSelectedDataView(savedSearch);
setSelectedSavedSearch(savedSearch);
}
}, [savedSearch]);

Expand All @@ -114,7 +114,7 @@ export const LogCategorizationPage: FC = () => {
// When the user loads saved search and then clear or modify the query
// we should remove the saved search and replace it with the index pattern id
if (selectedSavedSearch !== null) {
setSelectedDataView(null);
setSelectedSavedSearch(null);
}

setUrlState({
Expand Down
18 changes: 12 additions & 6 deletions x-pack/plugins/aiops/public/hooks/use_search.ts
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { useMemo } from 'react';

import type { DataView } from '@kbn/data-views-plugin/public';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';

Expand All @@ -24,12 +26,16 @@ export const useSearch = (
},
} = useAiopsAppContext();

const searchData = getEsQueryFromSavedSearch({
dataView,
uiSettings,
savedSearch,
filterManager,
});
const searchData = useMemo(
() =>
getEsQueryFromSavedSearch({
dataView,
uiSettings,
savedSearch,
filterManager,
}),
[dataView, uiSettings, savedSearch, filterManager]
);

if (searchData === undefined || (aiopsListState && aiopsListState.searchString !== '')) {
if (aiopsListState?.filters && readOnly === false) {
Expand Down

0 comments on commit 12edeaa

Please sign in to comment.