Skip to content

Commit

Permalink
[Lens][Telemetry] Track Elasticsearch took time in Lens editor (ela…
Browse files Browse the repository at this point in the history
…stic#192245)

## Summary
This commit separates the ES `took` time from the `time_to_data` telemetry in the EBT performance journey for the Lens Editor.
  • Loading branch information
markov00 authored Sep 9, 2024
1 parent 78dc7a5 commit 2c33e97
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -192,6 +193,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
// NOTE: initialRenderTime is only set once when the component mounts
const visualizationRenderStartTime = useRef<number>(NaN);
const dataReceivedTime = useRef<number>(NaN);
const esTookTime = useRef<number>(0);

const onRender$ = useCallback(() => {
if (renderDeps.current) {
Expand All @@ -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<string[]>(
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2c33e97

Please sign in to comment.