From 9ddf7f9b8ddee52a179060151ca7874de3ec1d23 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Sun, 26 Jan 2020 21:00:46 -0500 Subject: [PATCH 1/6] Fixes APM trackEvent usage in NP context --- .../AgentConfigurations/AddEditFlyout/index.tsx | 7 ++++++- .../AgentConfigurations/AddEditFlyout/saveConfig.ts | 8 +++++--- .../plugins/infra/public/hooks/use_track_metric.tsx | 12 ++++++++++-- x-pack/plugins/infra/public/index.ts | 8 +++++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx index e1cb07be3d378..cdad10ac31efe 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx @@ -34,6 +34,7 @@ import { isRumAgentName } from '../../../../../../common/agent_name'; import { ALL_OPTION_VALUE } from '../../../../../../common/agent_configuration_constants'; import { saveConfig } from './saveConfig'; import { useApmPluginContext } from '../../../../../hooks/useApmPluginContext'; +import { useUiTracker } from '../../../../../../../../../plugins/infra/public'; const defaultSettings = { TRANSACTION_SAMPLE_RATE: '1.0', @@ -59,6 +60,9 @@ export function AddEditFlyout({ const callApmApiFromHook = useCallApmApi(); + // get a telemetry UI event tracker + const trackApmEvent = useUiTracker({ app: 'apm' }); + // config conditions (service) const [serviceName, setServiceName] = useState( selectedConfig ? selectedConfig.service.name || ALL_OPTION_VALUE : '' @@ -133,7 +137,8 @@ export function AddEditFlyout({ transactionMaxSpans, configurationId: selectedConfig ? selectedConfig.id : undefined, agentName, - toasts + toasts, + trackApmEvent }); setIsSaving(false); onSaved(); diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts index 7653080cacf8c..bd4dd933b4637 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts @@ -12,6 +12,7 @@ import { getOptionLabel, omitAllOption } from '../../../../../../common/agent_configuration_constants'; +import { UiTracker } from '../../../../../../../../../plugins/infra/public'; interface Settings { transaction_sample_rate: number; @@ -28,7 +29,8 @@ export async function saveConfig({ transactionMaxSpans, configurationId, agentName, - toasts + toasts, + trackEvent }: { callApmApi: APMClient; serviceName: string; @@ -39,9 +41,9 @@ export async function saveConfig({ configurationId?: string; agentName?: string; toasts: NotificationsStart['toasts']; + trackEvent: UiTracker; }) { - // TODO: Migrate to useTrackMetric - // trackEvent({ app: 'apm', name: 'save_agent_configuration' }); + trackEvent({ metric: 'save_agent_configuration' }); try { const settings: Settings = { diff --git a/x-pack/plugins/infra/public/hooks/use_track_metric.tsx b/x-pack/plugins/infra/public/hooks/use_track_metric.tsx index b38493bd462dc..51c9f59d22fea 100644 --- a/x-pack/plugins/infra/public/hooks/use_track_metric.tsx +++ b/x-pack/plugins/infra/public/hooks/use_track_metric.tsx @@ -22,16 +22,24 @@ import { useKibana } from '../../../../../src/plugins/kibana_react/public'; type ObservabilityApp = 'infra_metrics' | 'infra_logs' | 'apm' | 'uptime'; interface TrackOptions { - app: ObservabilityApp; + app?: ObservabilityApp; metricType?: UiStatsMetricType; delay?: number; // in ms } type EffectDeps = unknown[]; -type TrackMetricOptions = TrackOptions & { metric: string }; +export type TrackMetricOptions = TrackOptions & { metric: string }; +export type UiTracker = ReturnType; export { METRIC_TYPE }; +export function useUiTracker({ app: defaultApp }: { app?: ObservabilityApp } = {}) { + const { reportUiStats } = useKibana().services?.usageCollection; + return ({ app = defaultApp, metric, metricType = METRIC_TYPE.COUNT }: TrackMetricOptions) => { + reportUiStats(app, metricType, metric); + }; +} + export function useTrackMetric( { app, metric, metricType = METRIC_TYPE.COUNT, delay = 0 }: TrackMetricOptions, effectDependencies: EffectDeps = [] diff --git a/x-pack/plugins/infra/public/index.ts b/x-pack/plugins/infra/public/index.ts index 9e3c47c4a9a3e..ce2defc6af68f 100644 --- a/x-pack/plugins/infra/public/index.ts +++ b/x-pack/plugins/infra/public/index.ts @@ -16,6 +16,12 @@ export const plugin: PluginInitializer< return new Plugin(context); }; -export { useTrackPageview } from './hooks/use_track_metric'; +export { + useTrackPageview, + useUiTracker, + UiTracker, + TrackMetricOptions, + METRIC_TYPE, +} from './hooks/use_track_metric'; export { FORMATTERS } from './utils/formatters'; export { InfraFormatterType } from './lib/lib'; From 87ef535af017d4859e59b272421edb09f2698d5e Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 27 Jan 2020 14:24:24 -0500 Subject: [PATCH 2/6] Converts the rest of the APM uses of trackEvent --- .../TransactionBreakdownGraph/index.tsx | 10 +++++----- .../components/shared/TransactionBreakdown/index.tsx | 11 ++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx index 970a4ba52321a..fe71f8e2f77b4 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx @@ -14,6 +14,7 @@ import { TransactionLineChart } from '../../charts/TransactionCharts/Transaction import { asPercent } from '../../../../utils/formatters'; import { unit } from '../../../../style/variables'; import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue'; +import { useUiTracker } from '../../../../../../../../plugins/infra/public'; interface Props { timeseries: TimeSeries[]; @@ -29,13 +30,12 @@ const formatTooltipValue = (coordinate: Coordinate) => { : NOT_AVAILABLE_LABEL; }; -const trackHoverBreakdownChart = throttle(() => { - // TODO: Migrate to useTrackMetric - // trackEvent({ app: 'apm', name: 'hover_breakdown_chart' }) -}, 60000); - const TransactionBreakdownGraph: React.FC = props => { const { timeseries } = props; + const trackApmEvent = useUiTracker({ app: 'apm' }); + const trackHoverBreakdownChart = throttle(() => { + trackApmEvent({ metric: 'hover_breakdown_chart' }); + }, 60000); return ( = ({ initialIsOpen }) => { const [showChart, setShowChart] = useState(!!initialIsOpen); - const { data, status } = useTransactionBreakdown(); - + const trackApmEvent = useUiTracker({ app: 'apm' }); const { kpis, timeseries } = data; - const noHits = data.kpis.length === 0 && status === FETCH_STATUS.SUCCESS; const showEmptyMessage = noHits && !showChart; @@ -37,11 +36,9 @@ const TransactionBreakdown: React.FC<{ onToggleClick={() => { setShowChart(!showChart); if (showChart) { - // TODO: Migrate to useTrackMetric - // trackEvent({ app: 'apm', name: 'hide_breakdown_chart' }); + trackApmEvent({ metric: 'hide_breakdown_chart' }); } else { - // TODO: Migrate to useTrackMetric - // trackEvent({ app: 'apm', name: 'show_breakdown_chart' }); + trackApmEvent({ metric: 'show_breakdown_chart' }); } }} /> From 3493e550c96ab29b911594ec97b2f221a23a258b Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 27 Jan 2020 14:43:07 -0500 Subject: [PATCH 3/6] Moves track metric telemetry hooks etc to shared observability plugin --- .../components/app/ErrorGroupDetails/index.tsx | 2 +- .../components/app/ErrorGroupOverview/index.tsx | 2 +- .../public/components/app/ServiceOverview/index.tsx | 2 +- .../AgentConfigurations/AddEditFlyout/index.tsx | 2 +- .../AgentConfigurations/AddEditFlyout/saveConfig.ts | 2 +- .../app/Settings/AgentConfigurations/index.tsx | 2 +- .../public/components/app/TraceOverview/index.tsx | 2 +- .../components/app/TransactionDetails/index.tsx | 2 +- .../components/app/TransactionOverview/index.tsx | 2 +- .../TransactionBreakdownGraph/index.tsx | 2 +- .../TransactionBreakdownKpiList.tsx | 6 ++++-- .../shared/TransactionBreakdown/index.tsx | 2 +- .../legacy/plugins/uptime/public/pages/monitor.tsx | 2 +- .../legacy/plugins/uptime/public/pages/overview.tsx | 2 +- x-pack/plugins/infra/public/index.ts | 7 ------- .../pages/infrastructure/metrics_explorer/index.tsx | 2 +- .../public/pages/infrastructure/snapshot/index.tsx | 2 +- .../log_entry_categories/page_results_content.tsx | 2 +- .../log_entry_categories/page_setup_content.tsx | 2 +- .../logs/log_entry_rate/page_results_content.tsx | 2 +- .../logs/log_entry_rate/page_setup_content.tsx | 2 +- .../plugins/infra/public/pages/logs/stream/page.tsx | 2 +- .../public/hooks/use_track_metric.tsx | 0 x-pack/plugins/observability/public/index.ts | 13 +++++++++++++ 24 files changed, 37 insertions(+), 29 deletions(-) rename x-pack/plugins/{infra => observability}/public/hooks/use_track_metric.tsx (100%) create mode 100644 x-pack/plugins/observability/public/index.ts diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx index 8647bdd098274..d79f2a4ed481d 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx @@ -25,7 +25,7 @@ import { DetailView } from './DetailView'; import { ErrorDistribution } from './Distribution'; import { useLocation } from '../../../hooks/useLocation'; import { useUrlParams } from '../../../hooks/useUrlParams'; -import { useTrackPageview } from '../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../plugins/observability/public'; const Titles = styled.div` margin-bottom: ${px(units.plus)}; diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupOverview/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupOverview/index.tsx index a855747f8c1bc..ecf5aaa112746 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupOverview/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupOverview/index.tsx @@ -17,7 +17,7 @@ import { useFetcher } from '../../../hooks/useFetcher'; import { ErrorDistribution } from '../ErrorGroupDetails/Distribution'; import { ErrorGroupList } from './List'; import { useUrlParams } from '../../../hooks/useUrlParams'; -import { useTrackPageview } from '../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../plugins/observability/public'; import { PROJECTION } from '../../../../common/projections/typings'; import { LocalUIFilters } from '../../shared/LocalUIFilters'; diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx index 6fabdfc9d240b..fa157bf37eaf7 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx @@ -14,7 +14,7 @@ import { useFetcher } from '../../../hooks/useFetcher'; import { NoServicesMessage } from './NoServicesMessage'; import { ServiceList } from './ServiceList'; import { useUrlParams } from '../../../hooks/useUrlParams'; -import { useTrackPageview } from '../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../plugins/observability/public'; import { PROJECTION } from '../../../../common/projections/typings'; import { LocalUIFilters } from '../../shared/LocalUIFilters'; import { useApmPluginContext } from '../../../hooks/useApmPluginContext'; diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx index cdad10ac31efe..b58d0b28e6d24 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx @@ -34,7 +34,7 @@ import { isRumAgentName } from '../../../../../../common/agent_name'; import { ALL_OPTION_VALUE } from '../../../../../../common/agent_configuration_constants'; import { saveConfig } from './saveConfig'; import { useApmPluginContext } from '../../../../../hooks/useApmPluginContext'; -import { useUiTracker } from '../../../../../../../../../plugins/infra/public'; +import { useUiTracker } from '../../../../../../../../../plugins/observability/public'; const defaultSettings = { TRANSACTION_SAMPLE_RATE: '1.0', diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts index bd4dd933b4637..e20acdd80276a 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts @@ -12,7 +12,7 @@ import { getOptionLabel, omitAllOption } from '../../../../../../common/agent_configuration_constants'; -import { UiTracker } from '../../../../../../../../../plugins/infra/public'; +import { UiTracker } from '../../../../../../../../../plugins/observability/public'; interface Settings { transaction_sample_rate: number; diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/index.tsx index a03640dced163..8812cccd2edaf 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/index.tsx @@ -18,7 +18,7 @@ import { isEmpty } from 'lodash'; import { useFetcher } from '../../../../hooks/useFetcher'; import { AgentConfigurationListAPIResponse } from '../../../../../server/lib/settings/agent_configuration/list_configurations'; import { AgentConfigurationList } from './AgentConfigurationList'; -import { useTrackPageview } from '../../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../../plugins/observability/public'; import { AddEditFlyout } from './AddEditFlyout'; export type Config = AgentConfigurationListAPIResponse[0]; diff --git a/x-pack/legacy/plugins/apm/public/components/app/TraceOverview/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/TraceOverview/index.tsx index 86b57d21c3a6a..8239e5400793d 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TraceOverview/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/TraceOverview/index.tsx @@ -9,7 +9,7 @@ import React, { useMemo } from 'react'; import { FETCH_STATUS, useFetcher } from '../../../hooks/useFetcher'; import { TraceList } from './TraceList'; import { useUrlParams } from '../../../hooks/useUrlParams'; -import { useTrackPageview } from '../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../plugins/observability/public'; import { LocalUIFilters } from '../../shared/LocalUIFilters'; import { PROJECTION } from '../../../../common/projections/typings'; diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/index.tsx index 37099f112f286..a6712becf7968 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/index.tsx @@ -26,7 +26,7 @@ import { useUrlParams } from '../../../hooks/useUrlParams'; import { FETCH_STATUS } from '../../../hooks/useFetcher'; import { TransactionBreakdown } from '../../shared/TransactionBreakdown'; import { ChartsSyncContextProvider } from '../../../context/ChartsSyncContext'; -import { useTrackPageview } from '../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../plugins/observability/public'; import { PROJECTION } from '../../../../common/projections/typings'; import { LocalUIFilters } from '../../shared/LocalUIFilters'; import { HeightRetainer } from '../../shared/HeightRetainer'; diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionOverview/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/TransactionOverview/index.tsx index 0b0fb1f1e46ab..b8b56c640ee2b 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionOverview/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionOverview/index.tsx @@ -27,7 +27,7 @@ import { getHasMLJob } from '../../../services/rest/ml'; import { history } from '../../../utils/history'; import { useLocation } from '../../../hooks/useLocation'; import { ChartsSyncContextProvider } from '../../../context/ChartsSyncContext'; -import { useTrackPageview } from '../../../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../../../plugins/observability/public'; import { fromQuery, toQuery } from '../../shared/Links/url_helpers'; import { LocalUIFilters } from '../../shared/LocalUIFilters'; import { PROJECTION } from '../../../../common/projections/typings'; diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx index fe71f8e2f77b4..b428bbad0cbef 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx @@ -14,7 +14,7 @@ import { TransactionLineChart } from '../../charts/TransactionCharts/Transaction import { asPercent } from '../../../../utils/formatters'; import { unit } from '../../../../style/variables'; import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue'; -import { useUiTracker } from '../../../../../../../../plugins/infra/public'; +import { useUiTracker } from '../../../../../../../../plugins/observability/public'; interface Props { timeseries: TimeSeries[]; diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx index 3246a78aa05f6..91f5f4e0a7176 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx @@ -13,8 +13,10 @@ import { EuiIcon } from '@elastic/eui'; import styled from 'styled-components'; -import { InfraFormatterType } from '../../../../../../../plugins/infra/public'; -import { FORMATTERS } from '../../../../../../../plugins/infra/public'; +import { + FORMATTERS, + InfraFormatterType +} from '../../../../../../../plugins/infra/public'; interface TransactionBreakdownKpi { name: string; diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/index.tsx index 5c366941ec65e..85f5f83fb920e 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionBreakdown/index.tsx @@ -11,7 +11,7 @@ import { TransactionBreakdownHeader } from './TransactionBreakdownHeader'; import { TransactionBreakdownKpiList } from './TransactionBreakdownKpiList'; import { TransactionBreakdownGraph } from './TransactionBreakdownGraph'; import { FETCH_STATUS } from '../../../hooks/useFetcher'; -import { useUiTracker } from '../../../../../../../plugins/infra/public'; +import { useUiTracker } from '../../../../../../../plugins/observability/public'; const emptyMessage = i18n.translate('xpack.apm.transactionBreakdown.noData', { defaultMessage: 'No data within this time range.' diff --git a/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx b/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx index 6af65255993e3..a5fce3fcf6f27 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx @@ -11,7 +11,7 @@ import { MonitorCharts, PingList } from '../components/functional'; import { UMUpdateBreadcrumbs } from '../lib/lib'; import { UptimeRefreshContext, UptimeThemeContext } from '../contexts'; import { useUptimeTelemetry, useUrlParams, UptimePage } from '../hooks'; -import { useTrackPageview } from '../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../plugins/observability/public'; import { MonitorStatusDetails } from '../components/functional/monitor_status_details'; import { PageHeader } from './page_header'; diff --git a/x-pack/legacy/plugins/uptime/public/pages/overview.tsx b/x-pack/legacy/plugins/uptime/public/pages/overview.tsx index 7bde8521db4cf..d511ab477766a 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/overview.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/overview.tsx @@ -18,7 +18,7 @@ import { import { UMUpdateBreadcrumbs } from '../lib/lib'; import { useIndexPattern, useUrlParams, useUptimeTelemetry, UptimePage } from '../hooks'; import { stringifyUrlParams } from '../lib/helper/stringify_url_params'; -import { useTrackPageview } from '../../../../../plugins/infra/public'; +import { useTrackPageview } from '../../../../../plugins/observability/public'; import { combineFiltersAndUserSearch, stringifyKueries, toStaticIndexPattern } from '../lib/helper'; import { store } from '../state'; import { setEsKueryString } from '../state/actions'; diff --git a/x-pack/plugins/infra/public/index.ts b/x-pack/plugins/infra/public/index.ts index ce2defc6af68f..13f2583ec96f2 100644 --- a/x-pack/plugins/infra/public/index.ts +++ b/x-pack/plugins/infra/public/index.ts @@ -16,12 +16,5 @@ export const plugin: PluginInitializer< return new Plugin(context); }; -export { - useTrackPageview, - useUiTracker, - UiTracker, - TrackMetricOptions, - METRIC_TYPE, -} from './hooks/use_track_metric'; export { FORMATTERS } from './utils/formatters'; export { InfraFormatterType } from './lib/lib'; diff --git a/x-pack/plugins/infra/public/pages/infrastructure/metrics_explorer/index.tsx b/x-pack/plugins/infra/public/pages/infrastructure/metrics_explorer/index.tsx index 4db4319b91d3c..0999cea59731c 100644 --- a/x-pack/plugins/infra/public/pages/infrastructure/metrics_explorer/index.tsx +++ b/x-pack/plugins/infra/public/pages/infrastructure/metrics_explorer/index.tsx @@ -14,7 +14,7 @@ import { MetricsExplorerToolbar } from '../../../components/metrics_explorer/too import { SourceQuery } from '../../../../common/graphql/types'; import { NoData } from '../../../components/empty_states'; import { useMetricsExplorerState } from './use_metric_explorer_state'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; interface MetricsExplorerPageProps { source: SourceQuery.Query['source']['configuration']; diff --git a/x-pack/plugins/infra/public/pages/infrastructure/snapshot/index.tsx b/x-pack/plugins/infra/public/pages/infrastructure/snapshot/index.tsx index ad2e95fec7e75..7f3be965af8db 100644 --- a/x-pack/plugins/infra/public/pages/infrastructure/snapshot/index.tsx +++ b/x-pack/plugins/infra/public/pages/infrastructure/snapshot/index.tsx @@ -26,7 +26,7 @@ import { Source } from '../../../containers/source'; import { WithWaffleFilterUrlState } from '../../../containers/waffle/with_waffle_filters'; import { WithWaffleOptionsUrlState } from '../../../containers/waffle/with_waffle_options'; import { WithWaffleTimeUrlState } from '../../../containers/waffle/with_waffle_time'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'; export const SnapshotPage = () => { diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx index 1027fa3352f08..6cda252377f04 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx @@ -19,7 +19,7 @@ import { } from '../../../components/logging/log_analysis_job_status'; import { FirstUseCallout } from '../../../components/logging/log_analysis_results'; import { useInterval } from '../../../hooks/use_interval'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; import { TopCategoriesSection } from './sections/top_categories'; import { useLogEntryCategoriesModuleContext } from './use_log_entry_categories_module'; import { useLogEntryCategoriesResults } from './use_log_entry_categories_results'; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx index ac902029f938e..a7ff98923a427 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx @@ -16,7 +16,7 @@ import { LogAnalysisSetupPageContent, LogAnalysisSetupPageHeader, } from '../../../components/logging/log_analysis_setup'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; import { useLogEntryCategoriesSetup } from './use_log_entry_categories_setup'; export const LogEntryCategoriesSetupContent: React.FunctionComponent = () => { diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx index e66116a3f1854..ac823e4815885 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx @@ -25,7 +25,7 @@ import { TimeRange } from '../../../../common/http_api/shared/time_range'; import { bucketSpan } from '../../../../common/log_analysis'; import { LoadingOverlayWrapper } from '../../../components/loading_overlay_wrapper'; import { useInterval } from '../../../hooks/use_interval'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; import { useKibanaUiSetting } from '../../../utils/use_kibana_ui_setting'; import { AnomaliesResults } from './sections/anomalies'; import { LogRateResults } from './sections/log_rate'; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_setup_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_setup_content.tsx index 13574f589a111..a02dbfa941588 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_setup_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_setup_content.tsx @@ -16,7 +16,7 @@ import { LogAnalysisSetupPageContent, LogAnalysisSetupPageHeader, } from '../../../components/logging/log_analysis_setup'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; import { useLogEntryRateSetup } from './use_log_entry_rate_setup'; export const LogEntryRateSetupContent: React.FunctionComponent = () => { diff --git a/x-pack/plugins/infra/public/pages/logs/stream/page.tsx b/x-pack/plugins/infra/public/pages/logs/stream/page.tsx index 9031a8cb4785d..3e07dcebf112d 100644 --- a/x-pack/plugins/infra/public/pages/logs/stream/page.tsx +++ b/x-pack/plugins/infra/public/pages/logs/stream/page.tsx @@ -10,7 +10,7 @@ import { ColumnarPage } from '../../../components/page'; import { StreamPageContent } from './page_content'; import { StreamPageHeader } from './page_header'; import { LogsPageProviders } from './page_providers'; -import { useTrackPageview } from '../../../hooks/use_track_metric'; +import { useTrackPageview } from '../../../../../observability/public'; export const StreamPage = () => { useTrackPageview({ app: 'infra_logs', path: 'stream' }); diff --git a/x-pack/plugins/infra/public/hooks/use_track_metric.tsx b/x-pack/plugins/observability/public/hooks/use_track_metric.tsx similarity index 100% rename from x-pack/plugins/infra/public/hooks/use_track_metric.tsx rename to x-pack/plugins/observability/public/hooks/use_track_metric.tsx diff --git a/x-pack/plugins/observability/public/index.ts b/x-pack/plugins/observability/public/index.ts new file mode 100644 index 0000000000000..d1553037dce36 --- /dev/null +++ b/x-pack/plugins/observability/public/index.ts @@ -0,0 +1,13 @@ +/* + * 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 { + useTrackPageview, + useUiTracker, + UiTracker, + TrackMetricOptions, + METRIC_TYPE, +} from './hooks/use_track_metric'; From dfcaaa0bc21c1f6a1256ce8f5da69f4f2e1dcbe7 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 27 Jan 2020 15:15:15 -0500 Subject: [PATCH 4/6] Completes fleshing out basic observability NP plugin --- x-pack/plugins/observability/kibana.json | 6 ++++++ x-pack/plugins/observability/public/index.ts | 9 +++++++++ x-pack/plugins/observability/public/plugin.ts | 15 +++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 x-pack/plugins/observability/kibana.json create mode 100644 x-pack/plugins/observability/public/plugin.ts diff --git a/x-pack/plugins/observability/kibana.json b/x-pack/plugins/observability/kibana.json new file mode 100644 index 0000000000000..57063ea729ed6 --- /dev/null +++ b/x-pack/plugins/observability/kibana.json @@ -0,0 +1,6 @@ +{ + "id": "observability", + "version": "8.0.0", + "kibanaVersion": "kibana", + "ui": true +} diff --git a/x-pack/plugins/observability/public/index.ts b/x-pack/plugins/observability/public/index.ts index d1553037dce36..04ee3155888c2 100644 --- a/x-pack/plugins/observability/public/index.ts +++ b/x-pack/plugins/observability/public/index.ts @@ -4,6 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ +import { PluginInitializerContext, PluginInitializer } from 'kibana/public'; +import { Plugin, ClientSetup, ClientStart } from './plugin'; + +export const plugin: PluginInitializer = ( + context: PluginInitializerContext +) => { + return new Plugin(context); +}; + export { useTrackPageview, useUiTracker, diff --git a/x-pack/plugins/observability/public/plugin.ts b/x-pack/plugins/observability/public/plugin.ts new file mode 100644 index 0000000000000..a7eb1c50a0392 --- /dev/null +++ b/x-pack/plugins/observability/public/plugin.ts @@ -0,0 +1,15 @@ +/* + * 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 { Plugin as PluginClass, PluginInitializerContext } from 'kibana/public'; + +export type ClientSetup = void; +export type ClientStart = void; + +export class Plugin implements PluginClass { + constructor(context: PluginInitializerContext) {} + start() {} + setup() {} +} From ed870316bda1a79af93d2ad2cc5d69f8b7f5d3bf Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 27 Jan 2020 15:15:34 -0500 Subject: [PATCH 5/6] Wraps APM app in KibanaContextProvider --- .../apm/public/new-platform/plugin.tsx | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx b/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx index de6cbc7d7a335..474608ff1c06c 100644 --- a/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx +++ b/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx @@ -37,6 +37,7 @@ import { getConfigFromInjectedMetadata } from './getConfigFromInjectedMetadata'; import { setHelpExtension } from './setHelpExtension'; import { toggleAppLinkInNav } from './toggleAppLinkInNav'; import { setReadonlyBadge } from './updateBadge'; +import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; export const REACT_APP_ROOT_ID = 'react-apm-root'; @@ -131,21 +132,23 @@ export class ApmPlugin ReactDOM.render( - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + , document.getElementById(REACT_APP_ROOT_ID) ); From df4cccabf7dfc5067a8b0685d2e8c5a1ca9b2637 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 27 Jan 2020 15:33:18 -0500 Subject: [PATCH 6/6] Fixed name mismatch problem --- .../AgentConfigurations/AddEditFlyout/saveConfig.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts index e20acdd80276a..a0c7c97e012a4 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts @@ -30,7 +30,7 @@ export async function saveConfig({ configurationId, agentName, toasts, - trackEvent + trackApmEvent }: { callApmApi: APMClient; serviceName: string; @@ -41,9 +41,9 @@ export async function saveConfig({ configurationId?: string; agentName?: string; toasts: NotificationsStart['toasts']; - trackEvent: UiTracker; + trackApmEvent: UiTracker; }) { - trackEvent({ metric: 'save_agent_configuration' }); + trackApmEvent({ metric: 'save_agent_configuration' }); try { const settings: Settings = {