From 2224bf6be3aaa67a0d69fcfc114e445efab1787c Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Tue, 25 Apr 2023 11:20:48 -0300 Subject: [PATCH 1/4] Add host limit telemetry --- .../cloud_full_story/server/config.ts | 1 + .../hosts/components/kpis/hosts_tile.tsx | 2 +- .../hosts/components/kpis/kpi_grid.tsx | 2 +- .../metrics/hosts/components/kpis/tile.tsx | 4 ++-- .../components/search_bar/limit_options.tsx | 2 +- .../metrics/hosts/hooks/use_host_count.ts | 12 ++++++++++ .../metrics/hosts/hooks/use_hosts_table.tsx | 4 ++-- .../hosts/hooks/use_hosts_table_url_state.ts | 2 +- .../metrics/hosts/hooks/use_unified_search.ts | 3 ++- .../telemetry/telemetry_client.mock.ts | 1 + .../services/telemetry/telemetry_client.ts | 10 +++++++++ .../services/telemetry/telemetry_events.ts | 22 +++++++++++++++++++ .../telemetry/telemetry_service.test.ts | 22 +++++++++++++++++++ .../infra/public/services/telemetry/types.ts | 14 +++++++++++- 14 files changed, 91 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts b/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts index 85822bae819eb..8b29fd3562cb2 100644 --- a/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts +++ b/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @@ -24,6 +24,7 @@ const configSchema = schema.object({ 'Host Entry Clicked', // Worst-case scenario once per second - AT RISK, 'Host Flyout Filter Removed', // Worst-case scenario once per second - AT RISK, 'Host Flyout Filter Added', // Worst-case scenario once per second - AT RISK, + 'Host View Total Host Count Retrieved', // Worst-case scenario 1 every 2 seconds ], }), }); diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx index 14a617682bf25..bcffad2a67a32 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx @@ -20,7 +20,7 @@ const HOSTS_CHART: Omit = { toolTip: i18n.translate('xpack.infra.hostsViewPage.metricTrend.hostCount.tooltip', { defaultMessage: 'The number of hosts returned by your current search criteria.', }), - ['data-test-subj']: 'hostsView-metricsTrend-hosts', + ['data-test-subj']: 'hostsViewKPIGridHostsCountTile', }; export const HostsTile = () => { diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/kpi_grid.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/kpi_grid.tsx index c3f751d26befb..15c25b79854f9 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/kpi_grid.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/kpi_grid.tsx @@ -70,7 +70,7 @@ export const KPIGrid = () => { direction="row" gutterSize="s" style={{ flexGrow: 0 }} - data-test-subj="hostsView-metricsTrend" + data-test-subj="hostsViewKPIGrid" > diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx index 89eebeefd240e..842dc94198df3 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx @@ -119,7 +119,7 @@ export const Tile = ({ hasShadow={false} paddingSize={error ? 'm' : 'none'} style={{ minHeight: MIN_HEIGHT }} - data-test-subj={`hostsView-metricsTrend-${type}`} + data-test-subj={`hostsViewKPIGrid${type}Tile`} > {error ? ( id: buildId(option), label: `${option}`, value: option, - 'data-test-subj': `hostsViewLimitSelection${option}button`, + 'data-test-subj': `hostsViewLimitSelection${option}Button`, })); diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_count.ts b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_count.ts index 5575c46e621f1..c5e1f7df63453 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_count.ts +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_count.ts @@ -11,6 +11,7 @@ import { useCallback, useEffect } from 'react'; import { catchError, map, Observable, of, startWith } from 'rxjs'; import createContainer from 'constate'; import type { QueryDslQueryContainer, SearchResponse } from '@elastic/elasticsearch/lib/api/types'; +import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana'; import { decodeOrThrow } from '../../../../../common/runtime_types'; import { useDataSearch, useLatestPartialDataSearchResponse } from '../../../../utils/data_search'; import { useMetricsDataViewContext } from './use_data_view'; @@ -18,6 +19,9 @@ import { useUnifiedSearchContext } from './use_unified_search'; export const useHostCount = () => { const { dataView, metricAlias } = useMetricsDataViewContext(); + const { + services: { telemetry }, + } = useKibanaContextForPlugin(); const { buildQuery, getParsedDateRange } = useUnifiedSearchContext(); const { search: fetchHostCount, requests$ } = useDataSearch({ @@ -81,6 +85,14 @@ export const useHostCount = () => { fetchHostCount(); }, [fetchHostCount]); + useEffect(() => { + if (latestResponseData) { + telemetry.reportHostsViewTotalHostCountRetrieved({ + total: latestResponseData.count.value, + }); + } + }, [latestResponseData, telemetry]); + return { errors: latestResponseErrors, isRequestRunning, diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table.tsx index 7350f402c57ec..6fb206880cf44 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table.tsx @@ -21,7 +21,7 @@ import { InfraAssetMetricType, } from '../../../../../common/http_api'; import { useHostFlyoutOpen } from './use_host_flyout_open_url_state'; -import { Sorting, useHostsTableProperties } from './use_hosts_table_url_state'; +import { Sorting, useHostsTableUrlState } from './use_hosts_table_url_state'; import { useHostsViewContext } from './use_hosts_view'; import { useUnifiedSearchContext } from './use_unified_search'; @@ -166,7 +166,7 @@ const toggleDialogActionLabel = i18n.translate( export const useHostsTable = () => { const { hostNodes } = useHostsViewContext(); const { searchCriteria } = useUnifiedSearchContext(); - const [{ pagination, sorting }, setProperties] = useHostsTableProperties(); + const [{ pagination, sorting }, setProperties] = useHostsTableUrlState(); const { services: { telemetry }, } = useKibanaContextForPlugin(); diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table_url_state.ts b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table_url_state.ts index b4889d62f5878..760ada008c8c0 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table_url_state.ts +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_hosts_table_url_state.ts @@ -37,7 +37,7 @@ const reducer = (prevState: TableProperties, params: Payload) => { }; }; -export const useHostsTableProperties = (): [TableProperties, TablePropertiesUpdater] => { +export const useHostsTableUrlState = (): [TableProperties, TablePropertiesUpdater] => { const [localStoragePageSize, setLocalStoragePageSize] = useLocalStorage( LOCAL_STORAGE_PAGE_SIZE_KEY, DEFAULT_PAGE_SIZE diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_unified_search.ts b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_unified_search.ts index e242f58054c6c..4261f630319f8 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_unified_search.ts +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_unified_search.ts @@ -25,13 +25,14 @@ import { const buildQuerySubmittedPayload = ( hostState: HostsState & { parsedDateRange: StringDateRangeTimestamp } ) => { - const { panelFilters, filters, parsedDateRange, query: queryObj } = hostState; + const { panelFilters, filters, parsedDateRange, query: queryObj, limit } = hostState; return { control_filters: panelFilters.map((filter) => JSON.stringify(filter)), filters: filters.map((filter) => JSON.stringify(filter)), interval: telemetryTimeRangeFormatter(parsedDateRange.to - parsedDateRange.from), query: queryObj.query, + limit, }; }; diff --git a/x-pack/plugins/infra/public/services/telemetry/telemetry_client.mock.ts b/x-pack/plugins/infra/public/services/telemetry/telemetry_client.mock.ts index 298424f5c9db6..3f913bd8d5611 100644 --- a/x-pack/plugins/infra/public/services/telemetry/telemetry_client.mock.ts +++ b/x-pack/plugins/infra/public/services/telemetry/telemetry_client.mock.ts @@ -12,4 +12,5 @@ export const createTelemetryClientMock = (): jest.Mocked => ({ reportHostsViewQuerySubmitted: jest.fn(), reportHostFlyoutFilterRemoved: jest.fn(), reportHostFlyoutFilterAdded: jest.fn(), + reportHostsViewTotalHostCountRetrieved: jest.fn(), }); diff --git a/x-pack/plugins/infra/public/services/telemetry/telemetry_client.ts b/x-pack/plugins/infra/public/services/telemetry/telemetry_client.ts index f53a6b298de1d..56eb8d1af2c77 100644 --- a/x-pack/plugins/infra/public/services/telemetry/telemetry_client.ts +++ b/x-pack/plugins/infra/public/services/telemetry/telemetry_client.ts @@ -9,6 +9,7 @@ import { AnalyticsServiceSetup } from '@kbn/core-analytics-server'; import { HostEntryClickedParams, HostFlyoutFilterActionParams, + HostsViewQueryHostsCountRetrievedParams, HostsViewQuerySubmittedParams, InfraTelemetryEventTypes, ITelemetryClient, @@ -50,4 +51,13 @@ export class TelemetryClient implements ITelemetryClient { public reportHostsViewQuerySubmitted = (params: HostsViewQuerySubmittedParams) => { this.analytics.reportEvent(InfraTelemetryEventTypes.HOSTS_VIEW_QUERY_SUBMITTED, params); }; + + public reportHostsViewTotalHostCountRetrieved( + params: HostsViewQueryHostsCountRetrievedParams + ): void { + this.analytics.reportEvent( + InfraTelemetryEventTypes.HOST_VIEW_TOTAL_HOST_COUNT_RETRIEVED, + params + ); + } } diff --git a/x-pack/plugins/infra/public/services/telemetry/telemetry_events.ts b/x-pack/plugins/infra/public/services/telemetry/telemetry_events.ts index 597c9c56eacfd..e81ddb5416fa6 100644 --- a/x-pack/plugins/infra/public/services/telemetry/telemetry_events.ts +++ b/x-pack/plugins/infra/public/services/telemetry/telemetry_events.ts @@ -43,6 +43,13 @@ const hostsViewQuerySubmittedEvent: InfraTelemetryEvent = { optional: false, }, }, + limit: { + type: 'integer', + _meta: { + description: 'Selected host limit', + optional: false, + }, + }, }, }; @@ -78,6 +85,7 @@ const hostFlyoutRemoveFilter: InfraTelemetryEvent = { }, }, }; + const hostFlyoutAddFilter: InfraTelemetryEvent = { eventType: InfraTelemetryEventTypes.HOST_FLYOUT_FILTER_ADDED, schema: { @@ -91,9 +99,23 @@ const hostFlyoutAddFilter: InfraTelemetryEvent = { }, }; +const hostViewTotalHostCountRetrieved: InfraTelemetryEvent = { + eventType: InfraTelemetryEventTypes.HOST_VIEW_TOTAL_HOST_COUNT_RETRIEVED, + schema: { + total: { + type: 'integer', + _meta: { + description: 'Total number of hosts retrieved.', + optional: false, + }, + }, + }, +}; + export const infraTelemetryEvents = [ hostsViewQuerySubmittedEvent, hostsEntryClickedEvent, hostFlyoutRemoveFilter, hostFlyoutAddFilter, + hostViewTotalHostCountRetrieved, ]; diff --git a/x-pack/plugins/infra/public/services/telemetry/telemetry_service.test.ts b/x-pack/plugins/infra/public/services/telemetry/telemetry_service.test.ts index 6fdd2105ec2df..e783180e828f9 100644 --- a/x-pack/plugins/infra/public/services/telemetry/telemetry_service.test.ts +++ b/x-pack/plugins/infra/public/services/telemetry/telemetry_service.test.ts @@ -107,6 +107,7 @@ describe('TelemetryService', () => { filters: [], interval: 'interval(now-1h)', query: '', + limit: 100, }); expect(setupParams.analytics.reportEvent).toHaveBeenCalledTimes(1); @@ -117,6 +118,7 @@ describe('TelemetryService', () => { filters: [], interval: 'interval(now-1h)', query: '', + limit: 100, } ); }); @@ -161,4 +163,24 @@ describe('TelemetryService', () => { ); }); }); + + describe('#reportHostsViewTotalHostCountRetrieved', () => { + it('should report Host Flyout Filter Added click with field name', async () => { + const setupParams = getSetupParams(); + service.setup(setupParams); + const telemetry = service.start(); + + telemetry.reportHostsViewTotalHostCountRetrieved({ + total: 300, + }); + + expect(setupParams.analytics.reportEvent).toHaveBeenCalledTimes(1); + expect(setupParams.analytics.reportEvent).toHaveBeenCalledWith( + InfraTelemetryEventTypes.HOST_VIEW_TOTAL_HOST_COUNT_RETRIEVED, + { + total: 300, + } + ); + }); + }); }); diff --git a/x-pack/plugins/infra/public/services/telemetry/types.ts b/x-pack/plugins/infra/public/services/telemetry/types.ts index f0f64ff00c918..4ad2a794643bd 100644 --- a/x-pack/plugins/infra/public/services/telemetry/types.ts +++ b/x-pack/plugins/infra/public/services/telemetry/types.ts @@ -17,6 +17,7 @@ export enum InfraTelemetryEventTypes { HOSTS_ENTRY_CLICKED = 'Host Entry Clicked', HOST_FLYOUT_FILTER_REMOVED = 'Host Flyout Filter Removed', HOST_FLYOUT_FILTER_ADDED = 'Host Flyout Filter Added', + HOST_VIEW_TOTAL_HOST_COUNT_RETRIEVED = 'Host View Total Host Count Retrieved', } export interface HostsViewQuerySubmittedParams { @@ -24,6 +25,7 @@ export interface HostsViewQuerySubmittedParams { filters: string[]; interval: string; query: string | { [key: string]: any }; + limit: number; } export interface HostEntryClickedParams { @@ -35,15 +37,21 @@ export interface HostFlyoutFilterActionParams { field_name: string; } +export interface HostsViewQueryHostsCountRetrievedParams { + total: number; +} + export type InfraTelemetryEventParams = | HostsViewQuerySubmittedParams | HostEntryClickedParams - | HostFlyoutFilterActionParams; + | HostFlyoutFilterActionParams + | HostsViewQueryHostsCountRetrievedParams; export interface ITelemetryClient { reportHostEntryClicked(params: HostEntryClickedParams): void; reportHostFlyoutFilterRemoved(params: HostFlyoutFilterActionParams): void; reportHostFlyoutFilterAdded(params: HostFlyoutFilterActionParams): void; + reportHostsViewTotalHostCountRetrieved(params: HostsViewQueryHostsCountRetrievedParams): void; reportHostsViewQuerySubmitted(params: HostsViewQuerySubmittedParams): void; } @@ -63,4 +71,8 @@ export type InfraTelemetryEvent = | { eventType: InfraTelemetryEventTypes.HOSTS_ENTRY_CLICKED; schema: RootSchema; + } + | { + eventType: InfraTelemetryEventTypes.HOST_VIEW_TOTAL_HOST_COUNT_RETRIEVED; + schema: RootSchema; }; From 0c05d029fc500999b2cbb5f3f3a0c9bac3deec68 Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Tue, 25 Apr 2023 16:36:58 -0300 Subject: [PATCH 2/4] Fix data-test-subj --- .../pages/metrics/hosts/components/kpis/hosts_tile.tsx | 2 +- .../public/pages/metrics/hosts/components/kpis/tile.tsx | 2 +- x-pack/test/functional/page_objects/infra_hosts_view.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx index bcffad2a67a32..64839fa222573 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/hosts_tile.tsx @@ -20,7 +20,7 @@ const HOSTS_CHART: Omit = { toolTip: i18n.translate('xpack.infra.hostsViewPage.metricTrend.hostCount.tooltip', { defaultMessage: 'The number of hosts returned by your current search criteria.', }), - ['data-test-subj']: 'hostsViewKPIGridHostsCountTile', + ['data-test-subj']: 'hostsViewKPI-hostsCount', }; export const HostsTile = () => { diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx index 842dc94198df3..2028f6265159e 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/kpis/tile.tsx @@ -119,7 +119,7 @@ export const Tile = ({ hasShadow={false} paddingSize={error ? 'm' : 'none'} style={{ minHeight: MIN_HEIGHT }} - data-test-subj={`hostsViewKPIGrid${type}Tile`} + data-test-subj={`hostsViewKPI-${type}`} > {error ? ( Date: Tue, 9 May 2023 14:23:18 -0300 Subject: [PATCH 3/4] Fix test --- x-pack/test/functional/apps/infra/hosts_view.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/infra/hosts_view.ts b/x-pack/test/functional/apps/infra/hosts_view.ts index a0b11335d9768..a906f916e504d 100644 --- a/x-pack/test/functional/apps/infra/hosts_view.ts +++ b/x-pack/test/functional/apps/infra/hosts_view.ts @@ -371,7 +371,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); [ - { metric: 'hosts', value: '6' }, + { metric: 'hostsCount', value: '6' }, { metric: 'cpu', value: '0.8%' }, { metric: 'memory', value: '16.81%' }, { metric: 'tx', value: 'N/A' }, @@ -510,7 +510,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { it('should update the KPIs content on a search submit', async () => { await Promise.all( [ - { metric: 'hosts', value: '3' }, + { metric: 'hostsCount', value: '3' }, { metric: 'cpu', value: '0.8%' }, { metric: 'memory', value: '16.25%' }, { metric: 'tx', value: 'N/A' }, From 2023f4c5943410bf219383bbc2ad00254efb0b76 Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Thu, 11 May 2023 10:15:30 -0300 Subject: [PATCH 4/4] Removing host limit custom event from FS allow list --- .../cloud_integrations/cloud_full_story/server/config.ts | 1 - x-pack/test/functional/page_objects/infra_hosts_view.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts b/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts index 8b29fd3562cb2..85822bae819eb 100644 --- a/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts +++ b/x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @@ -24,7 +24,6 @@ const configSchema = schema.object({ 'Host Entry Clicked', // Worst-case scenario once per second - AT RISK, 'Host Flyout Filter Removed', // Worst-case scenario once per second - AT RISK, 'Host Flyout Filter Added', // Worst-case scenario once per second - AT RISK, - 'Host View Total Host Count Retrieved', // Worst-case scenario 1 every 2 seconds ], }), }); diff --git a/x-pack/test/functional/page_objects/infra_hosts_view.ts b/x-pack/test/functional/page_objects/infra_hosts_view.ts index bc4bee62e9b26..1d90013f77c2c 100644 --- a/x-pack/test/functional/page_objects/infra_hosts_view.ts +++ b/x-pack/test/functional/page_objects/infra_hosts_view.ts @@ -118,7 +118,7 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) { async visitMetricsTab() { const metricsTab = await this.getMetricsTab(); - metricsTab.click(); + return metricsTab.click(); }, async getAllMetricsCharts() {