Skip to content

Commit

Permalink
[8.6] [Discover] Track adhoc data views usage (#144244) (#145543)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.6`:
- [[Discover] Track adhoc data views usage
(#144244)](#144244)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dmitry
Tomashevich","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-17T11:29:35Z","message":"[Discover]
Track adhoc data views usage (#144244)\n\n## Summary\r\n\r\nCloses
#141090\r\n\r\nThis PR enabled metrics for adhoc data views usage in
Discover.\r\n\r\nCo-authored-by: Julia Rechkunova
<[email protected]>","sha":"2454fd01b08767b31f25fe4674ac92b9633606f6","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:skip","auto-backport","Team:DataDiscovery","v8.6.0","v8.7.0"],"number":144244,"url":"https://github.com/elastic/kibana/pull/144244","mergeCommit":{"message":"[Discover]
Track adhoc data views usage (#144244)\n\n## Summary\r\n\r\nCloses
#141090\r\n\r\nThis PR enabled metrics for adhoc data views usage in
Discover.\r\n\r\nCo-authored-by: Julia Rechkunova
<[email protected]>","sha":"2454fd01b08767b31f25fe4674ac92b9633606f6"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/144244","number":144244,"mergeCommit":{"message":"[Discover]
Track adhoc data views usage (#144244)\n\n## Summary\r\n\r\nCloses
#141090\r\n\r\nThis PR enabled metrics for adhoc data views usage in
Discover.\r\n\r\nCo-authored-by: Julia Rechkunova
<[email protected]>","sha":"2454fd01b08767b31f25fe4674ac92b9633606f6"}}]}]
BACKPORT-->

Co-authored-by: Dmitry Tomashevich <[email protected]>
  • Loading branch information
kibanamachine and dimaanj authored Nov 17, 2022
1 parent 03042ac commit cbdfade
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import { useCallback, useEffect, useState } from 'react';
import type { DataView, DataViewsContract } from '@kbn/data-views-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { METRIC_TYPE } from '@kbn/analytics';
import {
UPDATE_FILTER_REFERENCES_ACTION,
UPDATE_FILTER_REFERENCES_TRIGGER,
} from '@kbn/unified-search-plugin/public';
import { ActionExecutionContext } from '@kbn/ui-actions-plugin/public';
import type { FilterManager } from '@kbn/data-plugin/public';
import type { ToastsStart } from '@kbn/core-notifications-browser';
import { ADHOC_DATA_VIEW_RENDER_EVENT } from '../../../constants';
import { getUiActions } from '../../../kibana_services';
import { useConfirmPersistencePrompt } from '../../../hooks/use_confirm_persistence_prompt';
import { GetStateReturn } from '../services/discover_state';
Expand All @@ -29,6 +31,7 @@ export const useAdHocDataViews = ({
filterManager,
dataViews,
toastNotifications,
trackUiMetric,
}: {
dataView: DataView;
savedSearch: SavedSearch;
Expand All @@ -37,6 +40,7 @@ export const useAdHocDataViews = ({
dataViews: DataViewsContract;
filterManager: FilterManager;
toastNotifications: ToastsStart;
trackUiMetric?: (metricType: string, eventName: string | string[], count?: number) => void;
}) => {
const [adHocDataViewList, setAdHocDataViewList] = useState<DataView[]>(
!dataView.isPersisted() ? [dataView] : []
Expand All @@ -48,8 +52,9 @@ export const useAdHocDataViews = ({
const existing = prev.find((prevDataView) => prevDataView.id === dataView.id);
return existing ? prev : [...prev, dataView];
});
trackUiMetric?.(METRIC_TYPE.COUNT, ADHOC_DATA_VIEW_RENDER_EVENT);
}
}, [dataView]);
}, [dataView, trackUiMetric]);

/**
* Takes care of checking data view id references in filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export function useDiscoverState({
setExpandedDoc: (doc?: DataTableRecord) => void;
dataViewList: DataViewListItem[];
}) {
const { uiSettings, data, filterManager, dataViews, toastNotifications } = services;
const { uiSettings, data, filterManager, dataViews, toastNotifications, trackUiMetric } =
services;
const useNewFieldsApi = useMemo(() => !uiSettings.get(SEARCH_FIELDS_FROM_SOURCE), [uiSettings]);
const { timefilter } = data.query.timefilter;

Expand Down Expand Up @@ -133,6 +134,7 @@ export function useDiscoverState({
setUrlTracking,
filterManager,
toastNotifications,
trackUiMetric,
});

const [savedDataViewList, setSavedDataViewList] = useState(initialDataViewList);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/public/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
* Side Public License, v 1.
*/

export const ADHOC_DATA_VIEW_RENDER_EVENT = 'ad_hoc_data_view';

export const SEARCH_SESSION_ID_QUERY_PARAM = 'searchSessionId';
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { METRIC_TYPE } from '@kbn/analytics';
import { getSortForEmbeddable, SortPair } from '../utils/sorting';
import { RecordRawType } from '../application/main/hooks/use_saved_search';
import { buildDataTableRecord } from '../utils/build_data_record';
Expand All @@ -60,6 +61,7 @@ import { updateSearchSource } from './utils/update_search_source';
import { FieldStatisticsTable } from '../application/main/components/field_stats_table';
import { getRawRecordType } from '../application/main/utils/get_raw_record_type';
import { fetchSql } from '../application/main/utils/fetch_sql';
import { ADHOC_DATA_VIEW_RENDER_EVENT } from '../constants';

export type SearchProps = Partial<DiscoverGridProps> &
Partial<DocTableProps> & {
Expand Down Expand Up @@ -302,6 +304,11 @@ export class SavedSearchEmbeddable
}
const sort = this.getSort(this.savedSearch.sort, dataView);

if (!dataView.isPersisted()) {
// one used adhoc data view
this.services.trackUiMetric?.(METRIC_TYPE.COUNT, ADHOC_DATA_VIEW_RENDER_EVENT);
}

const props: SearchProps = {
columns: this.savedSearch.columns,
savedSearchId: this.savedSearch.id,
Expand Down

0 comments on commit cbdfade

Please sign in to comment.