From 23e924b8da23a69adaf0c09ba61257b93a499315 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 6 Mar 2019 11:06:04 -0800 Subject: [PATCH 1/6] Fix API endpoint typo indices/clear_caches -> indices/clear_cache. --- .../server/routes/api/indices/register_clear_cache_route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.js b/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.js index 95afc6c1c5382..5c003ebe5bb64 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.js +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.js @@ -17,5 +17,5 @@ const handler = async (request, callWithRequest, h) => { return h.response(); }; export function registerClearCacheRoute(router) { - router.post('indices/clear_caches', handler); + router.post('indices/clear_cache', handler); } From 5203fe29280872f3641d01d307c600334e6a95b7 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 6 Mar 2019 13:35:35 -0800 Subject: [PATCH 2/6] Track Index Management index actions. --- .../common/constants/index.js | 28 +++++++++ .../common/constants/user_action.js | 57 +++++++++++++++++++ x-pack/plugins/index_management/index.js | 4 +- .../index_management/public/services/api.js | 47 ++++++++++++--- .../public/services/track_user_action.js | 28 +++++++++ .../server/usage/collector.js | 25 ++++++++ .../index_management/server/usage/index.js | 7 +++ 7 files changed, 187 insertions(+), 9 deletions(-) create mode 100644 x-pack/plugins/index_management/common/constants/user_action.js create mode 100644 x-pack/plugins/index_management/public/services/track_user_action.js create mode 100644 x-pack/plugins/index_management/server/usage/collector.js create mode 100644 x-pack/plugins/index_management/server/usage/index.js diff --git a/x-pack/plugins/index_management/common/constants/index.js b/x-pack/plugins/index_management/common/constants/index.js index f22974ffd3c5a..e6ae2d098bb5c 100644 --- a/x-pack/plugins/index_management/common/constants/index.js +++ b/x-pack/plugins/index_management/common/constants/index.js @@ -7,3 +7,31 @@ export { PLUGIN } from './plugin'; export { BASE_PATH } from './base_path'; export * from './index_statuses'; + +export { + UA_APP_NAME, + USER_ACTIONS, + UA_INDEX_CLEAR_CACHE, + UA_INDEX_CLEAR_CACHE_BULK, + UA_INDEX_DELETE, + UA_INDEX_DELETE_BULK, + UA_INDEX_FLUSH, + UA_INDEX_FLUSH_BULK, + UA_INDEX_FORCE_MERGE, + UA_INDEX_FORCE_MERGE_BULK, + UA_INDEX_CLOSE, + UA_INDEX_CLOSE_BULK, + UA_INDEX_OPEN, + UA_INDEX_OPEN_BULK, + UA_INDEX_FREEZE, + UA_INDEX_FREEZE_BULK, + UA_INDEX_UNFREEZE, + UA_INDEX_UNFREEZE_BULK, + UA_INDEX_SETTINGS_EDIT, + UA_SHOW_DETAILS_CLICK, + UA_DETAIL_PANEL_SUMMARY_TAB_CLICK, + UA_DETAIL_PANEL_SETTINGS_TAB_CLICK, + UA_DETAIL_PANEL_MAPPING_TAB_CLICK, + UA_DETAIL_PANEL_STATS_TAB_CLICK, + UA_DETAIL_PANEL_EDIT_SETTINGS_TAB_CLICK, +} from './user_action'; diff --git a/x-pack/plugins/index_management/common/constants/user_action.js b/x-pack/plugins/index_management/common/constants/user_action.js new file mode 100644 index 0000000000000..f8217ec2005a6 --- /dev/null +++ b/x-pack/plugins/index_management/common/constants/user_action.js @@ -0,0 +1,57 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const UA_APP_NAME = 'index-management'; + +export const UA_INDEX_CLEAR_CACHE = 'index_clear_cache'; +export const UA_INDEX_CLEAR_CACHE_BULK = 'index_clear_cache_bulk'; +export const UA_INDEX_DELETE = 'index_delete'; +export const UA_INDEX_DELETE_BULK = 'index_delete_bulk'; +export const UA_INDEX_FLUSH = 'index_flush'; +export const UA_INDEX_FLUSH_BULK = 'index_flush_bulk'; +export const UA_INDEX_FORCE_MERGE = 'index_force_merge'; +export const UA_INDEX_FORCE_MERGE_BULK = 'index_force_merge_bulk'; +export const UA_INDEX_CLOSE = 'index_close'; +export const UA_INDEX_CLOSE_BULK = 'index_close_bulk'; +export const UA_INDEX_OPEN = 'index_open'; +export const UA_INDEX_OPEN_BULK = 'index_open_bulk'; +export const UA_INDEX_FREEZE = 'index_freeze'; +export const UA_INDEX_FREEZE_BULK = 'index_freeze_bulk'; +export const UA_INDEX_UNFREEZE = 'index_unfreeze'; +export const UA_INDEX_UNFREEZE_BULK = 'index_unfreeze_bulk'; +export const UA_INDEX_SETTINGS_EDIT = 'index_settings_edit'; +export const UA_SHOW_DETAILS_CLICK = 'show_details_click'; +export const UA_DETAIL_PANEL_SUMMARY_TAB_CLICK = 'detail_panel_summary_tab_click'; +export const UA_DETAIL_PANEL_SETTINGS_TAB_CLICK = 'detail_panel_settings_tab_click'; +export const UA_DETAIL_PANEL_MAPPING_TAB_CLICK = 'detail_panel_mapping_tab_click'; +export const UA_DETAIL_PANEL_STATS_TAB_CLICK = 'detail_panel_stats_tab_click'; +export const UA_DETAIL_PANEL_EDIT_SETTINGS_TAB_CLICK = 'detail_panel_edit_settings_tab_click'; + +export const USER_ACTIONS = [ + UA_INDEX_CLEAR_CACHE, + UA_INDEX_CLEAR_CACHE_BULK, + UA_INDEX_DELETE, + UA_INDEX_DELETE_BULK, + UA_INDEX_FLUSH, + UA_INDEX_FLUSH_BULK, + UA_INDEX_FORCE_MERGE, + UA_INDEX_FORCE_MERGE_BULK, + UA_INDEX_CLOSE, + UA_INDEX_CLOSE_BULK, + UA_INDEX_OPEN, + UA_INDEX_OPEN_BULK, + UA_INDEX_FREEZE, + UA_INDEX_FREEZE_BULK, + UA_INDEX_UNFREEZE, + UA_INDEX_UNFREEZE_BULK, + UA_INDEX_SETTINGS_EDIT, + UA_SHOW_DETAILS_CLICK, + UA_DETAIL_PANEL_SUMMARY_TAB_CLICK, + UA_DETAIL_PANEL_SETTINGS_TAB_CLICK, + UA_DETAIL_PANEL_MAPPING_TAB_CLICK, + UA_DETAIL_PANEL_STATS_TAB_CLICK, + UA_DETAIL_PANEL_EDIT_SETTINGS_TAB_CLICK, +]; diff --git a/x-pack/plugins/index_management/index.js b/x-pack/plugins/index_management/index.js index d0910ec9ce703..4b69590ccc46d 100644 --- a/x-pack/plugins/index_management/index.js +++ b/x-pack/plugins/index_management/index.js @@ -5,6 +5,7 @@ */ import { resolve } from 'path'; +import { createRouter } from '../../server/lib/create_router'; import { registerIndicesRoutes } from './server/routes/api/indices'; import { registerMappingRoute } from './server/routes/api/mapping'; import { registerSettingsRoutes } from './server/routes/api/settings'; @@ -12,7 +13,7 @@ import { registerStatsRoute } from './server/routes/api/stats'; import { registerLicenseChecker } from '../../server/lib/register_license_checker'; import { PLUGIN } from './common/constants'; import { addIndexManagementDataEnricher } from './index_management_data'; -import { createRouter } from '../../server/lib/create_router'; +import { registerIndexManagementUsageCollector } from './server/usage'; export function indexManagement(kibana) { return new kibana.Plugin({ @@ -34,6 +35,7 @@ export function indexManagement(kibana) { registerSettingsRoutes(router); registerStatsRoute(router); registerMappingRoute(router); + registerIndexManagementUsageCollector(server); } }); } diff --git a/x-pack/plugins/index_management/public/services/api.js b/x-pack/plugins/index_management/public/services/api.js index c8d77f140db61..594e416c768df 100644 --- a/x-pack/plugins/index_management/public/services/api.js +++ b/x-pack/plugins/index_management/public/services/api.js @@ -5,13 +5,36 @@ */ import chrome from 'ui/chrome'; +import { + UA_INDEX_CLEAR_CACHE, + UA_INDEX_CLEAR_CACHE_BULK, + UA_INDEX_DELETE, + UA_INDEX_DELETE_BULK, + UA_INDEX_FLUSH, + UA_INDEX_FLUSH_BULK, + UA_INDEX_FORCE_MERGE, + UA_INDEX_FORCE_MERGE_BULK, + UA_INDEX_CLOSE, + UA_INDEX_CLOSE_BULK, + UA_INDEX_OPEN, + UA_INDEX_OPEN_BULK, + UA_INDEX_FREEZE, + UA_INDEX_FREEZE_BULK, + UA_INDEX_UNFREEZE, + UA_INDEX_UNFREEZE_BULK, +} from '../../common/constants'; +import { trackUserRequestBulk } from './track_user_action'; + let httpClient; + export const setHttpClient = (client) => { httpClient = client; }; + export const getHttpClient = () => { return httpClient; }; + const apiPrefix = chrome.addBasePath('/api/index_management'); export async function loadIndices() { @@ -31,7 +54,8 @@ export async function closeIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/close`, body); + const request = httpClient.post(`${apiPrefix}/indices/close`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_CLOSE, UA_INDEX_CLOSE_BULK); return response.data; } @@ -39,7 +63,8 @@ export async function deleteIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/delete`, body); + const request = httpClient.post(`${apiPrefix}/indices/delete`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_DELETE, UA_INDEX_DELETE_BULK); return response.data; } @@ -47,7 +72,8 @@ export async function openIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/open`, body); + const request = httpClient.post(`${apiPrefix}/indices/open`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_OPEN, UA_INDEX_OPEN_BULK); return response.data; } @@ -63,7 +89,8 @@ export async function flushIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/flush`, body); + const request = httpClient.post(`${apiPrefix}/indices/flush`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_FLUSH, UA_INDEX_FLUSH_BULK); return response.data; } @@ -72,7 +99,8 @@ export async function forcemergeIndices(indices, maxNumSegments) { indices, maxNumSegments }; - const response = await httpClient.post(`${apiPrefix}/indices/forcemerge`, body); + const request = httpClient.post(`${apiPrefix}/indices/forcemerge`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_FORCE_MERGE, UA_INDEX_FORCE_MERGE_BULK); return response.data; } @@ -80,21 +108,24 @@ export async function clearCacheIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/clear_cache`, body); + const request = httpClient.post(`${apiPrefix}/indices/clear_cache`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_CLEAR_CACHE, UA_INDEX_CLEAR_CACHE_BULK); return response.data; } export async function freezeIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/freeze`, body); + const request = httpClient.post(`${apiPrefix}/indices/freeze`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_FREEZE, UA_INDEX_FREEZE_BULK); return response.data; } export async function unfreezeIndices(indices) { const body = { indices }; - const response = await httpClient.post(`${apiPrefix}/indices/unfreeze`, body); + const request = httpClient.post(`${apiPrefix}/indices/unfreeze`, body); + const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_UNFREEZE, UA_INDEX_UNFREEZE_BULK); return response.data; } diff --git a/x-pack/plugins/index_management/public/services/track_user_action.js b/x-pack/plugins/index_management/public/services/track_user_action.js new file mode 100644 index 0000000000000..7ddb3b9cb5e78 --- /dev/null +++ b/x-pack/plugins/index_management/public/services/track_user_action.js @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { createUserActionUri } from '../../../../common/user_action'; +import { UA_APP_NAME } from '../../common/constants'; +import { getHttpClient } from './api'; + +export function trackUserAction(actionType) { + const userActionUri = createUserActionUri(UA_APP_NAME, actionType); + getHttpClient().post(userActionUri); +} + +export function trackUserRequest(request, actionType) { + // Only track successful actions. + request.then(() => trackUserAction(actionType)); + return request; +} + +export function trackUserRequestBulk(request, itemCount, actionTypeSingle, actionTypeBulk) { + if (itemCount > 1) { + return trackUserRequest(request, actionTypeBulk); + } + + return trackUserRequest(request, actionTypeSingle); +} diff --git a/x-pack/plugins/index_management/server/usage/collector.js b/x-pack/plugins/index_management/server/usage/collector.js new file mode 100644 index 0000000000000..59fc6b3ac050d --- /dev/null +++ b/x-pack/plugins/index_management/server/usage/collector.js @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { fetchUserActions } from '../../../../server/lib/user_action'; +import { UA_APP_NAME, USER_ACTIONS } from '../../common/constants'; + +const INDEX_MANAGEMENT_USAGE_TYPE = 'index_management'; + +export function registerIndexManagementUsageCollector(server) { + const collector = server.usage.collectorSet.makeUsageCollector({ + type: INDEX_MANAGEMENT_USAGE_TYPE, + fetch: async () => { + const userActions = await fetchUserActions(server, UA_APP_NAME, USER_ACTIONS); + + return { + user_actions: userActions, + }; + }, + }); + + server.usage.collectorSet.register(collector); +} diff --git a/x-pack/plugins/index_management/server/usage/index.js b/x-pack/plugins/index_management/server/usage/index.js new file mode 100644 index 0000000000000..a5d92612287c1 --- /dev/null +++ b/x-pack/plugins/index_management/server/usage/index.js @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { registerIndexManagementUsageCollector } from './collector'; From 8b0d1f0ed20be13da63adc23aebca07bff477750 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 6 Mar 2019 14:04:03 -0800 Subject: [PATCH 3/6] Track user actions for opening detail tab and viewing various tabs. - Use constants instead of hard-coded strings to identify tabs. - Internationalize tab labels. --- .../common/constants/index.js | 10 +-- .../common/constants/user_action.js | 20 ++--- .../public/constants/detail_panel_tabs.js | 11 +++ .../public/constants/index.js | 8 ++ .../components/detail_panel/detail_panel.js | 75 +++++++++++++++---- .../edit_settings_json/edit_settings_json.js | 3 +- .../index_actions_context_menu.container.js | 14 +++- .../components/index_table/index_table.js | 10 ++- .../index_management/public/services/api.js | 13 +++- .../index_management/public/services/index.js | 1 + .../public/store/reducers/detail_panel.js | 30 +++++++- 11 files changed, 151 insertions(+), 44 deletions(-) create mode 100644 x-pack/plugins/index_management/public/constants/detail_panel_tabs.js diff --git a/x-pack/plugins/index_management/common/constants/index.js b/x-pack/plugins/index_management/common/constants/index.js index e6ae2d098bb5c..fab5002fd6fe1 100644 --- a/x-pack/plugins/index_management/common/constants/index.js +++ b/x-pack/plugins/index_management/common/constants/index.js @@ -29,9 +29,9 @@ export { UA_INDEX_UNFREEZE_BULK, UA_INDEX_SETTINGS_EDIT, UA_SHOW_DETAILS_CLICK, - UA_DETAIL_PANEL_SUMMARY_TAB_CLICK, - UA_DETAIL_PANEL_SETTINGS_TAB_CLICK, - UA_DETAIL_PANEL_MAPPING_TAB_CLICK, - UA_DETAIL_PANEL_STATS_TAB_CLICK, - UA_DETAIL_PANEL_EDIT_SETTINGS_TAB_CLICK, + UA_DETAIL_PANEL_SUMMARY_TAB, + UA_DETAIL_PANEL_SETTINGS_TAB, + UA_DETAIL_PANEL_MAPPING_TAB, + UA_DETAIL_PANEL_STATS_TAB, + UA_DETAIL_PANEL_EDIT_SETTINGS_TAB, } from './user_action'; diff --git a/x-pack/plugins/index_management/common/constants/user_action.js b/x-pack/plugins/index_management/common/constants/user_action.js index f8217ec2005a6..e64c21ebd8a1c 100644 --- a/x-pack/plugins/index_management/common/constants/user_action.js +++ b/x-pack/plugins/index_management/common/constants/user_action.js @@ -24,11 +24,11 @@ export const UA_INDEX_UNFREEZE = 'index_unfreeze'; export const UA_INDEX_UNFREEZE_BULK = 'index_unfreeze_bulk'; export const UA_INDEX_SETTINGS_EDIT = 'index_settings_edit'; export const UA_SHOW_DETAILS_CLICK = 'show_details_click'; -export const UA_DETAIL_PANEL_SUMMARY_TAB_CLICK = 'detail_panel_summary_tab_click'; -export const UA_DETAIL_PANEL_SETTINGS_TAB_CLICK = 'detail_panel_settings_tab_click'; -export const UA_DETAIL_PANEL_MAPPING_TAB_CLICK = 'detail_panel_mapping_tab_click'; -export const UA_DETAIL_PANEL_STATS_TAB_CLICK = 'detail_panel_stats_tab_click'; -export const UA_DETAIL_PANEL_EDIT_SETTINGS_TAB_CLICK = 'detail_panel_edit_settings_tab_click'; +export const UA_DETAIL_PANEL_SUMMARY_TAB = 'detail_panel_summary_tab'; +export const UA_DETAIL_PANEL_SETTINGS_TAB = 'detail_panel_settings_tab'; +export const UA_DETAIL_PANEL_MAPPING_TAB = 'detail_panel_mapping_tab'; +export const UA_DETAIL_PANEL_STATS_TAB = 'detail_panel_stats_tab'; +export const UA_DETAIL_PANEL_EDIT_SETTINGS_TAB = 'detail_panel_edit_settings_tab'; export const USER_ACTIONS = [ UA_INDEX_CLEAR_CACHE, @@ -49,9 +49,9 @@ export const USER_ACTIONS = [ UA_INDEX_UNFREEZE_BULK, UA_INDEX_SETTINGS_EDIT, UA_SHOW_DETAILS_CLICK, - UA_DETAIL_PANEL_SUMMARY_TAB_CLICK, - UA_DETAIL_PANEL_SETTINGS_TAB_CLICK, - UA_DETAIL_PANEL_MAPPING_TAB_CLICK, - UA_DETAIL_PANEL_STATS_TAB_CLICK, - UA_DETAIL_PANEL_EDIT_SETTINGS_TAB_CLICK, + UA_DETAIL_PANEL_SUMMARY_TAB, + UA_DETAIL_PANEL_SETTINGS_TAB, + UA_DETAIL_PANEL_MAPPING_TAB, + UA_DETAIL_PANEL_STATS_TAB, + UA_DETAIL_PANEL_EDIT_SETTINGS_TAB, ]; diff --git a/x-pack/plugins/index_management/public/constants/detail_panel_tabs.js b/x-pack/plugins/index_management/public/constants/detail_panel_tabs.js new file mode 100644 index 0000000000000..60097e6f36e5c --- /dev/null +++ b/x-pack/plugins/index_management/public/constants/detail_panel_tabs.js @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const TAB_SUMMARY = 'TAB_SUMMARY'; +export const TAB_SETTINGS = 'TAB_SETTINGS'; +export const TAB_MAPPING = 'TAB_MAPPING'; +export const TAB_STATS = 'TAB_STATS'; +export const TAB_EDIT_SETTINGS = 'TAB_EDIT_SETTINGS'; diff --git a/x-pack/plugins/index_management/public/constants/index.js b/x-pack/plugins/index_management/public/constants/index.js index af4da7533af4e..4369194c49ad5 100644 --- a/x-pack/plugins/index_management/public/constants/index.js +++ b/x-pack/plugins/index_management/public/constants/index.js @@ -5,3 +5,11 @@ */ export { REFRESH_RATE_INDEX_LIST } from './refresh_intervals'; + +export { + TAB_SUMMARY, + TAB_SETTINGS, + TAB_MAPPING, + TAB_STATS, + TAB_EDIT_SETTINGS, +} from './detail_panel_tabs'; diff --git a/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/detail_panel.js b/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/detail_panel.js index fb65779183349..ea131164b49dd 100644 --- a/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/detail_panel.js +++ b/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/detail_panel.js @@ -5,12 +5,8 @@ */ import React, { Component, Fragment } from 'react'; -import { FormattedMessage } from '@kbn/i18n/react'; import { Route } from 'react-router-dom'; -import { ShowJson } from './show_json'; -import { Summary } from './summary'; -import { EditSettingsJson } from './edit_settings_json'; -import { renderBadges } from '../../../../lib/render_badges'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiCallOut, EuiFlexGroup, @@ -24,14 +20,61 @@ import { EuiTab, EuiTitle, } from '@elastic/eui'; -import { IndexActionsContextMenu } from '../../components'; +import { renderBadges } from '../../../../lib/render_badges'; import { INDEX_OPEN } from '../../../../../common/constants'; +import { + TAB_SUMMARY, + TAB_SETTINGS, + TAB_MAPPING, + TAB_STATS, + TAB_EDIT_SETTINGS, +} from '../../../../constants'; +import { IndexActionsContextMenu } from '../../components'; +import { ShowJson } from './show_json'; +import { Summary } from './summary'; +import { EditSettingsJson } from './edit_settings_json'; -function capitalizeFirstLetter(string) { - return string.charAt(0).toUpperCase() + string.slice(1); -} +const tabToHumanizedMap = { + [TAB_SUMMARY]: ( + + ), + [TAB_SETTINGS]: ( + + ), + [TAB_MAPPING]: ( + + ), + [TAB_STATS]: ( + + ), + [TAB_EDIT_SETTINGS]: ( + + ), +}; + +const tabs = [ + TAB_SUMMARY, + TAB_SETTINGS, + TAB_MAPPING, + TAB_STATS, + TAB_EDIT_SETTINGS, +]; -const tabs = ['Summary', 'Settings', 'Mapping', 'Stats', 'Edit settings']; export class DetailPanel extends Component { renderTabs() { const { panelType, indexName, index, openDetailPanel } = this.props; @@ -42,10 +85,10 @@ export class DetailPanel extends Component { onClick={() => openDetailPanel({ panelType: tab, indexName })} isSelected={isSelected} data-test-subj={`detailPanelTab${isSelected ? 'Selected' : ''}`} - disabled={tab === 'Stats' && index.status !== INDEX_OPEN} + disabled={tab === TAB_STATS && index.status !== INDEX_OPEN} key={i} > - {capitalizeFirstLetter(tab)} + {tabToHumanizedMap[tab]} ); }); @@ -57,12 +100,12 @@ export class DetailPanel extends Component { } let component = null; switch (panelType) { - case 'Edit settings': + case TAB_EDIT_SETTINGS: component = ; break; - case 'Mapping': - case 'Settings': - case 'Stats': + case TAB_MAPPING: + case TAB_SETTINGS: + case TAB_STATS: component = ; break; default: diff --git a/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/edit_settings_json/edit_settings_json.js b/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/edit_settings_json/edit_settings_json.js index 2bd4319fcc616..f5b5dd3771e79 100644 --- a/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/edit_settings_json/edit_settings_json.js +++ b/x-pack/plugins/index_management/public/sections/index_list/components/detail_panel/edit_settings_json/edit_settings_json.js @@ -18,6 +18,7 @@ import { EuiTextColor, EuiTitle, } from '@elastic/eui'; +import { TAB_SETTINGS } from '../../../../../constants'; import { settingsToDisplay, readOnlySettings @@ -57,7 +58,7 @@ export class EditSettingsJson extends React.PureComponent { } componentWillMount() { const { indexName } = this.props; - this.props.loadIndexData({ dataType: 'Settings', indexName }); + this.props.loadIndexData({ dataType: TAB_SETTINGS, indexName }); } componentDidUpdate() { const { data, indexStatus } = this.props; diff --git a/x-pack/plugins/index_management/public/sections/index_list/components/index_actions_context_menu/index_actions_context_menu.container.js b/x-pack/plugins/index_management/public/sections/index_list/components/index_actions_context_menu/index_actions_context_menu.container.js index a0884e0883b1d..369141337d4ef 100644 --- a/x-pack/plugins/index_management/public/sections/index_list/components/index_actions_context_menu/index_actions_context_menu.container.js +++ b/x-pack/plugins/index_management/public/sections/index_list/components/index_actions_context_menu/index_actions_context_menu.container.js @@ -6,6 +6,12 @@ import { connect } from 'react-redux'; import { IndexActionsContextMenu as PresentationComponent } from './index_actions_context_menu'; +import { + TAB_SETTINGS, + TAB_MAPPING, + TAB_STATS, + TAB_EDIT_SETTINGS, +} from '../../../../constants'; import { clearCacheIndices, closeIndices, @@ -69,18 +75,18 @@ const mapDispatchToProps = (dispatch, { indexNames }) => { dispatch(forcemergeIndices({ indexNames, maxNumSegments })); }, showSettings: () => { - dispatch(openDetailPanel({ indexName: indexNames[0], panelType: 'Settings' })); + dispatch(openDetailPanel({ indexName: indexNames[0], panelType: TAB_SETTINGS })); }, showMapping: () => { - dispatch(openDetailPanel({ indexName: indexNames[0], panelType: 'Mapping' })); + dispatch(openDetailPanel({ indexName: indexNames[0], panelType: TAB_MAPPING })); }, showStats: () => { - dispatch(openDetailPanel({ indexName: indexNames[0], panelType: 'Stats' })); + dispatch(openDetailPanel({ indexName: indexNames[0], panelType: TAB_STATS })); }, editIndex: () => { const indexName = indexNames ? indexNames[0] : null; if (indexName) { - dispatch(openDetailPanel({ indexName, panelType: 'Edit settings' })); + dispatch(openDetailPanel({ indexName, panelType: TAB_EDIT_SETTINGS })); } }, deleteIndices: () => { diff --git a/x-pack/plugins/index_management/public/sections/index_list/components/index_table/index_table.js b/x-pack/plugins/index_management/public/sections/index_list/components/index_table/index_table.js index c307cb6ab3560..d1102279c7fed 100644 --- a/x-pack/plugins/index_management/public/sections/index_list/components/index_table/index_table.js +++ b/x-pack/plugins/index_management/public/sections/index_list/components/index_table/index_table.js @@ -8,9 +8,6 @@ import React, { Component, Fragment } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; import { Route } from 'react-router-dom'; -import { NoMatch } from '../../../no_match'; -import { healthToColor } from '../../../../services'; -import { REFRESH_RATE_INDEX_LIST } from '../../../../constants'; import { EuiButton, @@ -38,13 +35,17 @@ import { EuiPageContent, } from '@elastic/eui'; -import { IndexActionsContextMenu } from '../../components'; +import { UA_SHOW_DETAILS_CLICK } from '../../../../../common/constants'; +import { REFRESH_RATE_INDEX_LIST } from '../../../../constants'; +import { healthToColor, trackUserAction } from '../../../../services'; import { getBannerExtensions, getFilterExtensions, getToggleExtensions, } from '../../../../index_management_extensions'; import { renderBadges } from '../../../../lib/render_badges'; +import { NoMatch } from '../../../no_match'; +import { IndexActionsContextMenu } from '../../components'; const HEADERS = { name: i18n.translate('xpack.idxMgmt.indexTable.headers.nameHeader', { @@ -223,6 +224,7 @@ export class IndexTableUi extends Component { className="indTable__link" data-test-subj="indexTableIndexNameLink" onClick={() => { + trackUserAction(UA_SHOW_DETAILS_CLICK); openDetailPanel(value); }} > diff --git a/x-pack/plugins/index_management/public/services/api.js b/x-pack/plugins/index_management/public/services/api.js index 594e416c768df..fea327f951d1b 100644 --- a/x-pack/plugins/index_management/public/services/api.js +++ b/x-pack/plugins/index_management/public/services/api.js @@ -23,6 +23,11 @@ import { UA_INDEX_UNFREEZE, UA_INDEX_UNFREEZE_BULK, } from '../../common/constants'; +import { + TAB_SETTINGS, + TAB_MAPPING, + TAB_STATS, +} from '../constants'; import { trackUserRequestBulk } from './track_user_action'; let httpClient; @@ -150,11 +155,13 @@ export async function loadIndexMapping(indexName) { export async function loadIndexData(type, indexName) { switch (type) { - case 'Mapping': + case TAB_MAPPING: return loadIndexMapping(indexName); - case 'Settings': + + case TAB_SETTINGS: return loadIndexSettings(indexName); - case 'Stats': + + case TAB_STATS: return loadIndexStats(indexName); } } diff --git a/x-pack/plugins/index_management/public/services/index.js b/x-pack/plugins/index_management/public/services/index.js index e3fb12070753f..1ed5a47a4c062 100644 --- a/x-pack/plugins/index_management/public/services/index.js +++ b/x-pack/plugins/index_management/public/services/index.js @@ -8,3 +8,4 @@ export * from './api'; export { sortTable } from './sort_table'; export { filterItems } from './filter_items'; export { healthToColor } from './health_to_color'; +export { trackUserAction, trackUserRequest, trackUserRequestBulk } from './track_user_action'; diff --git a/x-pack/plugins/index_management/public/store/reducers/detail_panel.js b/x-pack/plugins/index_management/public/store/reducers/detail_panel.js index 41105b745693e..c7752760c6fa5 100644 --- a/x-pack/plugins/index_management/public/store/reducers/detail_panel.js +++ b/x-pack/plugins/index_management/public/store/reducers/detail_panel.js @@ -5,6 +5,21 @@ */ import { handleActions } from 'redux-actions'; +import { + UA_DETAIL_PANEL_SUMMARY_TAB, + UA_DETAIL_PANEL_SETTINGS_TAB, + UA_DETAIL_PANEL_MAPPING_TAB, + UA_DETAIL_PANEL_STATS_TAB, + UA_DETAIL_PANEL_EDIT_SETTINGS_TAB, +} from '../../../common/constants'; +import { + TAB_SUMMARY, + TAB_SETTINGS, + TAB_MAPPING, + TAB_STATS, + TAB_EDIT_SETTINGS, +} from '../../constants'; +import { trackUserAction } from '../../services'; import { openDetailPanel, closeDetailPanel } from '../actions/detail_panel'; import { loadIndexDataSuccess } from '../actions/load_index_data'; import { updateIndexSettingsSuccess, updateIndexSettingsError } from '../actions/update_index_settings'; @@ -29,8 +44,21 @@ export const detailPanel = handleActions( indexName, title } = action.payload; + + const panelTypeToUserActionMap = { + [TAB_SUMMARY]: UA_DETAIL_PANEL_SUMMARY_TAB, + [TAB_SETTINGS]: UA_DETAIL_PANEL_SETTINGS_TAB, + [TAB_MAPPING]: UA_DETAIL_PANEL_MAPPING_TAB, + [TAB_STATS]: UA_DETAIL_PANEL_STATS_TAB, + [TAB_EDIT_SETTINGS]: UA_DETAIL_PANEL_EDIT_SETTINGS_TAB, + }; + + if (panelTypeToUserActionMap[panelType]) { + trackUserAction(panelTypeToUserActionMap[panelType]); + } + return { - panelType: panelType || state.panelType || 'Summary', + panelType: panelType || state.panelType || TAB_SUMMARY, indexName, title }; From b5328bc7df3cc53fb55d36c8e93068ae13232d84 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 6 Mar 2019 14:09:21 -0800 Subject: [PATCH 4/6] Track update settings action. --- x-pack/plugins/index_management/common/constants/index.js | 1 + .../index_management/common/constants/user_action.js | 2 ++ x-pack/plugins/index_management/public/services/api.js | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/index_management/common/constants/index.js b/x-pack/plugins/index_management/common/constants/index.js index fab5002fd6fe1..a5496d92e57ad 100644 --- a/x-pack/plugins/index_management/common/constants/index.js +++ b/x-pack/plugins/index_management/common/constants/index.js @@ -11,6 +11,7 @@ export * from './index_statuses'; export { UA_APP_NAME, USER_ACTIONS, + UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, UA_INDEX_CLEAR_CACHE_BULK, UA_INDEX_DELETE, diff --git a/x-pack/plugins/index_management/common/constants/user_action.js b/x-pack/plugins/index_management/common/constants/user_action.js index e64c21ebd8a1c..dfbe17cc6f657 100644 --- a/x-pack/plugins/index_management/common/constants/user_action.js +++ b/x-pack/plugins/index_management/common/constants/user_action.js @@ -6,6 +6,7 @@ export const UA_APP_NAME = 'index-management'; +export const UA_UPDATE_SETTINGS = 'update_settings'; export const UA_INDEX_CLEAR_CACHE = 'index_clear_cache'; export const UA_INDEX_CLEAR_CACHE_BULK = 'index_clear_cache_bulk'; export const UA_INDEX_DELETE = 'index_delete'; @@ -31,6 +32,7 @@ export const UA_DETAIL_PANEL_STATS_TAB = 'detail_panel_stats_tab'; export const UA_DETAIL_PANEL_EDIT_SETTINGS_TAB = 'detail_panel_edit_settings_tab'; export const USER_ACTIONS = [ + UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, UA_INDEX_CLEAR_CACHE_BULK, UA_INDEX_DELETE, diff --git a/x-pack/plugins/index_management/public/services/api.js b/x-pack/plugins/index_management/public/services/api.js index fea327f951d1b..2020879191657 100644 --- a/x-pack/plugins/index_management/public/services/api.js +++ b/x-pack/plugins/index_management/public/services/api.js @@ -6,6 +6,7 @@ import chrome from 'ui/chrome'; import { + UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, UA_INDEX_CLEAR_CACHE_BULK, UA_INDEX_DELETE, @@ -28,7 +29,7 @@ import { TAB_MAPPING, TAB_STATS, } from '../constants'; -import { trackUserRequestBulk } from './track_user_action'; +import { trackUserRequest, trackUserRequestBulk } from './track_user_action'; let httpClient; @@ -140,7 +141,9 @@ export async function loadIndexSettings(indexName) { } export async function updateIndexSettings(indexName, settings) { - return await httpClient.put(`${apiPrefix}/settings/${indexName}`, settings); + const request = httpClient.put(`${apiPrefix}/settings/${indexName}`, settings); + trackUserRequest(request, UA_UPDATE_SETTINGS); + return await request; } export async function loadIndexStats(indexName) { From 0f38c77b708009d76ed831d7963a49abe621bb55 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 11 Mar 2019 09:21:41 -0700 Subject: [PATCH 5/6] Move request-tracking logic into api service. - Track refresh action. - Rename 'bulk' action type to 'many' for clarity. --- .../common/constants/index.js | 22 ++--- .../common/constants/user_action.js | 60 +++++++------ .../index_management/public/services/api.js | 85 ++++++++++++------- .../index_management/public/services/index.js | 2 +- .../public/services/track_user_action.js | 14 --- 5 files changed, 100 insertions(+), 83 deletions(-) diff --git a/x-pack/plugins/index_management/common/constants/index.js b/x-pack/plugins/index_management/common/constants/index.js index a5496d92e57ad..7b2df1a3ae3a9 100644 --- a/x-pack/plugins/index_management/common/constants/index.js +++ b/x-pack/plugins/index_management/common/constants/index.js @@ -13,21 +13,23 @@ export { USER_ACTIONS, UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, - UA_INDEX_CLEAR_CACHE_BULK, + UA_INDEX_CLEAR_CACHE_MANY, + UA_INDEX_CLOSE, + UA_INDEX_CLOSE_MANY, UA_INDEX_DELETE, - UA_INDEX_DELETE_BULK, + UA_INDEX_DELETE_MANY, UA_INDEX_FLUSH, - UA_INDEX_FLUSH_BULK, + UA_INDEX_FLUSH_MANY, UA_INDEX_FORCE_MERGE, - UA_INDEX_FORCE_MERGE_BULK, - UA_INDEX_CLOSE, - UA_INDEX_CLOSE_BULK, - UA_INDEX_OPEN, - UA_INDEX_OPEN_BULK, + UA_INDEX_FORCE_MERGE_MANY, UA_INDEX_FREEZE, - UA_INDEX_FREEZE_BULK, + UA_INDEX_FREEZE_MANY, + UA_INDEX_OPEN, + UA_INDEX_OPEN_MANY, + UA_INDEX_REFRESH, + UA_INDEX_REFRESH_MANY, UA_INDEX_UNFREEZE, - UA_INDEX_UNFREEZE_BULK, + UA_INDEX_UNFREEZE_MANY, UA_INDEX_SETTINGS_EDIT, UA_SHOW_DETAILS_CLICK, UA_DETAIL_PANEL_SUMMARY_TAB, diff --git a/x-pack/plugins/index_management/common/constants/user_action.js b/x-pack/plugins/index_management/common/constants/user_action.js index dfbe17cc6f657..880a05d35d3ee 100644 --- a/x-pack/plugins/index_management/common/constants/user_action.js +++ b/x-pack/plugins/index_management/common/constants/user_action.js @@ -8,52 +8,56 @@ export const UA_APP_NAME = 'index-management'; export const UA_UPDATE_SETTINGS = 'update_settings'; export const UA_INDEX_CLEAR_CACHE = 'index_clear_cache'; -export const UA_INDEX_CLEAR_CACHE_BULK = 'index_clear_cache_bulk'; +export const UA_INDEX_CLEAR_CACHE_MANY = 'index_clear_cache_many'; +export const UA_INDEX_CLOSE = 'index_close'; +export const UA_INDEX_CLOSE_MANY = 'index_close_many'; export const UA_INDEX_DELETE = 'index_delete'; -export const UA_INDEX_DELETE_BULK = 'index_delete_bulk'; +export const UA_INDEX_DELETE_MANY = 'index_delete_many'; export const UA_INDEX_FLUSH = 'index_flush'; -export const UA_INDEX_FLUSH_BULK = 'index_flush_bulk'; +export const UA_INDEX_FLUSH_MANY = 'index_flush_many'; export const UA_INDEX_FORCE_MERGE = 'index_force_merge'; -export const UA_INDEX_FORCE_MERGE_BULK = 'index_force_merge_bulk'; -export const UA_INDEX_CLOSE = 'index_close'; -export const UA_INDEX_CLOSE_BULK = 'index_close_bulk'; -export const UA_INDEX_OPEN = 'index_open'; -export const UA_INDEX_OPEN_BULK = 'index_open_bulk'; +export const UA_INDEX_FORCE_MERGE_MANY = 'index_force_merge_many'; export const UA_INDEX_FREEZE = 'index_freeze'; -export const UA_INDEX_FREEZE_BULK = 'index_freeze_bulk'; -export const UA_INDEX_UNFREEZE = 'index_unfreeze'; -export const UA_INDEX_UNFREEZE_BULK = 'index_unfreeze_bulk'; +export const UA_INDEX_FREEZE_MANY = 'index_freeze_many'; +export const UA_INDEX_OPEN = 'index_open'; +export const UA_INDEX_OPEN_MANY = 'index_open_many'; +export const UA_INDEX_REFRESH = 'index_refresh'; +export const UA_INDEX_REFRESH_MANY = 'index_refresh_many'; export const UA_INDEX_SETTINGS_EDIT = 'index_settings_edit'; +export const UA_INDEX_UNFREEZE = 'index_unfreeze'; +export const UA_INDEX_UNFREEZE_MANY = 'index_unfreeze_many'; export const UA_SHOW_DETAILS_CLICK = 'show_details_click'; -export const UA_DETAIL_PANEL_SUMMARY_TAB = 'detail_panel_summary_tab'; -export const UA_DETAIL_PANEL_SETTINGS_TAB = 'detail_panel_settings_tab'; +export const UA_DETAIL_PANEL_EDIT_SETTINGS_TAB = 'detail_panel_edit_settings_tab'; export const UA_DETAIL_PANEL_MAPPING_TAB = 'detail_panel_mapping_tab'; +export const UA_DETAIL_PANEL_SETTINGS_TAB = 'detail_panel_settings_tab'; export const UA_DETAIL_PANEL_STATS_TAB = 'detail_panel_stats_tab'; -export const UA_DETAIL_PANEL_EDIT_SETTINGS_TAB = 'detail_panel_edit_settings_tab'; +export const UA_DETAIL_PANEL_SUMMARY_TAB = 'detail_panel_summary_tab'; export const USER_ACTIONS = [ UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, - UA_INDEX_CLEAR_CACHE_BULK, + UA_INDEX_CLEAR_CACHE_MANY, + UA_INDEX_CLOSE, + UA_INDEX_CLOSE_MANY, UA_INDEX_DELETE, - UA_INDEX_DELETE_BULK, + UA_INDEX_DELETE_MANY, UA_INDEX_FLUSH, - UA_INDEX_FLUSH_BULK, + UA_INDEX_FLUSH_MANY, UA_INDEX_FORCE_MERGE, - UA_INDEX_FORCE_MERGE_BULK, - UA_INDEX_CLOSE, - UA_INDEX_CLOSE_BULK, - UA_INDEX_OPEN, - UA_INDEX_OPEN_BULK, + UA_INDEX_FORCE_MERGE_MANY, UA_INDEX_FREEZE, - UA_INDEX_FREEZE_BULK, - UA_INDEX_UNFREEZE, - UA_INDEX_UNFREEZE_BULK, + UA_INDEX_FREEZE_MANY, + UA_INDEX_OPEN, + UA_INDEX_OPEN_MANY, + UA_INDEX_REFRESH, + UA_INDEX_REFRESH_MANY, UA_INDEX_SETTINGS_EDIT, + UA_INDEX_UNFREEZE, + UA_INDEX_UNFREEZE_MANY, UA_SHOW_DETAILS_CLICK, - UA_DETAIL_PANEL_SUMMARY_TAB, - UA_DETAIL_PANEL_SETTINGS_TAB, + UA_DETAIL_PANEL_EDIT_SETTINGS_TAB, UA_DETAIL_PANEL_MAPPING_TAB, + UA_DETAIL_PANEL_SETTINGS_TAB, UA_DETAIL_PANEL_STATS_TAB, - UA_DETAIL_PANEL_EDIT_SETTINGS_TAB, + UA_DETAIL_PANEL_SUMMARY_TAB, ]; diff --git a/x-pack/plugins/index_management/public/services/api.js b/x-pack/plugins/index_management/public/services/api.js index 2020879191657..f553f27b3875e 100644 --- a/x-pack/plugins/index_management/public/services/api.js +++ b/x-pack/plugins/index_management/public/services/api.js @@ -5,31 +5,36 @@ */ import chrome from 'ui/chrome'; + import { UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, - UA_INDEX_CLEAR_CACHE_BULK, + UA_INDEX_CLEAR_CACHE_MANY, + UA_INDEX_CLOSE, + UA_INDEX_CLOSE_MANY, UA_INDEX_DELETE, - UA_INDEX_DELETE_BULK, + UA_INDEX_DELETE_MANY, UA_INDEX_FLUSH, - UA_INDEX_FLUSH_BULK, + UA_INDEX_FLUSH_MANY, UA_INDEX_FORCE_MERGE, - UA_INDEX_FORCE_MERGE_BULK, - UA_INDEX_CLOSE, - UA_INDEX_CLOSE_BULK, - UA_INDEX_OPEN, - UA_INDEX_OPEN_BULK, + UA_INDEX_FORCE_MERGE_MANY, UA_INDEX_FREEZE, - UA_INDEX_FREEZE_BULK, + UA_INDEX_FREEZE_MANY, + UA_INDEX_OPEN, + UA_INDEX_OPEN_MANY, + UA_INDEX_REFRESH, + UA_INDEX_REFRESH_MANY, UA_INDEX_UNFREEZE, - UA_INDEX_UNFREEZE_BULK, + UA_INDEX_UNFREEZE_MANY, } from '../../common/constants'; + import { TAB_SETTINGS, TAB_MAPPING, TAB_STATS, } from '../constants'; -import { trackUserRequest, trackUserRequestBulk } from './track_user_action'; + +import { trackUserAction } from './track_user_action'; let httpClient; @@ -60,8 +65,10 @@ export async function closeIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/close`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_CLOSE, UA_INDEX_CLOSE_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/close`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_CLOSE_MANY : UA_INDEX_CLOSE; + trackUserAction(actionType); return response.data; } @@ -69,8 +76,10 @@ export async function deleteIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/delete`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_DELETE, UA_INDEX_DELETE_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/delete`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_DELETE_MANY : UA_INDEX_DELETE; + trackUserAction(actionType); return response.data; } @@ -78,8 +87,10 @@ export async function openIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/open`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_OPEN, UA_INDEX_OPEN_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/open`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_OPEN_MANY : UA_INDEX_OPEN; + trackUserAction(actionType); return response.data; } @@ -88,6 +99,9 @@ export async function refreshIndices(indices) { indices }; const response = await httpClient.post(`${apiPrefix}/indices/refresh`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_REFRESH_MANY : UA_INDEX_REFRESH; + trackUserAction(actionType); return response.data; } @@ -95,8 +109,10 @@ export async function flushIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/flush`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_FLUSH, UA_INDEX_FLUSH_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/flush`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_FLUSH_MANY : UA_INDEX_FLUSH; + trackUserAction(actionType); return response.data; } @@ -105,8 +121,10 @@ export async function forcemergeIndices(indices, maxNumSegments) { indices, maxNumSegments }; - const request = httpClient.post(`${apiPrefix}/indices/forcemerge`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_FORCE_MERGE, UA_INDEX_FORCE_MERGE_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/forcemerge`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_FORCE_MERGE_MANY : UA_INDEX_FORCE_MERGE; + trackUserAction(actionType); return response.data; } @@ -114,24 +132,30 @@ export async function clearCacheIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/clear_cache`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_CLEAR_CACHE, UA_INDEX_CLEAR_CACHE_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/clear_cache`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_CLEAR_CACHE_MANY : UA_INDEX_CLEAR_CACHE; + trackUserAction(actionType); return response.data; } export async function freezeIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/freeze`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_FREEZE, UA_INDEX_FREEZE_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/freeze`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_FREEZE_MANY : UA_INDEX_FREEZE; + trackUserAction(actionType); return response.data; } export async function unfreezeIndices(indices) { const body = { indices }; - const request = httpClient.post(`${apiPrefix}/indices/unfreeze`, body); - const response = await trackUserRequestBulk(request, indices.length, UA_INDEX_UNFREEZE, UA_INDEX_UNFREEZE_BULK); + const response = await httpClient.post(`${apiPrefix}/indices/unfreeze`, body); + // Only track successful requests. + const actionType = indices.length > 1 ? UA_INDEX_UNFREEZE_MANY : UA_INDEX_UNFREEZE; + trackUserAction(actionType); return response.data; } @@ -141,9 +165,10 @@ export async function loadIndexSettings(indexName) { } export async function updateIndexSettings(indexName, settings) { - const request = httpClient.put(`${apiPrefix}/settings/${indexName}`, settings); - trackUserRequest(request, UA_UPDATE_SETTINGS); - return await request; + const response = await httpClient.put(`${apiPrefix}/settings/${indexName}`, settings); + // Only track successful requests. + trackUserAction(UA_UPDATE_SETTINGS); + return response; } export async function loadIndexStats(indexName) { diff --git a/x-pack/plugins/index_management/public/services/index.js b/x-pack/plugins/index_management/public/services/index.js index 1ed5a47a4c062..8bd0afcb827a9 100644 --- a/x-pack/plugins/index_management/public/services/index.js +++ b/x-pack/plugins/index_management/public/services/index.js @@ -8,4 +8,4 @@ export * from './api'; export { sortTable } from './sort_table'; export { filterItems } from './filter_items'; export { healthToColor } from './health_to_color'; -export { trackUserAction, trackUserRequest, trackUserRequestBulk } from './track_user_action'; +export { trackUserAction } from './track_user_action'; diff --git a/x-pack/plugins/index_management/public/services/track_user_action.js b/x-pack/plugins/index_management/public/services/track_user_action.js index 7ddb3b9cb5e78..51b0e3154c525 100644 --- a/x-pack/plugins/index_management/public/services/track_user_action.js +++ b/x-pack/plugins/index_management/public/services/track_user_action.js @@ -12,17 +12,3 @@ export function trackUserAction(actionType) { const userActionUri = createUserActionUri(UA_APP_NAME, actionType); getHttpClient().post(userActionUri); } - -export function trackUserRequest(request, actionType) { - // Only track successful actions. - request.then(() => trackUserAction(actionType)); - return request; -} - -export function trackUserRequestBulk(request, itemCount, actionTypeSingle, actionTypeBulk) { - if (itemCount > 1) { - return trackUserRequest(request, actionTypeBulk); - } - - return trackUserRequest(request, actionTypeSingle); -} From b0e0003af1a7775675708cc1da91cafba997ef0d Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 11 Mar 2019 09:26:57 -0700 Subject: [PATCH 6/6] Track app load. --- .../common/constants/index.js | 1 + .../common/constants/user_action.js | 2 ++ x-pack/plugins/index_management/public/app.js | 31 ++++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/index_management/common/constants/index.js b/x-pack/plugins/index_management/common/constants/index.js index 7b2df1a3ae3a9..cbd9882de5168 100644 --- a/x-pack/plugins/index_management/common/constants/index.js +++ b/x-pack/plugins/index_management/common/constants/index.js @@ -10,6 +10,7 @@ export * from './index_statuses'; export { UA_APP_NAME, + UA_APP_LOAD, USER_ACTIONS, UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, diff --git a/x-pack/plugins/index_management/common/constants/user_action.js b/x-pack/plugins/index_management/common/constants/user_action.js index 880a05d35d3ee..9f491e4918c4d 100644 --- a/x-pack/plugins/index_management/common/constants/user_action.js +++ b/x-pack/plugins/index_management/common/constants/user_action.js @@ -6,6 +6,7 @@ export const UA_APP_NAME = 'index-management'; +export const UA_APP_LOAD = 'app_load'; export const UA_UPDATE_SETTINGS = 'update_settings'; export const UA_INDEX_CLEAR_CACHE = 'index_clear_cache'; export const UA_INDEX_CLEAR_CACHE_MANY = 'index_clear_cache_many'; @@ -34,6 +35,7 @@ export const UA_DETAIL_PANEL_STATS_TAB = 'detail_panel_stats_tab'; export const UA_DETAIL_PANEL_SUMMARY_TAB = 'detail_panel_summary_tab'; export const USER_ACTIONS = [ + UA_APP_LOAD, UA_UPDATE_SETTINGS, UA_INDEX_CLEAR_CACHE, UA_INDEX_CLEAR_CACHE_MANY, diff --git a/x-pack/plugins/index_management/public/app.js b/x-pack/plugins/index_management/public/app.js index de978674206f6..5446e20f18523 100644 --- a/x-pack/plugins/index_management/public/app.js +++ b/x-pack/plugins/index_management/public/app.js @@ -4,17 +4,26 @@ * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; +import React, { Component } from 'react'; import { Switch, Route, Redirect } from 'react-router-dom'; -import { BASE_PATH } from '../common/constants'; +import { BASE_PATH, UA_APP_LOAD } from '../common/constants'; import { IndexList } from './sections/index_list'; +import { trackUserAction } from './services'; -export const App = () => ( -
- - - - - -
-); +export class App extends Component { + componentWillMount() { + trackUserAction(UA_APP_LOAD); + } + + render() { + return ( +
+ + + + + +
+ ); + } +}