Skip to content

Commit

Permalink
add new ui counters to UA
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Sep 16, 2021
1 parent 67c11e1 commit f483ab7
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 16 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* 2.0.
*/

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

import {
EuiButtonEmpty,
Expand All @@ -24,6 +25,7 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { uiMetricService, UIM_KIBANA_QUICK_RESOLVE_CLICK } from '../../lib/ui_metric';
import type { DeprecationResolutionState, KibanaDeprecationDetails } from './kibana_deprecations';
import { DeprecationBadge } from '../shared';

Expand Down Expand Up @@ -134,6 +136,11 @@ export const DeprecationDetailsFlyout = ({
const isCurrent = deprecationResolutionState?.id === deprecation.id;
const isResolved = isCurrent && deprecationResolutionState?.resolveDeprecationStatus === 'ok';

const onResolveDeprecation = useCallback(() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_KIBANA_QUICK_RESOLVE_CLICK);
resolveDeprecation(deprecation);
}, [deprecation, resolveDeprecation]);

return (
<>
<EuiFlyoutHeader hasBorder>
Expand Down Expand Up @@ -225,7 +232,7 @@ export const DeprecationDetailsFlyout = ({
<EuiButton
fill
data-test-subj="resolveButton"
onClick={() => resolveDeprecation(deprecation)}
onClick={onResolveDeprecation}
isLoading={Boolean(
deprecationResolutionState?.resolveDeprecationStatus === 'in_progress'
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { useEffect } from 'react';
import moment from 'moment-timezone';
import { FormattedDate, FormattedTime, FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';
import {
EuiLoadingContent,
EuiFlexGroup,
Expand All @@ -21,6 +22,7 @@ import {
} from '@elastic/eui';

import { useAppContext } from '../../../app_context';
import { uiMetricService, UIM_BACKUP_DATA_CLOUD_CLICK } from '../../../lib/ui_metric';

interface Props {
cloudSnapshotsUrl: string;
Expand Down Expand Up @@ -133,11 +135,13 @@ export const CloudBackup: React.FunctionComponent<Props> = ({
return (
<>
{statusMessage}

<EuiSpacer size="s" />

{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButton
href={cloudSnapshotsUrl}
onClick={() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_BACKUP_DATA_CLOUD_CLICK);
}}
data-test-subj="cloudSnapshotsLink"
target="_blank"
iconType="popout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';
import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui';

import { useAppContext } from '../../../app_context';
import { uiMetricService, UIM_BACKUP_DATA_ON_PREM_CLICK } from '../../../lib/ui_metric';

const SnapshotRestoreAppLink: React.FunctionComponent = () => {
const {
Expand All @@ -22,7 +24,14 @@ const SnapshotRestoreAppLink: React.FunctionComponent = () => {
?.useUrl({ page: 'snapshots' });

return (
<EuiButton href={snapshotRestoreUrl} data-test-subj="snapshotRestoreLink">
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiButton
href={snapshotRestoreUrl}
onClick={() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_BACKUP_DATA_ON_PREM_CLICK);
}}
data-test-subj="snapshotRestoreLink"
>
<FormattedMessage
id="xpack.upgradeAssistant.overview.snapshotRestoreLink"
defaultMessage="Create snapshot"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import React, { FunctionComponent, useEffect } from 'react';
import moment from 'moment-timezone';
import { FormattedDate, FormattedTime, FormattedMessage } from '@kbn/i18n/react';

import { METRIC_TYPE } from '@kbn/analytics';
import { i18n } from '@kbn/i18n';
import { EuiCallOut, EuiButton, EuiLoadingContent } from '@elastic/eui';

import { useAppContext } from '../../../../app_context';
import { uiMetricService, UIM_RESET_LOGS_COUNTER_CLICK } from '../../../../lib/ui_metric';

const i18nTexts = {
calloutTitle: (warningsCount: number, previousCheck: string) => (
Expand Down Expand Up @@ -73,6 +75,7 @@ export const DeprecationsCountCheckpoint: FunctionComponent<Props> = ({

const onResetClick = () => {
const now = moment().toISOString();
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_RESET_LOGS_COUNTER_CLICK);
setCheckpoint(now);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ import { encode } from 'rison-node';
import React, { FunctionComponent, useState, useEffect } from 'react';

import { FormattedMessage } from '@kbn/i18n/react';
import { METRIC_TYPE } from '@kbn/analytics';
import { EuiLink, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiPanel, EuiText } from '@elastic/eui';

import { useAppContext } from '../../../app_context';
import { DataPublicPluginStart } from '../../../../shared_imports';
import { useAppContext } from '../../../app_context';
import {
uiMetricService,
UIM_OBSERVABILITY_CLICK,
UIM_DISCOVER_CLICK,
} from '../../../lib/ui_metric';

import {
DEPRECATION_LOGS_INDEX_PATTERN,
DEPRECATION_LOGS_SOURCE_ID,
Expand Down Expand Up @@ -73,7 +80,14 @@ const DiscoverAppLink: FunctionComponent<Props> = ({ checkpoint }) => {
}, [dataService, checkpoint, share.url.locators]);

return (
<EuiLink href={discoveryUrl} data-test-subj="viewDiscoverLogs">
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink
href={discoveryUrl}
onClick={() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_DISCOVER_CLICK);
}}
data-test-subj="viewDiscoverLogs"
>
<FormattedMessage
id="xpack.upgradeAssistant.overview.viewDiscoverResultsAction"
defaultMessage="Analyze logs in Discover"
Expand All @@ -95,7 +109,14 @@ const ObservabilityAppLink: FunctionComponent<Props> = ({ checkpoint }) => {
);

return (
<EuiLink href={logStreamUrl} data-test-subj="viewObserveLogs">
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink
href={logStreamUrl}
onClick={() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, UIM_OBSERVABILITY_CLICK);
}}
data-test-subj="viewObserveLogs"
>
<FormattedMessage
id="xpack.upgradeAssistant.overview.viewObservabilityResultsAction"
defaultMessage="View deprecation logs in Observability"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export const UIM_REINDEX_OPEN_FLYOUT_CLICK = 'reindex_open_flyout_click';
export const UIM_REINDEX_CLOSE_FLYOUT_CLICK = 'reindex_close_flyout_click';
export const UIM_REINDEX_START_CLICK = 'reindex_start_click';
export const UIM_REINDEX_STOP_CLICK = 'reindex_stop_click';
export const UIM_BACKUP_DATA_CLOUD_CLICK = 'backup_data_cloud_click';
export const UIM_BACKUP_DATA_ON_PREM_CLICK = 'backup_data_on_prem_click';
export const UIM_RESET_LOGS_COUNTER_CLICK = 'reset_logs_counter_click';
export const UIM_OBSERVABILITY_CLICK = 'observability_click';
export const UIM_DISCOVER_CLICK = 'discover_click';
export const UIM_ML_SNAPSHOT_UPGRADE_CLICK = 'ml_snapshot_upgrade_click';
export const UIM_ML_SNAPSHOT_DELETE_CLICK = 'ml_snapshot_delete_click';
export const UIM_INDEX_SETTINGS_DELETE_CLICK = 'index_settings_delete_click';
export const UIM_KIBANA_QUICK_RESOLVE_CLICK = 'kibana_quick_resolve_click';

export class UiMetricService {
private usageCollection: UsageCollectionSetup | undefined;
Expand Down

0 comments on commit f483ab7

Please sign in to comment.