Skip to content

Commit

Permalink
feat: ๐ŸŽธ connect dasdhboard telemetry to persistable state (#99498)
Browse files Browse the repository at this point in the history
* feat: ๐ŸŽธ connect dasdhboard telemetry to persistable state

* fix: ๐Ÿ› do not mutate .telemetry() stats objects

* feat: ๐ŸŽธ populate stats object with embeddable telemetry

* feat: ๐ŸŽธ embeddable telemetry schema

* feat: ๐ŸŽธ update telemetry schema

* feat: ๐ŸŽธ add descriptions to dashboard collector

* chore: ๐Ÿค– update telemetry schema

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
streamich and kibanamachine authored Jun 3, 2021
1 parent 4e5652d commit 1d39d36
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/plugins/dashboard/server/usage/dashboard_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ export interface DashboardCollectorData {
visualizationByValue: {
[key: string]: number;
};
embeddable: {
[key: string]: number;
};
}

export const getEmptyTelemetryData = (): DashboardCollectorData => ({
panels: 0,
panelsByValue: 0,
lensByValue: {},
visualizationByValue: {},
embeddable: {},
});

type DashboardCollectorFunction = (
Expand Down Expand Up @@ -115,6 +119,23 @@ export const collectForPanels: DashboardCollectorFunction = (panels, collectorDa
collectByValueLensInfo(panels, collectorData);
};

export const collectEmbeddableData = (
panels: SavedDashboardPanel730ToLatest[],
collectorData: DashboardCollectorData,
embeddableService: EmbeddablePersistableStateService
) => {
for (const panel of panels) {
collectorData.embeddable = embeddableService.telemetry(
{
...panel.embeddableConfig,
id: panel.id || '',
type: panel.type,
},
collectorData.embeddable
);
}
};

export async function collectDashboardTelemetry(
savedObjectClient: Pick<ISavedObjectsRepository, 'find'>,
embeddableService: EmbeddablePersistableStateService
Expand All @@ -134,6 +155,7 @@ export async function collectDashboardTelemetry(
) as unknown) as SavedDashboardPanel730ToLatest[];

collectForPanels(panels, collectorData);
collectEmbeddableData(panels, collectorData, embeddableService);
}

return collectorData;
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/dashboard/server/usage/register_collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,28 @@ export function registerDashboardUsageCollector(
lensByValue: {
DYNAMIC_KEY: {
type: 'long',
_meta: {
description:
'Collection of telemetry metrics for Lens visualizations, which are added to dashboard by "value".',
},
},
},
visualizationByValue: {
DYNAMIC_KEY: {
type: 'long',
_meta: {
description:
'Collection of telemetry metrics for visualizations, which are added to dashboard by "value".',
},
},
},
embeddable: {
DYNAMIC_KEY: {
type: 'long',
_meta: {
description:
'Collection of telemetry metrics that embeddable service reports. Embeddable service internally calls each embeddable, which in turn calls its dynamic actions, which calls each drill down attached to that embeddable.',
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
return (
this.enhancements.get(id) || {
id: 'unknown',
telemetry: () => ({}),
telemetry: (state, stats) => stats,
inject: identity,
extract: (state: SerializableState) => {
return { state, references: [] };
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/embeddable/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class EmbeddableServerPlugin implements Plugin<EmbeddableSetup, Embeddabl
return (
this.enhancements.get(id) || {
id: 'unknown',
telemetry: () => ({}),
telemetry: (state, stats) => stats,
inject: identity,
extract: (state: SerializableState) => {
return { state, references: [] };
Expand Down Expand Up @@ -119,7 +119,7 @@ export class EmbeddableServerPlugin implements Plugin<EmbeddableSetup, Embeddabl
return (
this.embeddableFactories.get(embeddableFactoryId) || {
id: 'unknown',
telemetry: () => ({}),
telemetry: (state, stats) => stats,
inject: (state: EmbeddableStateWithType) => state,
extract: (state: EmbeddableStateWithType) => {
return { state, references: [] };
Expand Down
20 changes: 18 additions & 2 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@
"lensByValue": {
"properties": {
"DYNAMIC_KEY": {
"type": "long"
"type": "long",
"_meta": {
"description": "Collection of telemetry metrics for Lens visualizations, which are added to dashboard by \"value\"."
}
}
}
},
"visualizationByValue": {
"properties": {
"DYNAMIC_KEY": {
"type": "long"
"type": "long",
"_meta": {
"description": "Collection of telemetry metrics for visualizations, which are added to dashboard by \"value\"."
}
}
}
},
"embeddable": {
"properties": {
"DYNAMIC_KEY": {
"type": "long",
"_meta": {
"description": "Collection of telemetry metrics that embeddable service reports. Embeddable service internally calls each embeddable, which in turn calls its dynamic actions, which calls each drill down attached to that embeddable."
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class ActionFactory<
}

public telemetry(state: SerializedEvent, telemetryData: Record<string, any>) {
return this.def.telemetry ? this.def.telemetry(state, telemetryData) : {};
return this.def.telemetry ? this.def.telemetry(state, telemetryData) : telemetryData;
}

public extract(state: SerializedEvent) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ui_actions_enhanced/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class AdvancedUiActionsServerPlugin

this.actionFactories.set(definition.id, {
id: definition.id,
telemetry: definition.telemetry || (() => ({})),
telemetry: definition.telemetry || ((state, stats) => stats),
inject: definition.inject || identity,
extract:
definition.extract ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { getMetricKey } from './get_metric_key';

export const dynamicActionsCollector = (
state: DynamicActionsState,
stats: Record<string, any>
currentStats: Record<string, any>
): Record<string, any> => {
const stats: Record<string, any> = { ...currentStats };
const countMetricKey = getMetricKey('count');

stats[countMetricKey] = state.events.length + (stats[countMetricKey] || 0);
Expand Down

0 comments on commit 1d39d36

Please sign in to comment.