Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens][Telemetry] Track Elasticsearch took time in Lens editor #192245

Merged
merged 8 commits into from
Sep 9, 2024
Merged
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