mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Lens] Add ES-request time telemetry to Lens embeddable (#192743)
## Summary Similar to https://github.com/elastic/kibana/pull/192245, this adds request-time to the Lens Embeddable. This would allow to track these metrics anywhere where Lens is embedded. This is particularly important for Lens embedded in a Dashboard since all performance journeys are written against Dashboards. ### Checklist Delete any items that are not applicable to this PR. - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
This commit is contained in:
parent
8a79173c4e
commit
682afb7d8c
3 changed files with 54 additions and 9 deletions
|
@ -28,7 +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 { getSuccessfulRequestTimings } from '../../../report_performance_metric_util';
|
||||
import { trackUiCounterEvents } from '../../../lens_ui_telemetry';
|
||||
import { getSearchWarningMessages } from '../../../utils';
|
||||
import {
|
||||
|
@ -205,8 +205,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({
|
|||
eventName: 'lensVisualizationRenderTime',
|
||||
duration: currentTime - visualizationRenderStartTime.current,
|
||||
key1: 'time_to_data',
|
||||
value1:
|
||||
dataReceivedTime.current - visualizationRenderStartTime.current - esTookTime.current,
|
||||
value1: dataReceivedTime.current - visualizationRenderStartTime.current,
|
||||
key2: 'time_to_render',
|
||||
value2: currentTime - dataReceivedTime.current,
|
||||
key3: 'es_took',
|
||||
|
@ -268,13 +267,9 @@ 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);
|
||||
const timings = getSuccessfulRequestTimings(adapters);
|
||||
esTookTime.current = timings ? timings.esTookTotal : 0;
|
||||
}
|
||||
|
||||
if (requestWarnings.length) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import { css } from '@emotion/react';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { ENABLE_ESQL } from '@kbn/esql-utils';
|
||||
import { reportPerformanceMetricEvent } from '@kbn/ebt-tools';
|
||||
import {
|
||||
DataViewBase,
|
||||
EsQueryConfig,
|
||||
|
@ -86,6 +87,7 @@ import { DataViewSpec } from '@kbn/data-views-plugin/common';
|
|||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { useEuiFontSize, useEuiTheme, EuiEmptyPrompt } from '@elastic/eui';
|
||||
import { canTrackContentfulRender } from '@kbn/presentation-containers';
|
||||
import { getSuccessfulRequestTimings } from '../report_performance_metric_util';
|
||||
import { getExecutionContextEvents, trackUiCounterEvents } from '../lens_ui_telemetry';
|
||||
import { Document } from '../persistence';
|
||||
import { ExpressionWrapper, ExpressionWrapperProps } from './expression_wrapper';
|
||||
|
@ -1076,6 +1078,18 @@ export class Embeddable
|
|||
...this.getOutput(),
|
||||
rendered: true,
|
||||
});
|
||||
|
||||
const inspectorAdapters = this.getInspectorAdapters();
|
||||
const timings = getSuccessfulRequestTimings(inspectorAdapters);
|
||||
if (timings) {
|
||||
const esRequestMetrics = {
|
||||
eventName: 'lens_chart_es_request_totals',
|
||||
duration: timings.requestTimeTotal,
|
||||
key1: 'es_took_total',
|
||||
value1: timings.esTookTotal,
|
||||
};
|
||||
reportPerformanceMetricEvent(this.deps.coreStart.analytics, esRequestMetrics);
|
||||
}
|
||||
};
|
||||
|
||||
getExecutionContext() {
|
||||
|
|
36
x-pack/plugins/lens/public/report_performance_metric_util.ts
Normal file
36
x-pack/plugins/lens/public/report_performance_metric_util.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { RequestStatus } from '@kbn/inspector-plugin/common';
|
||||
import type { Adapters } from '@kbn/inspector-plugin/public';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
|
||||
export interface ILensRequestPerformance {
|
||||
requestTimeTotal: number;
|
||||
esTookTotal: number;
|
||||
}
|
||||
|
||||
export function getSuccessfulRequestTimings(
|
||||
inspectorAdapters: Adapters
|
||||
): ILensRequestPerformance | null {
|
||||
const requests = inspectorAdapters.requests?.getRequests() || [];
|
||||
|
||||
let esTookTotal = 0;
|
||||
let requestTimeTotal = 0;
|
||||
for (let i = 0; i < requests.length; i++) {
|
||||
const request = requests[i];
|
||||
if (request.status !== RequestStatus.OK) {
|
||||
return null;
|
||||
}
|
||||
esTookTotal +=
|
||||
(request.response?.json as { rawResponse: estypes.SearchResponse | undefined } | undefined)
|
||||
?.rawResponse?.took ?? 0;
|
||||
requestTimeTotal += request.time || 0;
|
||||
}
|
||||
|
||||
return { requestTimeTotal, esTookTotal };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue