From 434181566c329eb8f5e3f068db96eb194d2c240e Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 12 Sep 2024 12:38:14 -0400 Subject: [PATCH 01/11] Add telemetry to Lens embeddable --- .../lens/public/embeddable/embeddable.tsx | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 6c758abb81cff..16694f557d619 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -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, @@ -1076,6 +1077,32 @@ export class Embeddable ...this.getOutput(), rendered: true, }); + + const inspectorAdapters = this.getInspectorAdapters(); + const requests = inspectorAdapters.requests?.getRequests() || []; + + let totalTookTime = 0; + let allValid = true; + let totalTime = 0; + for (let i = 0; i < requests.length; i++) { + const request = requests[i]; + if (request.status !== 1) { + allValid = false; + break; + } + totalTookTime += request.response?.json?.rawResponse?.took ?? 0; + totalTime += request.time || 0; + } + + if (allValid) { + const esRequestMetrics = { + eventName: 'lens_chart_es_request_totals', + duration: totalTime, + key1: 'es_took_total', + value1: totalTookTime, + }; + reportPerformanceMetricEvent(this.deps.coreStart.analytics, esRequestMetrics); + } }; getExecutionContext() { From 823d4d7fd3704f561ebe87bbbfccb9c7dfb283de Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 12 Sep 2024 13:09:08 -0400 Subject: [PATCH 02/11] use enum --- x-pack/plugins/lens/public/embeddable/embeddable.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 16694f557d619..41238e9b1ea37 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -144,6 +144,7 @@ import { EmbeddableFeatureBadge } from './embeddable_info_badges'; import { getDatasourceLayers } from '../state_management/utils'; import type { EditLensConfigurationProps } from '../app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration'; import { TextBasedPersistedState } from '../datasources/text_based/types'; +import { RequestStatus } from '@kbn/inspector-plugin/public'; export type LensSavedObjectAttributes = Omit; @@ -1086,7 +1087,7 @@ export class Embeddable let totalTime = 0; for (let i = 0; i < requests.length; i++) { const request = requests[i]; - if (request.status !== 1) { + if (request.status !== RequestStatus.OK) { allValid = false; break; } From d8ccaddef61d3ad38638d1ee62b6b4f0a9be6896 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 12 Sep 2024 16:46:32 -0400 Subject: [PATCH 03/11] fix import order --- x-pack/plugins/lens/public/embeddable/embeddable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 41238e9b1ea37..cd1ff7bc0f67e 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -87,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 { RequestStatus } from '@kbn/inspector-plugin/public'; import { getExecutionContextEvents, trackUiCounterEvents } from '../lens_ui_telemetry'; import { Document } from '../persistence'; import { ExpressionWrapper, ExpressionWrapperProps } from './expression_wrapper'; @@ -144,7 +145,6 @@ import { EmbeddableFeatureBadge } from './embeddable_info_badges'; import { getDatasourceLayers } from '../state_management/utils'; import type { EditLensConfigurationProps } from '../app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration'; import { TextBasedPersistedState } from '../datasources/text_based/types'; -import { RequestStatus } from '@kbn/inspector-plugin/public'; export type LensSavedObjectAttributes = Omit; From 8f773395f032bd9c1033b9fcdf2f98bda7d1ad80 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 13 Sep 2024 09:05:09 -0400 Subject: [PATCH 04/11] fix type check --- x-pack/plugins/lens/public/embeddable/embeddable.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index cd1ff7bc0f67e..9746ae3f41f74 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -1091,7 +1091,9 @@ export class Embeddable allValid = false; break; } - totalTookTime += request.response?.json?.rawResponse?.took ?? 0; + totalTookTime += + (request.response?.json as { rawResponse: estypes.SearchResponse | undefined } | undefined) + ?.rawResponse?.took ?? 0; totalTime += request.time || 0; } From 5291df0f4f3f0faaedef0389210f3d83575ba36b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 13 Sep 2024 10:36:42 -0400 Subject: [PATCH 05/11] fix import --- x-pack/plugins/lens/public/embeddable/embeddable.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 9746ae3f41f74..34d757ca71efd 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -9,6 +9,7 @@ import { partition, uniqBy } from 'lodash'; import React from 'react'; import type { Observable } from 'rxjs'; import { css } from '@emotion/react'; +import type { estypes } from '@elastic/elasticsearch'; import { i18n } from '@kbn/i18n'; import { render, unmountComponentAtNode } from 'react-dom'; import { ENABLE_ESQL } from '@kbn/esql-utils'; From 0138c757517cd7c49a97b660f4009ad4d27054c3 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 17 Sep 2024 16:51:58 -0400 Subject: [PATCH 06/11] remove duplication --- .../workspace_panel/workspace_panel.tsx | 13 +++--- .../lens/public/embeddable/embeddable.tsx | 26 +++--------- .../public/report_performance_metric_util.ts | 40 +++++++++++++++++++ 3 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 x-pack/plugins/lens/public/report_performance_metric_util.ts 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 c38bfb2cc86f0..e5c8ed612e7f1 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,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 { @@ -201,6 +201,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ initialVisualizationRenderComplete.current = true; // NOTE: this metric is only reported for an initial editor load of a pre-existing visualization const currentTime = performance.now(); + reportPerformanceMetricEvent(core.analytics, { eventName: 'lensVisualizationRenderTime', duration: currentTime - visualizationRenderStartTime.current, @@ -268,13 +269,11 @@ 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); + if (timings) { + esTookTime.current = timings ? timings.esTookTotal : 0; + } } if (requestWarnings.length) { diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 34d757ca71efd..7e521f6a9b0c4 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -88,7 +88,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 { RequestStatus } from '@kbn/inspector-plugin/public'; +import { getSuccessfulRequestTimings } from '../report_performance_metric_util'; import { getExecutionContextEvents, trackUiCounterEvents } from '../lens_ui_telemetry'; import { Document } from '../persistence'; import { ExpressionWrapper, ExpressionWrapperProps } from './expression_wrapper'; @@ -1081,29 +1081,13 @@ export class Embeddable }); const inspectorAdapters = this.getInspectorAdapters(); - const requests = inspectorAdapters.requests?.getRequests() || []; - - let totalTookTime = 0; - let allValid = true; - let totalTime = 0; - for (let i = 0; i < requests.length; i++) { - const request = requests[i]; - if (request.status !== RequestStatus.OK) { - allValid = false; - break; - } - totalTookTime += - (request.response?.json as { rawResponse: estypes.SearchResponse | undefined } | undefined) - ?.rawResponse?.took ?? 0; - totalTime += request.time || 0; - } - - if (allValid) { + const timings = getSuccessfulRequestTimings(inspectorAdapters); + if (timings) { const esRequestMetrics = { eventName: 'lens_chart_es_request_totals', - duration: totalTime, + duration: timings.requestTimeTotal, key1: 'es_took_total', - value1: totalTookTime, + value1: timings.esTookTotal, }; reportPerformanceMetricEvent(this.deps.coreStart.analytics, esRequestMetrics); } diff --git a/x-pack/plugins/lens/public/report_performance_metric_util.ts b/x-pack/plugins/lens/public/report_performance_metric_util.ts new file mode 100644 index 0000000000000..1ff3e0033f4f3 --- /dev/null +++ b/x-pack/plugins/lens/public/report_performance_metric_util.ts @@ -0,0 +1,40 @@ +/* + * 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'; + +export interface ILensRequestPerformance { + requestTimeTotal: number; + esTookTotal: number; +} + +export function getSuccessfulRequestTimings( + inspectorAdapters: Adapters +): ILensRequestPerformance | null { + const requests = inspectorAdapters.requests?.getRequests() || []; + + let totalTookTime = 0; + let allValid = true; + let totalTime = 0; + for (let i = 0; i < requests.length; i++) { + const request = requests[i]; + if (request.status !== RequestStatus.OK) { + allValid = false; + return null; + } + totalTookTime += + (request.response?.json as { rawResponse: estypes.SearchResponse | undefined } | undefined) + ?.rawResponse?.took ?? 0; + totalTime += request.time || 0; + } + + return { + requestTimeTotal: totalTime, + esTookTotal: totalTookTime, + }; +} From ca8d25bbb6d6a3156e2c9ce25a01ef9135c34404 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 17 Sep 2024 16:52:45 -0400 Subject: [PATCH 07/11] do not change meaning of existing time_to_data metric --- .../editor_frame/workspace_panel/workspace_panel.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 e5c8ed612e7f1..f68612d70748b 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 @@ -206,8 +206,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', From b2ab31eb90a13e5bd63ef21392ab3d411007e7b0 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 17 Sep 2024 16:56:48 -0400 Subject: [PATCH 08/11] fix bug --- .../editor_frame/workspace_panel/workspace_panel.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 f68612d70748b..68c63f1da52dd 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 @@ -201,7 +201,6 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ initialVisualizationRenderComplete.current = true; // NOTE: this metric is only reported for an initial editor load of a pre-existing visualization const currentTime = performance.now(); - reportPerformanceMetricEvent(core.analytics, { eventName: 'lensVisualizationRenderTime', duration: currentTime - visualizationRenderStartTime.current, @@ -270,9 +269,7 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ ); const timings = getSuccessfulRequestTimings(adapters); - if (timings) { - esTookTime.current = timings ? timings.esTookTotal : 0; - } + esTookTime.current = timings ? timings.esTookTotal : 0; } if (requestWarnings.length) { From 6e9d638bc8e37655e81e2e6de8f1ba5a4ad9ebbf Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 17 Sep 2024 21:46:32 +0000 Subject: [PATCH 09/11] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- x-pack/plugins/lens/public/embeddable/embeddable.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 7e521f6a9b0c4..51bcbb4fed635 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -9,7 +9,6 @@ import { partition, uniqBy } from 'lodash'; import React from 'react'; import type { Observable } from 'rxjs'; import { css } from '@emotion/react'; -import type { estypes } from '@elastic/elasticsearch'; import { i18n } from '@kbn/i18n'; import { render, unmountComponentAtNode } from 'react-dom'; import { ENABLE_ESQL } from '@kbn/esql-utils'; From c9da1cdad1d8fa795131096b685467c559e8f7bf Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 18 Sep 2024 14:24:03 -0400 Subject: [PATCH 10/11] linting issues --- x-pack/plugins/lens/public/report_performance_metric_util.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/lens/public/report_performance_metric_util.ts b/x-pack/plugins/lens/public/report_performance_metric_util.ts index 1ff3e0033f4f3..257adbf5364e4 100644 --- a/x-pack/plugins/lens/public/report_performance_metric_util.ts +++ b/x-pack/plugins/lens/public/report_performance_metric_util.ts @@ -7,6 +7,7 @@ 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; @@ -19,12 +20,10 @@ export function getSuccessfulRequestTimings( const requests = inspectorAdapters.requests?.getRequests() || []; let totalTookTime = 0; - let allValid = true; let totalTime = 0; for (let i = 0; i < requests.length; i++) { const request = requests[i]; if (request.status !== RequestStatus.OK) { - allValid = false; return null; } totalTookTime += From c89058aa87aba65bee116142df75c7bc644ad0db Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 19 Sep 2024 12:35:51 -0400 Subject: [PATCH 11/11] Update x-pack/plugins/lens/public/report_performance_metric_util.ts improve naming Co-authored-by: Marco Vettorello --- .../lens/public/report_performance_metric_util.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/lens/public/report_performance_metric_util.ts b/x-pack/plugins/lens/public/report_performance_metric_util.ts index 257adbf5364e4..64465e8d20a18 100644 --- a/x-pack/plugins/lens/public/report_performance_metric_util.ts +++ b/x-pack/plugins/lens/public/report_performance_metric_util.ts @@ -19,21 +19,18 @@ export function getSuccessfulRequestTimings( ): ILensRequestPerformance | null { const requests = inspectorAdapters.requests?.getRequests() || []; - let totalTookTime = 0; - let totalTime = 0; + 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; } - totalTookTime += + esTookTotal += (request.response?.json as { rawResponse: estypes.SearchResponse | undefined } | undefined) ?.rawResponse?.took ?? 0; - totalTime += request.time || 0; + requestTimeTotal += request.time || 0; } - return { - requestTimeTotal: totalTime, - esTookTotal: totalTookTime, - }; + return { requestTimeTotal, esTookTotal }; }