Skip to content

Commit

Permalink
refactor existing UA telemetry in favor of UI counters
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Sep 16, 2021
1 parent 0e8cb0c commit 5ec2572
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 738 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6924,44 +6924,6 @@
}
}
}
},
"ui_open": {
"properties": {
"elasticsearch": {
"type": "long",
"_meta": {
"description": "Number of times a user viewed the list of Elasticsearch deprecations."
}
},
"overview": {
"type": "long",
"_meta": {
"description": "Number of times a user viewed the Overview page."
}
},
"kibana": {
"type": "long",
"_meta": {
"description": "Number of times a user viewed the list of Kibana deprecations"
}
}
}
},
"ui_reindex": {
"properties": {
"close": {
"type": "long"
},
"open": {
"type": "long"
},
"start": {
"type": "long"
},
"stop": {
"type": "long"
}
}
}
}
},
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ export interface UpgradeAssistantTelemetrySavedObject {
}

export interface UpgradeAssistantTelemetry {
ui_open: {
overview: number;
elasticsearch: number;
kibana: number;
};
ui_reindex: {
close: number;
open: number;
start: number;
stop: number;
};
features: {
deprecation_logging: {
enabled: boolean;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { Fragment } from 'react';
import React, { Fragment, useCallback } from 'react';

import {
EuiButton,
Expand All @@ -19,8 +19,14 @@ import {
EuiTitle,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { METRIC_TYPE } from '@kbn/analytics';

import { ReindexStatus } from '../../../../../../../common/types';
import {
uiMetricService,
UIM_REINDEX_START_CLICK,
UIM_REINDEX_STOP_CLICK,
} from '../../../../../lib/ui_metric';
import { LoadingState } from '../../../../types';
import type { ReindexState } from '../use_reindex_state';
import { ReindexProgress } from './progress';
Expand Down Expand Up @@ -78,6 +84,16 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
const { loadingState, status, hasRequiredPrivileges } = reindexState;
const loading = loadingState === LoadingState.Loading || status === ReindexStatus.inProgress;

const clickStartReindex = useCallback(() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_REINDEX_START_CLICK);
startReindex();
}, [startReindex]);

const clickStopReindex = useCallback(() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_REINDEX_STOP_CLICK);
cancelReindex();
}, [cancelReindex]);

return (
<Fragment>
<EuiFlyoutBody>
Expand Down Expand Up @@ -131,7 +147,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
/>
</h3>
</EuiTitle>
<ReindexProgress reindexState={reindexState} cancelReindex={cancelReindex} />
<ReindexProgress reindexState={reindexState} cancelReindex={clickStopReindex} />
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
Expand All @@ -148,7 +164,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
fill
color={status === ReindexStatus.paused ? 'warning' : 'primary'}
iconType={status === ReindexStatus.paused ? 'play' : undefined}
onClick={startReindex}
onClick={clickStartReindex}
isLoading={loading}
disabled={loading || status === ReindexStatus.completed || !hasRequiredPrivileges}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@

import React, { useState, useEffect, useCallback } from 'react';
import { EuiTableRowCell } from '@elastic/eui';
import { METRIC_TYPE } from '@kbn/analytics';
import { EnrichedDeprecationInfo } from '../../../../../../common/types';
import { GlobalFlyout } from '../../../../../shared_imports';
import { useAppContext } from '../../../../app_context';
import {
uiMetricService,
UIM_REINDEX_CLOSE_FLYOUT_CLICK,
UIM_REINDEX_OPEN_FLYOUT_CLICK,
} from '../../../../lib/ui_metric';
import { DeprecationTableColumns } from '../../../types';
import { EsDeprecationsTableCells } from '../../es_deprecations_table_cells';
import { ReindexResolutionCell } from './resolution_table_cell';
Expand All @@ -29,9 +35,6 @@ const ReindexTableRowCells: React.FunctionComponent<TableRowProps> = ({
}) => {
const [showFlyout, setShowFlyout] = useState(false);
const reindexState = useReindexContext();
const {
services: { api },
} = useAppContext();

const {
addContent: addContentToGlobalFlyout,
Expand All @@ -41,8 +44,8 @@ const ReindexTableRowCells: React.FunctionComponent<TableRowProps> = ({
const closeFlyout = useCallback(async () => {
removeContentFromGlobalFlyout('reindexFlyout');
setShowFlyout(false);
await api.sendReindexTelemetryData({ close: true });
}, [api, removeContentFromGlobalFlyout]);
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_REINDEX_CLOSE_FLYOUT_CLICK);
}, [removeContentFromGlobalFlyout]);

useEffect(() => {
if (showFlyout) {
Expand All @@ -65,13 +68,9 @@ const ReindexTableRowCells: React.FunctionComponent<TableRowProps> = ({

useEffect(() => {
if (showFlyout) {
async function sendTelemetry() {
await api.sendReindexTelemetryData({ open: true });
}

sendTelemetry();
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_REINDEX_OPEN_FLYOUT_CLICK);
}
}, [showFlyout, api]);
}, [showFlyout]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ export const useReindexStatus = ({ indexName, api }: { indexName: string; api: A
cancelLoadingState: undefined,
});

api.sendReindexTelemetryData({ start: true });

const { data, error } = await api.startReindexTask(indexName);

if (error) {
Expand All @@ -149,8 +147,6 @@ export const useReindexStatus = ({ indexName, api }: { indexName: string; api: A
}, [api, indexName, reindexState, updateStatus]);

const cancelReindex = useCallback(async () => {
api.sendReindexTelemetryData({ stop: true });

const { error } = await api.cancelReindexTask(indexName);

setReindexState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { withRouter, RouteComponentProps } from 'react-router-dom';

import { EuiPageHeader, EuiSpacer, EuiPageContent } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';

import { EnrichedDeprecationInfo } from '../../../../common/types';
import { SectionLoading } from '../../../shared_imports';
import { useAppContext } from '../../app_context';
import { uiMetricService, UIM_ES_DEPRECATIONS_PAGE_LOAD } from '../../lib/ui_metric';
import { EsDeprecationsTable } from './es_deprecations_table';
import { EsDeprecationErrors } from './es_deprecation_errors';
import { NoDeprecationsPrompt, DeprecationCount } from '../shared';
Expand Down Expand Up @@ -54,13 +56,7 @@ export const EsDeprecations = withRouter(({ history }: RouteComponentProps) => {
services: { api, breadcrumbs },
} = useAppContext();

const {
data: esDeprecations,
isLoading,
error,
resendRequest,
isInitialRequest,
} = api.useLoadEsDeprecations();
const { data: esDeprecations, isLoading, error, resendRequest } = api.useLoadEsDeprecations();

const deprecationsCountByLevel: {
warningDeprecations: number;
Expand All @@ -74,16 +70,8 @@ export const EsDeprecations = withRouter(({ history }: RouteComponentProps) => {
}, [breadcrumbs]);

useEffect(() => {
if (isLoading === false && isInitialRequest) {
async function sendTelemetryData() {
await api.sendPageTelemetryData({
elasticsearch: true,
});
}

sendTelemetryData();
}
}, [api, isLoading, isInitialRequest]);
uiMetricService.trackUiMetric(METRIC_TYPE.LOADED, UIM_ES_DEPRECATIONS_PAGE_LOAD);
}, []);

if (error) {
return <EsDeprecationErrors error={error} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import { withRouter, RouteComponentProps } from 'react-router-dom';
import { EuiPageContent, EuiPageHeader, EuiSpacer, EuiCallOut, EuiEmptyPrompt } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { METRIC_TYPE } from '@kbn/analytics';

import type { DomainDeprecationDetails } from 'kibana/public';
import { SectionLoading, GlobalFlyout } from '../../../shared_imports';
import { useAppContext } from '../../app_context';
import { uiMetricService, UIM_KIBANA_DEPRECATIONS_PAGE_LOAD } from '../../lib/ui_metric';
import { NoDeprecationsPrompt, DeprecationCount } from '../shared';
import { KibanaDeprecationsTable } from './kibana_deprecations_table';
import {
Expand Down Expand Up @@ -125,7 +127,6 @@ export const KibanaDeprecations = withRouter(({ history }: RouteComponentProps)
services: {
core: { deprecations },
breadcrumbs,
api,
},
} = useAppContext();

Expand Down Expand Up @@ -236,14 +237,8 @@ export const KibanaDeprecations = withRouter(({ history }: RouteComponentProps)
]);

useEffect(() => {
async function sendTelemetryData() {
await api.sendPageTelemetryData({
kibana: true,
});
}

sendTelemetryData();
}, [api]);
uiMetricService.trackUiMetric(METRIC_TYPE.LOADED, UIM_KIBANA_DEPRECATIONS_PAGE_LOAD);
}, []);

useEffect(() => {
breadcrumbs.setBreadcrumbs('kibanaDeprecations');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import {
EuiPageContent,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';
import { FormattedMessage } from '@kbn/i18n/react';

import { useAppContext } from '../../app_context';
import { uiMetricService, UIM_OVERVIEW_PAGE_LOAD } from '../../lib/ui_metric';
import { getBackupStep } from './backup_step';
import { getFixIssuesStep } from './fix_issues_step';
import { getFixLogsStep } from './fix_logs_step';
Expand All @@ -33,21 +35,14 @@ export const Overview: FunctionComponent = () => {
kibanaVersionInfo: { nextMajor },
services: {
breadcrumbs,
api,
core: { docLinks },
},
plugins: { cloud },
} = useAppContext();

useEffect(() => {
async function sendTelemetryData() {
await api.sendPageTelemetryData({
overview: true,
});
}

sendTelemetryData();
}, [api]);
uiMetricService.trackUiMetric(METRIC_TYPE.LOADED, UIM_OVERVIEW_PAGE_LOAD);
}, []);

useEffect(() => {
breadcrumbs.setBreadcrumbs('overview');
Expand Down
20 changes: 0 additions & 20 deletions x-pack/plugins/upgrade_assistant/public/application/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ export class ApiService {
});
}

public async sendPageTelemetryData(telemetryData: { [tabName: string]: boolean }) {
const result = await this.sendRequest({
path: `${API_BASE_PATH}/stats/ui_open`,
method: 'put',
body: JSON.stringify(telemetryData),
});

return result;
}

public useLoadDeprecationLogging() {
return this.useRequest<{
isDeprecationLogIndexingEnabled: boolean;
Expand Down Expand Up @@ -150,16 +140,6 @@ export class ApiService {
});
}

public async sendReindexTelemetryData(telemetryData: { [key: string]: boolean }) {
const result = await this.sendRequest({
path: `${API_BASE_PATH}/stats/ui_reindex`,
method: 'put',
body: JSON.stringify(telemetryData),
});

return result;
}

public async getReindexStatus(indexName: string) {
return await this.sendRequest({
path: `${API_BASE_PATH}/reindex/${indexName}`,
Expand Down
Loading

0 comments on commit 5ec2572

Please sign in to comment.