Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] NP Plugin dependency cleanup #64842

Merged
merged 7 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions x-pack/plugins/siem/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
"alerting",
"data",
"embeddable",
"esUiShared",
"features",
"home",
"inspector",
"kibanaUtils",
"licensing",
"maps",
"triggers_actions_ui",
"uiActions",
"uiActions"
],
"optionalPlugins": [
"encryptedSavedObjects",
"ml",
"newsfeed",
"security",
"spaces",
"usageCollection"
],
"optionalPlugins": ["encryptedSavedObjects", "ml", "newsfeed", "security", "spaces"],
"server": true,
"ui": true
}
8 changes: 3 additions & 5 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 @@ -24,11 +26,7 @@ export const track: TrackFn = (type, event, count) => {
};

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

export enum TELEMETRY_EVENT {
Expand Down
6 changes: 3 additions & 3 deletions 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 All @@ -59,14 +59,14 @@ export interface PluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PluginStart {}

export class Plugin implements IPlugin<PluginSetup, PluginStart> {
export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, StartPlugins> {
private kibanaVersion: string;

constructor(initializerContext: PluginInitializerContext) {
this.kibanaVersion = initializerContext.env.packageInfo.version;
}

public setup(core: CoreSetup, plugins: SetupPlugins) {
public setup(core: CoreSetup<StartPlugins, PluginStart>, plugins: SetupPlugins) {
initTelemetry(plugins.usageCollection, APP_ID);

plugins.home.featureCatalogue.register({
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/siem/server/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup, SetupPlugins } from '../../plugin';
import { CoreSetup } from '../../../../../../src/core/server';
import { SetupPlugins } from '../../plugin';

import { Authentications } from '../authentications';
import { ElasticsearchAuthenticationAdapter } from '../authentications/elasticsearch_adapter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { GraphQLSchema } from 'graphql';
import { runHttpQuery } from 'apollo-server-core';
import { schema as configSchema } from '@kbn/config-schema';
import {
CoreSetup,
IRouter,
KibanaResponseFactory,
RequestHandlerContext,
KibanaRequest,
} from '../../../../../../src/core/server';
import { IndexPatternsFetcher } from '../../../../../../src/plugins/data/server';
import { AuthenticatedUser } from '../../../../security/common/model';
import { CoreSetup, SetupPlugins } from '../../plugin';
import { SetupPlugins } from '../../plugin';

import {
FrameworkAdapter,
Expand Down
16 changes: 4 additions & 12 deletions x-pack/plugins/siem/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ import {
PluginInitializerContext,
Logger,
} from '../../../../src/core/server';
import {
PluginStartContract as AlertingStart,
PluginSetupContract as AlertingSetup,
} from '../../alerting/server';
import { PluginSetupContract as AlertingSetup } from '../../alerting/server';
import { SecurityPluginSetup as SecuritySetup } from '../../security/server';
import { PluginSetupContract as FeaturesSetup } from '../../features/server';
import { MlPluginSetup as MlSetup } from '../../ml/server';
import { EncryptedSavedObjectsPluginSetup as EncryptedSavedObjectsSetup } from '../../encrypted_saved_objects/server';
import { SpacesPluginSetup as SpacesSetup } from '../../spaces/server';
import { PluginStartContract as ActionsStart } from '../../actions/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { initServer } from './init_server';
import { compose } from './lib/compose/kibana';
Expand All @@ -40,8 +36,6 @@ import { createConfig$, ConfigType } from './config';
import { initUiSettings } from './ui_settings';
import { APP_ID, APP_ICON } from '../common/constants';

export { CoreSetup, CoreStart };

export interface SetupPlugins {
alerting: AlertingSetup;
encryptedSavedObjects?: EncryptedSavedObjectsSetup;
Expand All @@ -52,10 +46,8 @@ export interface SetupPlugins {
ml?: MlSetup;
}

export interface StartPlugins {
actions: ActionsStart;
alerting: AlertingStart;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface StartPlugins {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PluginSetup {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can optionally remove these two empty interfaces if you want and just do this below:

export class Plugin implements IPlugin<void, void, SetupPlugins, StartPlugins> {

And then remove the return {} you have in the start and setup to not return anything unless I'm missing something and we are returning empty objects for a purpose. But it looks like the contracts allow void for return types and we don't have anything useful to return at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrankHassanabad we return {} instead of undefined to allow consumers to distinguish between a disabled plugin and an enabled plugin with no contract. We first encountered this with our newsfeed integration, which resulted in #56236.

Expand All @@ -77,7 +69,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
this.logger.debug('plugin initialized');
}

public async setup(core: CoreSetup, plugins: SetupPlugins) {
public async setup(core: CoreSetup<StartPlugins, PluginStart>, plugins: SetupPlugins) {
this.logger.debug('plugin setup');

if (hasListsFeature()) {
Expand Down