mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
The location of plugins was previously somewhat irrelevant, but as we move into packages it's more important that we can find all plugins in the repository, and we would like to be able to do that without needing to maintain a manifest somewhere to accomplish this. In order to make this possible we plan to find any plugin/package by spotting all kibana.json files which are not "fixtures". This allows plugin-like code (but not actual plugin code) to exist for testing purposes, but it must be within some form of "fixtures" directory, and any plugin that isn't in a fixtures directory will be automatically pulled into the system (though test plugins, examples, etc. will still only be loaded when the plugin's path is passed via `--plugin-path`, the system will know about them and use that knowledge for other things). Since this is just a rename Operations will review and merge by EOD Jan 12th unless someone has a blocking concern. Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
108 lines
3.3 KiB
TypeScript
108 lines
3.3 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
* Side Public License, v 1.
|
|
*/
|
|
|
|
import { BehaviorSubject, filter, firstValueFrom, ReplaySubject } from 'rxjs';
|
|
import { takeWhile, tap, toArray } from 'rxjs/operators';
|
|
import type { Plugin, CoreSetup, CoreStart, TelemetryCounter, Event } from '@kbn/core/server';
|
|
import type { Action } from './custom_shipper';
|
|
import { CustomShipper } from './custom_shipper';
|
|
import './types';
|
|
|
|
export class AnalyticsPluginA implements Plugin {
|
|
private readonly actions$ = new ReplaySubject<Action>();
|
|
|
|
public setup({ analytics }: CoreSetup) {
|
|
const {
|
|
registerShipper,
|
|
registerContextProvider,
|
|
registerEventType,
|
|
reportEvent,
|
|
telemetryCounter$,
|
|
} = analytics;
|
|
registerShipper(CustomShipper, this.actions$);
|
|
|
|
const stats: TelemetryCounter[] = [];
|
|
telemetryCounter$.subscribe((event) => stats.push(event));
|
|
|
|
registerEventType({
|
|
eventType: 'test-plugin-lifecycle',
|
|
schema: {
|
|
plugin: {
|
|
type: 'keyword',
|
|
_meta: {
|
|
description: 'The ID of the plugin',
|
|
},
|
|
},
|
|
step: {
|
|
type: 'keyword',
|
|
_meta: {
|
|
description: 'The lifecycle step in which the plugin is',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Report an event before the shipper is registered
|
|
reportEvent('test-plugin-lifecycle', {
|
|
plugin: 'analyticsPluginA',
|
|
step: 'setup',
|
|
});
|
|
let found = false;
|
|
window.__analyticsPluginA__ = {
|
|
getActionsUntilReportTestPluginLifecycleEvent: async () =>
|
|
firstValueFrom(
|
|
this.actions$.pipe(
|
|
takeWhile(() => !found),
|
|
tap((action) => {
|
|
found = isTestPluginLifecycleReportEventAction(action);
|
|
}),
|
|
// Filter only the actions that are relevant to this plugin
|
|
filter(
|
|
({ action, meta }) =>
|
|
['optIn', 'extendContext'].includes(action) ||
|
|
isTestPluginLifecycleReportEventAction({ action, meta })
|
|
),
|
|
toArray()
|
|
)
|
|
),
|
|
stats,
|
|
setOptIn(optIn: boolean) {
|
|
analytics.optIn({ global: { enabled: optIn } });
|
|
},
|
|
getFlushAction: async () =>
|
|
firstValueFrom(this.actions$.pipe(filter(({ action }) => action === 'flush'))),
|
|
};
|
|
|
|
registerContextProvider({
|
|
name: 'analyticsPluginA',
|
|
context$: new BehaviorSubject({ user_agent: navigator.userAgent }).asObservable(),
|
|
schema: {
|
|
user_agent: {
|
|
type: 'keyword',
|
|
_meta: {
|
|
description: 'The user agent of the browser',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
public start({ analytics }: CoreStart) {
|
|
analytics.reportEvent('test-plugin-lifecycle', {
|
|
plugin: 'analyticsPluginA',
|
|
step: 'start',
|
|
});
|
|
}
|
|
public stop() {}
|
|
}
|
|
|
|
function isTestPluginLifecycleReportEventAction({ action, meta }: Action): boolean {
|
|
return (
|
|
action === 'reportEvents' &&
|
|
meta.find((event: Event) => event.event_type === 'test-plugin-lifecycle')
|
|
);
|
|
}
|