In-chart "Explore underlying data" action telemetry (#74516)

* 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 <elasticmachine@users.noreply.github.com>
This commit is contained in:
Vadim Dalecky 2020-08-24 14:06:57 +02:00 committed by GitHub
parent f3799c37f6
commit c6e86cf773
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 102 additions and 7 deletions

View file

@ -13,6 +13,19 @@
} }
} }
}, },
"search": {
"properties": {
"successCount": {
"type": "number"
},
"errorCount": {
"type": "number"
},
"averageDuration": {
"type": "long"
}
}
},
"sample-data": { "sample-data": {
"properties": { "properties": {
"installed": { "installed": {

View file

@ -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 } };
}

View file

@ -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';

View file

@ -5,7 +5,7 @@
"server": true, "server": true,
"ui": true, "ui": true,
"requiredPlugins": ["uiActions", "embeddable", "discover"], "requiredPlugins": ["uiActions", "embeddable", "discover"],
"optionalPlugins": ["share", "kibanaLegacy"], "optionalPlugins": ["share", "kibanaLegacy", "usageCollection"],
"configPath": ["xpack", "discoverEnhanced"], "configPath": ["xpack", "discoverEnhanced"],
"requiredBundles": ["kibanaUtils", "data"] "requiredBundles": ["kibanaUtils", "data"]
} }

View file

@ -28,6 +28,7 @@ import {
ACTION_EXPLORE_DATA_CHART, ACTION_EXPLORE_DATA_CHART,
ExploreDataChartActionContext, ExploreDataChartActionContext,
} from './actions'; } from './actions';
import { Config } from '../common';
declare module '../../../../src/plugins/ui_actions/public' { declare module '../../../../src/plugins/ui_actions/public' {
export interface ActionContextMapping { export interface ActionContextMapping {
@ -55,10 +56,10 @@ export interface DiscoverEnhancedStartDependencies {
export class DiscoverEnhancedPlugin export class DiscoverEnhancedPlugin
implements implements
Plugin<void, void, DiscoverEnhancedSetupDependencies, DiscoverEnhancedStartDependencies> { Plugin<void, void, DiscoverEnhancedSetupDependencies, DiscoverEnhancedStartDependencies> {
public readonly config: { actions: { exploreDataInChart: { enabled: boolean } } }; public readonly config: Config;
constructor(protected readonly context: PluginInitializerContext) { constructor(protected readonly context: PluginInitializerContext) {
this.config = context.config.get(); this.config = context.config.get<Config>();
} }
setup( setup(

View file

@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License. * 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 { config } from './config';
export const plugin = () => ({ export const plugin = (context: PluginInitializerContext) => new DiscoverEnhancedPlugin(context);
setup() {},
start() {},
});

View file

@ -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) {}
}

View file

@ -7,6 +7,13 @@
} }
} }
}, },
"discoverEnhanced": {
"properties": {
"exploreDataInChartActionEnabled": {
"type": "boolean"
}
}
},
"app_search": { "app_search": {
"properties": { "properties": {
"ui_viewed": { "ui_viewed": {