Skip to content

Commit

Permalink
[Fleet] Add telemetry for integration cards (#115413)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Oct 19, 2021
1 parent 44d0150 commit 7420cc2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 34 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"requiredPlugins": ["licensing", "data", "encryptedSavedObjects", "navigation", "customIntegrations", "share"],
"optionalPlugins": ["security", "features", "cloud", "usageCollection", "home", "globalSearch"],
"extraPublicDirs": ["common"],
"requiredBundles": ["kibanaReact", "esUiShared", "home", "infra", "kibanaUtils"]
"requiredBundles": ["kibanaReact", "esUiShared", "home", "infra", "kibanaUtils", "usageCollection"]
}
23 changes: 13 additions & 10 deletions x-pack/plugins/fleet/public/applications/integrations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ export function renderApp(
{ element, appBasePath, history, setHeaderActionMenu }: AppMountParameters,
config: FleetConfigType,
kibanaVersion: string,
extensions: UIExtensionsStorage
extensions: UIExtensionsStorage,
UsageTracker: React.FC
) {
ReactDOM.render(
<IntegrationsApp
basepath={appBasePath}
startServices={startServices}
config={config}
history={history}
kibanaVersion={kibanaVersion}
extensions={extensions}
setHeaderActionMenu={setHeaderActionMenu}
/>,
<UsageTracker>
<IntegrationsApp
basepath={appBasePath}
startServices={startServices}
config={config}
history={history}
kibanaVersion={kibanaVersion}
extensions={extensions}
setHeaderActionMenu={setHeaderActionMenu}
/>
</UsageTracker>,
element
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import React from 'react';
import styled from 'styled-components';
import { EuiCard, EuiFlexItem, EuiBadge, EuiToolTip, EuiSpacer } from '@elastic/eui';

import { TrackApplicationView } from '../../../../../../../../../src/plugins/usage_collection/public';

import { CardIcon } from '../../../../../components/package_icon';
import type { IntegrationCardItem } from '../../../../../../common/types/models/epm';

Expand All @@ -31,6 +33,7 @@ export function PackageCard({
integration,
url,
release,
id,
}: PackageCardProps) {
let releaseBadge: React.ReactNode | null = null;

Expand All @@ -47,26 +50,30 @@ export function PackageCard({
);
}

const testid = `integration-card:${id}`;
return (
<Card
layout="horizontal"
title={title || ''}
titleSize="xs"
description={description}
hasBorder
icon={
<CardIcon
icons={icons}
packageName={name}
integrationName={integration}
version={version}
size="xl"
/>
}
href={url}
target={url.startsWith('http') || url.startsWith('https') ? '_blank' : undefined}
>
{releaseBadge}
</Card>
<TrackApplicationView viewId={testid}>
<Card
data-test-subj={testid}
layout="horizontal"
title={title || ''}
titleSize="xs"
description={description}
hasBorder
icon={
<CardIcon
icons={icons}
packageName={name}
integrationName={integration}
version={version}
size="xl"
/>
}
href={url}
target={url.startsWith('http') || url.startsWith('https') ? '_blank' : undefined}
>
{releaseBadge}
</Card>
</TrackApplicationView>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const packageListToIntegrationsList = (packages: PackageList): PackageList => {
const allCategories = [...topCategories, ...categories];
return {
...restOfPackage,
id: `${restOfPackage}-${name}`,
id: `${restOfPackage.id}-${name}`,
integration: name,
title,
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const mapToCard = (
}

return {
id: `${item.type === 'ui_link' ? 'ui_link' : 'epr'}-${item.id}`,
id: `${item.type === 'ui_link' ? 'ui_link' : 'epr'}:${item.id}`,
description: item.description,
icons: !item.icons || !item.icons.length ? [] : item.icons,
title: item.title,
Expand Down
16 changes: 15 additions & 1 deletion x-pack/plugins/fleet/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import React from 'react';
import type {
AppMountParameters,
CoreSetup,
Expand All @@ -23,6 +24,8 @@ import type {

import type { SharePluginStart } from 'src/plugins/share/public';

import type { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';

import { DEFAULT_APP_CATEGORIES, AppNavLinkStatus } from '../../../../src/core/public';

import type {
Expand Down Expand Up @@ -73,6 +76,7 @@ export interface FleetSetupDeps {
cloud?: CloudSetup;
globalSearch?: GlobalSearchPluginSetup;
customIntegrations: CustomIntegrationsSetup;
usageCollection?: UsageCollectionSetup;
}

export interface FleetStartDeps {
Expand Down Expand Up @@ -137,7 +141,17 @@ export class FleetPlugin implements Plugin<FleetSetup, FleetStart, FleetSetupDep
cloud: deps.cloud,
};
const { renderApp, teardownIntegrations } = await import('./applications/integrations');
const unmount = renderApp(startServices, params, config, kibanaVersion, extensions);

const Tracker =
deps.usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment;
const unmount = renderApp(
startServices,
params,
config,
kibanaVersion,
extensions,
Tracker
);

return () => {
unmount();
Expand Down

0 comments on commit 7420cc2

Please sign in to comment.