Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('ProfileTree', () => {
onHighlight: () => {},
target: 'searches',
data: searchResponse,
onDataInitError: jest.fn(),
};
const init = registerTestBed(ProfileTree);
await init(props);
Expand All @@ -24,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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -28,8 +29,7 @@ export const ProfileTree = memo(({ data, target, onHighlight }: Props) => {
try {
sortedIndices = initDataFor(target)(data);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
onDataInitError(e);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
const [shardVisibility, setShardVisibility] = useState<boolean>(() =>
hasVisibleOperation(operations.map(op => op.treeRoot ?? op))
);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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]
Expand All @@ -70,7 +80,12 @@ export const Main = () => {
if (activeTab) {
return (
<div className="prfDevTool__main__profiletree">
<ProfileTree onHighlight={onHighlight} target={activeTab} data={currentResponse} />
<ProfileTree
onDataInitError={handleProfileTreeError}
onHighlight={onHighlight}
target={activeTab}
data={currentResponse}
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/searchprofiler/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down