From 95edbd832dd83b8089d5eebdd341691a68b898c8 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 23 Mar 2020 16:04:08 +0100 Subject: [PATCH 1/5] Fix auto-expanding of shards in profile tree --- .../profile_tree/shard_details/shard_details.tsx | 16 +++++++++++++++- .../searchprofiler/public/application/types.ts | 9 ++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/shard_details/shard_details.tsx b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/shard_details/shard_details.tsx index 5ca8ad4ecd979..ac2a2997515d5 100644 --- a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/shard_details/shard_details.tsx +++ b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/shard_details/shard_details.tsx @@ -18,10 +18,24 @@ interface Props { operations: Operation[]; } +const hasVisibleOperation = (ops: Operation[]): boolean => { + for (const op of ops) { + if (op.visible) { + return true; + } + if (op.children?.length && hasVisibleOperation(op.children)) { + return true; + } + } + return false; +}; + export const ShardDetails = ({ index, shard, operations }: Props) => { const { relative, time } = shard; - const [shardVisibility, setShardVisibility] = useState(false); + const [shardVisibility, setShardVisibility] = useState(() => + hasVisibleOperation(operations.map(op => op.treeRoot ?? op)) + ); return ( <> diff --git a/x-pack/plugins/searchprofiler/public/application/types.ts b/x-pack/plugins/searchprofiler/public/application/types.ts index 9866f8d5b1ccb..5680cba137f70 100644 --- a/x-pack/plugins/searchprofiler/public/application/types.ts +++ b/x-pack/plugins/searchprofiler/public/application/types.ts @@ -49,7 +49,14 @@ export interface Operation { parent: Operation | null; children: Operation[]; - // Only exists on top level + /** + * Only exists on top level. + * + * @remark + * For now, when we init profile data for rendering we take a top-level + * operation and designate it the root of the operations tree - this is not + * information we get from ES! + */ treeRoot?: Operation; depth?: number; From c1781f2b83b2078bf86c15e562dd38169974e8cb Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 23 Mar 2020 16:10:17 +0100 Subject: [PATCH 2/5] Fix bad error message for ES errors that don't have line numbers --- .../public/application/hooks/use_request_profile.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/searchprofiler/public/application/hooks/use_request_profile.ts b/x-pack/plugins/searchprofiler/public/application/hooks/use_request_profile.ts index 3d8bee1d62b27..435db4a98c552 100644 --- a/x-pack/plugins/searchprofiler/public/application/hooks/use_request_profile.ts +++ b/x-pack/plugins/searchprofiler/public/application/hooks/use_request_profile.ts @@ -22,7 +22,9 @@ interface ReturnValue { const extractProfilerErrorMessage = (e: any): string | undefined => { if (e.body?.attributes?.error?.reason) { const { reason, line, col } = e.body.attributes.error; - return `${reason} at line: ${line - 1} col: ${col}`; + if (typeof line === 'number' && typeof col === 'number') { + return `${reason} at line: ${line - 1} col: ${col}`; + } } if (e.body?.message) { From 3c80f43b8334998c18a4930942d4355af8a491a5 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 23 Mar 2020 16:17:15 +0100 Subject: [PATCH 3/5] Add error message for bad profile data --- .../__tests__/profile_tree.test.tsx | 1 + .../components/profile_tree/profile_tree.tsx | 4 +++- .../application/containers/main/main.tsx | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx index 1286f30d69c26..c2900a57d4f5a 100644 --- a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx +++ b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx @@ -14,6 +14,7 @@ describe('ProfileTree', () => { onHighlight: () => {}, target: 'searches', data: searchResponse, + onDataInitError: jest.fn(), }; const init = registerTestBed(ProfileTree); await init(props); diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx index 1dec8f0161c52..915cb157f13d1 100644 --- a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx +++ b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx @@ -17,9 +17,10 @@ export interface Props { target: Targets; data: ShardSerialized[] | null; onHighlight: (args: OnHighlightChangeArgs) => void; + onDataInitError: (error: Error) => void; } -export const ProfileTree = memo(({ data, target, onHighlight }: Props) => { +export const ProfileTree = memo(({ data, target, onHighlight, onDataInitError }: Props) => { if (!data || data.length === 0) { return null; } @@ -30,6 +31,7 @@ export const ProfileTree = memo(({ data, target, onHighlight }: Props) => { } catch (e) { // eslint-disable-next-line no-console console.error(e); + onDataInitError(e); return null; } diff --git a/x-pack/plugins/searchprofiler/public/application/containers/main/main.tsx b/x-pack/plugins/searchprofiler/public/application/containers/main/main.tsx index aa6c20aa6a7f3..11dbc6b320531 100644 --- a/x-pack/plugins/searchprofiler/public/application/containers/main/main.tsx +++ b/x-pack/plugins/searchprofiler/public/application/containers/main/main.tsx @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import React, { useCallback } from 'react'; import { @@ -33,7 +34,7 @@ import { useProfilerActionContext, useProfilerReadContext } from '../../contexts import { hasAggregations, hasSearch } from '../../utils'; export const Main = () => { - const { getLicenseStatus } = useAppContext(); + const { getLicenseStatus, notifications } = useAppContext(); const { activeTab, @@ -42,8 +43,17 @@ export const Main = () => { pristine, profiling, } = useProfilerReadContext(); + const dispatch = useProfilerActionContext(); + const handleProfileTreeError = (e: Error) => { + notifications.addError(e, { + title: i18n.translate('xpack.searchProfiler.profileTreeErrorRenderTitle', { + defaultMessage: 'Profile data cannot be parsed.', + }), + }); + }; + const setActiveTab = useCallback( (target: Targets) => dispatch({ type: 'setActiveTab', value: target }), [dispatch] @@ -70,7 +80,12 @@ export const Main = () => { if (activeTab) { return (
- +
); } From 190bb5dab4aae8c9c600e81ad63f1bf51930ef24 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Tue, 24 Mar 2020 11:43:48 +0100 Subject: [PATCH 4/5] Fix type and test issues and rename __test__ folder to __jest__ --- .../profile_tree/{__tests__ => __jest__}/fixtures/breakdown.ts | 0 .../{__tests__ => __jest__}/fixtures/normalize_indices.ts | 0 .../{__tests__ => __jest__}/fixtures/normalize_times.ts | 0 .../fixtures/processed_search_response.ts | 0 .../{__tests__ => __jest__}/fixtures/search_response.ts | 0 .../profile_tree/{__tests__ => __jest__}/init_data.test.ts | 0 .../profile_tree/{__tests__ => __jest__}/profile_tree.test.tsx | 2 ++ .../profile_tree/{__tests__ => __jest__}/unsafe_utils.test.ts | 0 .../profile_tree/{__tests__ => __jest__}/utils.test.ts | 0 .../public/application/components/profile_tree/profile_tree.tsx | 2 -- 10 files changed, 2 insertions(+), 2 deletions(-) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/fixtures/breakdown.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/fixtures/normalize_indices.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/fixtures/normalize_times.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/fixtures/processed_search_response.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/fixtures/search_response.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/init_data.test.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/profile_tree.test.tsx (92%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/unsafe_utils.test.ts (100%) rename x-pack/plugins/searchprofiler/public/application/components/profile_tree/{__tests__ => __jest__}/utils.test.ts (100%) diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/breakdown.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/breakdown.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/breakdown.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/breakdown.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/normalize_indices.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/normalize_indices.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/normalize_indices.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/normalize_indices.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/normalize_times.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/normalize_times.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/normalize_times.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/normalize_times.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/processed_search_response.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/processed_search_response.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/processed_search_response.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/processed_search_response.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/search_response.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/search_response.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/fixtures/search_response.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/fixtures/search_response.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/init_data.test.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/init_data.test.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/init_data.test.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/init_data.test.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/profile_tree.test.tsx similarity index 92% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/profile_tree.test.tsx index c2900a57d4f5a..64f77e8b4e52c 100644 --- a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/profile_tree.test.tsx +++ b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/profile_tree.test.tsx @@ -25,10 +25,12 @@ describe('ProfileTree', () => { const props: Props = { onHighlight: () => {}, target: 'searches', + onDataInitError: jest.fn(), data: [{}] as any, }; const init = registerTestBed(ProfileTree); await init(props); + expect(props.onDataInitError).toHaveBeenCalled(); }); }); diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/unsafe_utils.test.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/unsafe_utils.test.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/unsafe_utils.test.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/unsafe_utils.test.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/utils.test.ts b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/utils.test.ts similarity index 100% rename from x-pack/plugins/searchprofiler/public/application/components/profile_tree/__tests__/utils.test.ts rename to x-pack/plugins/searchprofiler/public/application/components/profile_tree/__jest__/utils.test.ts diff --git a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx index 915cb157f13d1..ade547a7d440f 100644 --- a/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx +++ b/x-pack/plugins/searchprofiler/public/application/components/profile_tree/profile_tree.tsx @@ -29,8 +29,6 @@ export const ProfileTree = memo(({ data, target, onHighlight, onDataInitError }: try { sortedIndices = initDataFor(target)(data); } catch (e) { - // eslint-disable-next-line no-console - console.error(e); onDataInitError(e); return null; } From 6db950c7b9ec0cbd1b00b538dd37975dc7c1c640 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Tue, 24 Mar 2020 11:46:26 +0100 Subject: [PATCH 5/5] =?UTF-8?q?!=20=F0=9F=91=89=F0=9F=8F=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- x-pack/plugins/searchprofiler/public/application/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/searchprofiler/public/application/types.ts b/x-pack/plugins/searchprofiler/public/application/types.ts index 5680cba137f70..896af0851eb52 100644 --- a/x-pack/plugins/searchprofiler/public/application/types.ts +++ b/x-pack/plugins/searchprofiler/public/application/types.ts @@ -55,7 +55,7 @@ export interface Operation { * @remark * For now, when we init profile data for rendering we take a top-level * operation and designate it the root of the operations tree - this is not - * information we get from ES! + * information we get from ES. */ treeRoot?: Operation;