Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Apr 11, 2020
1 parent 23c90b9 commit d2959c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/remote_clusters/public/application/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
import { Switch, Route, Redirect, withRouter } from 'react-router-dom';

import { CRUD_APP_BASE_PATH, UIM_APP_LOAD } from './constants';
import { registerRouter, setUserHasLeftApp, trackUiMetric } from './services';
import { registerRouter, setUserHasLeftApp, trackUiMetric, METRIC_TYPE } from './services';
import { RemoteClusterList, RemoteClusterAdd, RemoteClusterEdit } from './sections';

class AppComponent extends Component {
Expand All @@ -35,7 +35,7 @@ class AppComponent extends Component {
}

componentDidMount() {
trackUiMetric('LOADED', UIM_APP_LOAD);
trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD);
}

componentWillUnmount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {

import { CRUD_APP_BASE_PATH, UIM_SHOW_DETAILS_CLICK } from '../../../constants';
import { PROXY_MODE } from '../../../../../common/constants';
import { getRouterLinkProps, trackUiMetric } from '../../../services';
import { getRouterLinkProps, trackUiMetric, METRIC_TYPE } from '../../../services';
import { ConnectionStatus, RemoveClusterButtonProvider } from '../components';

export class RemoteClusterTable extends Component {
Expand Down Expand Up @@ -89,7 +89,7 @@ export class RemoteClusterTable extends Component {
<EuiLink
data-test-subj="remoteClustersTableListClusterLink"
onClick={() => {
trackUiMetric('CLICK', UIM_SHOW_DETAILS_CLICK);
trackUiMetric(METRIC_TYPE.CLICK, UIM_SHOW_DETAILS_CLICK);
openDetailPanel(name);
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export {
getRouterLinkProps,
} from './routing';

export { trackUiMetric } from './ui_metric';
export { trackUiMetric, METRIC_TYPE } from './ui_metric';
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { UiStatsMetricType, METRIC_TYPE } from '@kbn/analytics';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
import { UIM_APP_NAME } from '../constants';

export { METRIC_TYPE };

export let usageCollection: UsageCollectionSetup | undefined;

export function init(_usageCollection: UsageCollectionSetup): void {
usageCollection = _usageCollection;
}

export function trackUiMetric(type: 'COUNT' | 'CLICK' | 'LOADED', name: string) {
export function trackUiMetric(metricType: UiStatsMetricType, name: string) {
if (!usageCollection) {
return;
}
const { reportUiStats, METRIC_TYPE } = usageCollection;
reportUiStats(UIM_APP_NAME, METRIC_TYPE[type], name);
const { reportUiStats } = usageCollection;
reportUiStats(UIM_APP_NAME, metricType, name);
}

/**
Expand All @@ -28,7 +30,7 @@ export function trackUiMetric(type: 'COUNT' | 'CLICK' | 'LOADED', name: string)
export function trackUserRequest(request: Promise<any>, eventName: string) {
// Only track successful actions.
return request.then((response: any) => {
trackUiMetric('COUNT', eventName);
trackUiMetric(METRIC_TYPE.COUNT, eventName);
// We return the response immediately without waiting for the tracking request to resolve,
// to avoid adding additional latency.
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { i18n } from '@kbn/i18n';
import { toasts } from '../../services/notification';
import { UIM_CLUSTER_REMOVE, UIM_CLUSTER_REMOVE_MANY } from '../../constants';

import { removeClusterRequest as sendRemoveClusterRequest, trackUiMetric } from '../../services';
import {
removeClusterRequest as sendRemoveClusterRequest,
trackUiMetric,
METRIC_TYPE,
} from '../../services';

import { REMOVE_CLUSTERS_START, REMOVE_CLUSTERS_FINISH } from '../action_types';

Expand Down Expand Up @@ -72,7 +76,10 @@ export const removeClusters = names => async (dispatch, getState) => {

if (itemsDeleted.length > 0) {
// Only track successful requests.
trackUiMetric('COUNT', names.length > 1 ? UIM_CLUSTER_REMOVE_MANY : UIM_CLUSTER_REMOVE);
trackUiMetric(
METRIC_TYPE.COUNT,
names.length > 1 ? UIM_CLUSTER_REMOVE_MANY : UIM_CLUSTER_REMOVE
);

if (itemsDeleted.length === 1) {
toasts.addSuccess(
Expand Down

0 comments on commit d2959c2

Please sign in to comment.