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] Add ES-request time telemetry to Lens embeddable #192743

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -143,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<Document, 'savedObjectId' | 'type'>;

Expand Down Expand Up @@ -1076,6 +1078,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 !== RequestStatus.OK) {
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() {
Expand Down