Skip to content

Commit

Permalink
In-chart "Explore underlying data" action telemetry (#74516)
Browse files Browse the repository at this point in the history
* feat: ๐ŸŽธ add telemetry for in-chart "Explore underlying data"

* refactor: ๐Ÿ’ก use shared Config type from /common folder

* feat: ๐ŸŽธ register usage collector

* chore: ๐Ÿค– upate telemetry schema

* fix: ๐Ÿ› use relative import for usage_collector

* fix: ๐Ÿ› use relative imports for core

* fix: ๐Ÿ› use relative import

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
streamich and elasticmachine authored Aug 24, 2020
1 parent f3799c3 commit c6e86cf
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
}
}
},
"search": {
"properties": {
"successCount": {
"type": "number"
},
"errorCount": {
"type": "number"
},
"averageDuration": {
"type": "long"
}
}
},
"sample-data": {
"properties": {
"installed": {
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/discover_enhanced/common/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 interface Config {
actions: { exploreDataInChart: { enabled: boolean } };
}
7 changes: 7 additions & 0 deletions x-pack/plugins/discover_enhanced/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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 * from './config';
2 changes: 1 addition & 1 deletion x-pack/plugins/discover_enhanced/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"server": true,
"ui": true,
"requiredPlugins": ["uiActions", "embeddable", "discover"],
"optionalPlugins": ["share", "kibanaLegacy"],
"optionalPlugins": ["share", "kibanaLegacy", "usageCollection"],
"configPath": ["xpack", "discoverEnhanced"],
"requiredBundles": ["kibanaUtils", "data"]
}
5 changes: 3 additions & 2 deletions x-pack/plugins/discover_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
ACTION_EXPLORE_DATA_CHART,
ExploreDataChartActionContext,
} from './actions';
import { Config } from '../common';

declare module '../../../../src/plugins/ui_actions/public' {
export interface ActionContextMapping {
Expand Down Expand Up @@ -55,10 +56,10 @@ export interface DiscoverEnhancedStartDependencies {
export class DiscoverEnhancedPlugin
implements
Plugin<void, void, DiscoverEnhancedSetupDependencies, DiscoverEnhancedStartDependencies> {
public readonly config: { actions: { exploreDataInChart: { enabled: boolean } } };
public readonly config: Config;

constructor(protected readonly context: PluginInitializerContext) {
this.config = context.config.get();
this.config = context.config.get<Config>();
}

setup(
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/discover_enhanced/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializerContext } from '../../../../src/core/server';
import { DiscoverEnhancedPlugin } from './plugin';

export { config } from './config';

export const plugin = () => ({
setup() {},
start() {},
});
export const plugin = (context: PluginInitializerContext) => new DiscoverEnhancedPlugin(context);
58 changes: 58 additions & 0 deletions x-pack/plugins/discover_enhanced/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import {
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
} from '../../../../src/core/server';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { Config } from '../common';

interface SetupDependencies {
usageCollection?: UsageCollectionSetup;
}

interface StartDependencies {
usageCollection?: unknown;
}

export class DiscoverEnhancedPlugin
implements Plugin<void, void, SetupDependencies, StartDependencies> {
private config$: Observable<Config>;

constructor(protected readonly context: PluginInitializerContext) {
this.config$ = context.config.create<Config>();
}

public setup(core: CoreSetup, { usageCollection }: SetupDependencies) {
if (!!usageCollection) {
const collector = usageCollection.makeUsageCollector<{
exploreDataInChartActionEnabled: boolean;
}>({
type: 'discoverEnhanced',
schema: {
exploreDataInChartActionEnabled: {
type: 'boolean',
},
},
isReady: () => true,
fetch: async () => {
const config = await this.config$.pipe(take(1)).toPromise();
return {
exploreDataInChartActionEnabled: config.actions.exploreDataInChart.enabled,
};
},
});
usageCollection.registerCollector(collector);
}
}

public start(core: CoreStart) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
}
}
},
"discoverEnhanced": {
"properties": {
"exploreDataInChartActionEnabled": {
"type": "boolean"
}
}
},
"app_search": {
"properties": {
"ui_viewed": {
Expand Down

0 comments on commit c6e86cf

Please sign in to comment.