Skip to content

Commit

Permalink
Make usageCollection an optional dependency
Browse files Browse the repository at this point in the history
If it's not enabled, we simply use a noop for our tracker call.
  • Loading branch information
rylnd committed Apr 29, 2020
1 parent 687d301 commit 809382a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions x-pack/plugins/siem/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
"licensing",
"maps",
"triggers_actions_ui",
"uiActions",
"uiActions"
],
"optionalPlugins": [
"encryptedSavedObjects",
"ml",
"newsfeed",
"security",
"spaces",
"usageCollection"
],
"optionalPlugins": ["encryptedSavedObjects", "ml", "newsfeed", "security", "spaces"],
"server": true,
"ui": true
}
6 changes: 4 additions & 2 deletions x-pack/plugins/siem/public/lib/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export { METRIC_TYPE };

type TrackFn = (type: UiStatsMetricType, event: string | string[], count?: number) => void;

const noop = () => {};

let _track: TrackFn;

export const track: TrackFn = (type, event, count) => {
Expand All @@ -25,9 +27,9 @@ export const track: TrackFn = (type, event, count) => {

export const initTelemetry = (usageCollection: SetupPlugins['usageCollection'], appId: string) => {
try {
_track = usageCollection.reportUiStats.bind(null, appId);
_track = usageCollection?.reportUiStats.bind(null, appId) ?? noop;
} catch (error) {
// ignore failed setup here, as we'll just have an inert tracker
_track = noop;
}
};

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface SetupPlugins {
home: HomePublicPluginSetup;
security: SecurityPluginSetup;
triggers_actions_ui: TriggersActionsSetup;
usageCollection: UsageCollectionSetup;
usageCollection?: UsageCollectionSetup;
}

export interface StartPlugins {
Expand Down

0 comments on commit 809382a

Please sign in to comment.