Skip to content

Commit

Permalink
[Upgrade Assistant] Refactor telemetry (elastic#112177)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Sep 23, 2021
1 parent ca55b00 commit 991d24b
Show file tree
Hide file tree
Showing 32 changed files with 207 additions and 809 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
27 changes: 26 additions & 1 deletion x-pack/plugins/upgrade_assistant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,29 @@ This is a non-exhaustive list of different error scenarios in Upgrade Assistant.
- **Error updating deprecation logging status.** Mock a `404` status code to `PUT /api/upgrade_assistant/deprecation_logging`. Alternatively, edit [this line](https://github.com/elastic/kibana/blob/545c1420c285af8f5eee56f414bd6eca735aea11/x-pack/plugins/upgrade_assistant/public/application/lib/api.ts#L77) locally and replace `deprecation_logging` with `fake_deprecation_logging`.
- **Unauthorized error fetching ES deprecations.** Mock a `403` status code to `GET /api/upgrade_assistant/es_deprecations` with the response payload: `{ "statusCode": 403 }`
- **Partially upgraded error fetching ES deprecations.** Mock a `426` status code to `GET /api/upgrade_assistant/es_deprecations` with the response payload: `{ "statusCode": 426, "attributes": { "allNodesUpgraded": false } }`
- **Upgraded error fetching ES deprecations.** Mock a `426` status code to `GET /api/upgrade_assistant/es_deprecations` with the response payload: `{ "statusCode": 426, "attributes": { "allNodesUpgraded": true } }`
- **Upgraded error fetching ES deprecations.** Mock a `426` status code to `GET /api/upgrade_assistant/es_deprecations` with the response payload: `{ "statusCode": 426, "attributes": { "allNodesUpgraded": true } }`

### Telemetry

The Upgrade Assistant tracks several triggered events in the UI, using Kibana Usage Collection service's [UI counters](https://github.com/elastic/kibana/blob/master/src/plugins/usage_collection/README.mdx#ui-counters).

**Overview page**
- Component loaded
- Click event for "Create snapshot" button
- Click event for "View deprecation logs in Observability" link
- Click event for "Analyze logs in Discover" link
- Click event for "Reset counter" button

**ES deprecations page**
- Component loaded
- Click events for starting and stopping reindex tasks
- Click events for upgrading or deleting a Machine Learning snapshot
- Click event for deleting a deprecated index setting

**Kibana deprecations page**
- Component loaded
- Click event for "Quick resolve" button

In addition to UI counters, the Upgrade Assistant has a [custom usage collector](https://github.com/elastic/kibana/blob/master/src/plugins/usage_collection/README.mdx#custom-collector). It currently is only responsible for tracking whether the user has deprecation logging enabled or not.

For testing instructions, refer to the [Kibana Usage Collection service README](https://github.com/elastic/kibana/blob/master/src/plugins/usage_collection/README.mdx#testing).
29 changes: 0 additions & 29 deletions x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,14 @@ export interface UIReindex {
stop: boolean;
}

export interface UpgradeAssistantTelemetrySavedObject {
ui_open: {
overview: number;
elasticsearch: number;
kibana: number;
};
ui_reindex: {
close: number;
open: number;
start: number;
stop: number;
};
}

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;
};
};
}

export interface UpgradeAssistantTelemetrySavedObjectAttributes {
[key: string]: any;
}

export type MIGRATION_DEPRECATION_LEVEL = 'none' | 'info' | 'warning' | 'critical';
export interface DeprecationInfo {
level: MIGRATION_DEPRECATION_LEVEL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

import React from 'react';
import React, { useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';
import {
EuiButton,
EuiButtonEmpty,
Expand All @@ -25,6 +26,7 @@ import {
} from '@elastic/eui';
import { EnrichedDeprecationInfo, IndexSettingAction } from '../../../../../../common/types';
import type { ResponseError } from '../../../../lib/api';
import { uiMetricService, UIM_INDEX_SETTINGS_DELETE_CLICK } from '../../../../lib/ui_metric';
import type { Status } from '../../../types';
import { DeprecationBadge } from '../../../shared';

Expand Down Expand Up @@ -107,6 +109,11 @@ export const RemoveIndexSettingsFlyout = ({
// Flag used to hide certain parts of the UI if the deprecation has been resolved or is in progress
const isResolvable = ['idle', 'error'].includes(statusType);

const onRemoveSettings = useCallback(() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_INDEX_SETTINGS_DELETE_CLICK);
removeIndexSettings(index!, (correctiveAction as IndexSettingAction).deprecatedSettings);
}, [correctiveAction, index, removeIndexSettings]);

return (
<>
<EuiFlyoutHeader hasBorder>
Expand Down Expand Up @@ -190,12 +197,7 @@ export const RemoveIndexSettingsFlyout = ({
fill
data-test-subj="deleteSettingsButton"
color="danger"
onClick={() =>
removeIndexSettings(
index!,
(correctiveAction as IndexSettingAction).deprecatedSettings
)
}
onClick={onRemoveSettings}
>
{statusType === 'error'
? i18nTexts.retryRemoveButtonLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';

import {
EuiButton,
Expand All @@ -24,6 +25,11 @@ import {
} from '@elastic/eui';

import { EnrichedDeprecationInfo } from '../../../../../../common/types';
import {
uiMetricService,
UIM_ML_SNAPSHOT_UPGRADE_CLICK,
UIM_ML_SNAPSHOT_DELETE_CLICK,
} from '../../../../lib/ui_metric';
import { DeprecationBadge } from '../../../shared';
import { MlSnapshotContext } from './context';
import { SnapshotState } from './use_snapshot_state';
Expand Down Expand Up @@ -143,11 +149,13 @@ export const FixSnapshotsFlyout = ({
const isResolved = snapshotState.status === 'complete';

const onUpgradeSnapshot = () => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_ML_SNAPSHOT_UPGRADE_CLICK);
upgradeSnapshot();
closeFlyout();
};

const onDeleteSnapshot = () => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_ML_SNAPSHOT_DELETE_CLICK);
deleteSnapshot();
closeFlyout();
};
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 @@ -71,6 +77,16 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
const { loadingState, status, hasRequiredPrivileges } = reindexState;
const loading = loadingState === LoadingState.Loading || status === ReindexStatus.inProgress;

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

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

return (
<Fragment>
<EuiFlyoutBody>
Expand Down Expand Up @@ -124,7 +140,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
/>
</h3>
</EuiTitle>
<ReindexProgress reindexState={reindexState} cancelReindex={cancelReindex} />
<ReindexProgress reindexState={reindexState} cancelReindex={onStopReindex} />
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
Expand All @@ -142,7 +158,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
fill
color={status === ReindexStatus.paused ? 'warning' : 'primary'}
iconType={status === ReindexStatus.paused ? 'play' : undefined}
onClick={startReindex}
onClick={onStartReindex}
isLoading={loading}
disabled={loading || !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,18 +35,15 @@ const ReindexTableRowCells: React.FunctionComponent<TableRowProps> = ({
}) => {
const [showFlyout, setShowFlyout] = useState(false);
const reindexState = useReindexContext();
const {
services: { api },
} = useAppContext();

const { addContent: addContentToGlobalFlyout, removeContent: removeContentFromGlobalFlyout } =
useGlobalFlyout();

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 @@ -64,13 +67,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 { getEsDeprecationError } from '../../lib/get_es_deprecation_error';
import { DeprecationsPageLoadingError, NoDeprecationsPrompt, DeprecationCount } from '../shared';
import { EsDeprecationsTable } from './es_deprecations_table';
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 @@ -75,16 +71,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 (
Expand Down
Loading

0 comments on commit 991d24b

Please sign in to comment.