From 2c33e97b0f37f4ef453c5f704f39a8a50b3973f1 Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Mon, 9 Sep 2024 15:01:19 +0200 Subject: [PATCH] [Lens][Telemetry] Track Elasticsearch `took` time in Lens editor (#192245) ## Summary This commit separates the ES `took` time from the `time_to_data` telemetry in the EBT performance journey for the Lens Editor. --- .../workspace_panel/workspace_panel.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx index bfca879d18d73..c38bfb2cc86f0 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx @@ -28,6 +28,7 @@ import { DropIllustration } from '@kbn/chart-icons'; import { useDragDropContext, DragDropIdentifier, Droppable } from '@kbn/dom-drag-drop'; import { reportPerformanceMetricEvent } from '@kbn/ebt-tools'; import { ChartSizeSpec, isChartSizeEvent } from '@kbn/chart-expressions-common'; +import { estypes } from '@elastic/elasticsearch'; import { trackUiCounterEvents } from '../../../lens_ui_telemetry'; import { getSearchWarningMessages } from '../../../utils'; import { @@ -192,6 +193,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ // NOTE: initialRenderTime is only set once when the component mounts const visualizationRenderStartTime = useRef(NaN); const dataReceivedTime = useRef(NaN); + const esTookTime = useRef(0); const onRender$ = useCallback(() => { if (renderDeps.current) { @@ -203,9 +205,12 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ eventName: 'lensVisualizationRenderTime', duration: currentTime - visualizationRenderStartTime.current, key1: 'time_to_data', - value1: dataReceivedTime.current - visualizationRenderStartTime.current, + value1: + dataReceivedTime.current - visualizationRenderStartTime.current - esTookTime.current, key2: 'time_to_render', value2: currentTime - dataReceivedTime.current, + key3: 'es_took', + value3: esTookTime.current, }); } const datasourceEvents = Object.values(renderDeps.current.datasourceMap).reduce( @@ -263,6 +268,13 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ searchService: plugins.data.search, } ); + esTookTime.current = adapters.requests.getRequests().reduce((maxTime, { response }) => { + const took = + (response?.json as { rawResponse: estypes.SearchResponse | undefined } | undefined) + ?.rawResponse?.took ?? 0; + + return Math.max(maxTime, took); + }, 0); } if (requestWarnings.length) {