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

migrate TaskManager Plugin to the Kibana Platform #53869

Merged
merged 38 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3155252
moved Task Manager server code under "server" directory
gmmorris Dec 23, 2019
2cbc508
Merge branch 'master' into task-manager/server-dir
elasticmachine Dec 30, 2019
f7c61c7
expose Task Manager via a Kibana Platform plugin
gmmorris Dec 31, 2019
00efbf0
fixed TM types
gmmorris Jan 2, 2020
b0c47b6
fixed TM usage in maps
gmmorris Jan 2, 2020
4246b94
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 2, 2020
1108dfb
fixed test fixture in maps
gmmorris Jan 2, 2020
f317390
Merge branch 'master' into task-manager/schema-config
elasticmachine Jan 2, 2020
5f8e2e5
fixed empty TaskManager issue in oss_telemetry
gmmorris Jan 3, 2020
ce915d8
Merge branch 'task-manager/schema-config' of github.com:gmmorris/kiba…
gmmorris Jan 3, 2020
2eb807e
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 3, 2020
85be0b8
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 3, 2020
1e582b8
removed optional chaining
gmmorris Jan 3, 2020
923846a
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 6, 2020
e6862da
fixed tm reference in collectors
gmmorris Jan 6, 2020
2047538
fixed tm immport in alerting FT
gmmorris Jan 6, 2020
a330d9a
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 6, 2020
731c476
cleaned up udage of new TM in lens
gmmorris Jan 6, 2020
5c93173
use NP elasticsearch client in legacy plugin
gmmorris Jan 6, 2020
37fa4b1
removed unneeded import
gmmorris Jan 6, 2020
d797059
pass TM directly to NP plugin
gmmorris Jan 7, 2020
9327532
moved to using the NP SavedObjectsRepository
gmmorris Jan 7, 2020
e4263e5
moved Legacy Task Manager implementation into the New Platform Plugin
gmmorris Jan 8, 2020
9e0c028
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 8, 2020
8e18ee2
admin client is no longer observable
gmmorris Jan 8, 2020
4854616
removed any usage of Legacy TM api
gmmorris Jan 8, 2020
3c27cac
renamed plugin to final name
gmmorris Jan 8, 2020
b7520ee
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 8, 2020
c8ec059
retain legacy API
gmmorris Jan 8, 2020
bb2789d
added docs for new Taskmanager plugin API
gmmorris Jan 8, 2020
f5ec90c
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 8, 2020
a2cce60
clean up usage of NP TM in legacy plugins
gmmorris Jan 8, 2020
39b6857
use legacy helper in our own legacy TM obviously
gmmorris Jan 8, 2020
3dd94d5
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 9, 2020
35d55e7
cleaned up dependency on TM in other plugins
gmmorris Jan 9, 2020
9e63e9b
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 9, 2020
4173614
Merge branch 'master' into task-manager/schema-config
gmmorris Jan 13, 2020
5ad09d2
allow lens t ostart even if TM isnt available
gmmorris Jan 13, 2020
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
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.
export { httpServiceMock } from './http/http_service.mock';
export { loggingServiceMock } from './logging/logging_service.mock';
export { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock';
export { savedObjectsRepositoryMock } from './saved_objects/service/lib/repository.mock';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Task Manager interacts with the repository directly, so accessing this mock was needed for testing purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's okay. The SO repository is a part of public contract

createInternalRepository: (extraTypes?: string[]) =>

export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
import { uuidServiceMock } from './uuid/uuid_service.mock';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { taskManagerMock } from '../../../../plugins/task_manager/server/task_manager.mock';
import { ActionTypeRegistry } from './action_type_registry';
import { ExecutorType } from './types';
import { ActionExecutor, ExecutorError, TaskRunnerFactory } from './lib';
import { configUtilsMock } from './actions_config.mock';

const mockTaskManager = taskManagerMock.create();
const mockTaskManager = taskManagerMock.setup();
const actionTypeRegistryParams = {
taskManager: mockTaskManager,
taskRunnerFactory: new TaskRunnerFactory(new ActionExecutor()),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import Boom from 'boom';
import { i18n } from '@kbn/i18n';
import { TaskManagerSetupContract } from './shim';
import { RunContext } from '../../task_manager/server';
import { RunContext, TaskManagerSetupContract } from '../../../../plugins/task_manager/server';
import { ExecutorError, TaskRunnerFactory } from './lib';
import { ActionType } from './types';
import { ActionsConfigurationUtilities } from './actions_config';

interface ConstructorOptions {
taskManager: TaskManagerSetupContract;
taskRunnerFactory: TaskRunnerFactory;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ActionTypeRegistry } from './action_type_registry';
import { ActionsClient } from './actions_client';
import { ExecutorType } from './types';
import { ActionExecutor, TaskRunnerFactory } from './lib';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { taskManagerMock } from '../../../../plugins/task_manager/server/task_manager.mock';
import { configUtilsMock } from './actions_config.mock';
import { getActionsConfigurationUtilities } from './actions_config';

Expand All @@ -23,7 +23,7 @@ const defaultKibanaIndex = '.kibana';
const savedObjectsClient = savedObjectsClientMock.create();
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();

const mockTaskManager = taskManagerMock.create();
const mockTaskManager = taskManagerMock.setup();

const actionTypeRegistryParams = {
taskManager: mockTaskManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ActionExecutor, TaskRunnerFactory } from '../lib';
import { ActionTypeRegistry } from '../action_type_registry';
import { taskManagerMock } from '../../../task_manager/server/task_manager.mock';
import { taskManagerMock } from '../../../../../plugins/task_manager/server/task_manager.mock';
import { registerBuiltInActionTypes } from './index';
import { Logger } from '../../../../../../src/core/server';
import { loggingServiceMock } from '../../../../../../src/core/server/mocks';
Expand All @@ -20,7 +20,7 @@ export function createActionTypeRegistry(): {
} {
const logger = loggingServiceMock.create().get() as jest.Mocked<Logger>;
const actionTypeRegistry = new ActionTypeRegistry({
taskManager: taskManagerMock.create(),
taskManager: taskManagerMock.setup(),
taskRunnerFactory: new TaskRunnerFactory(new ActionExecutor()),
actionsConfigUtils: configUtilsMock,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { taskManagerMock } from '../../../../plugins/task_manager/server/task_manager.mock';
import { createExecuteFunction } from './create_execute_function';
import { savedObjectsClientMock } from '../../../../../src/core/server/mocks';

const mockTaskManager = taskManagerMock.create();
const mockTaskManager = taskManagerMock.start();
const savedObjectsClient = savedObjectsClientMock.create();
const getBasePath = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { SavedObjectsClientContract } from 'src/core/server';
import { TaskManagerStartContract } from './shim';
import { TaskManagerStartContract } from '../../../../plugins/task_manager/server';
import { GetBasePathFunction } from './types';

interface CreateExecuteFunctionOptions {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/legacy/plugins/actions/server/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Legacy } from 'kibana';
import { Plugin } from './plugin';
import { shim, Server } from './shim';
import { shim } from './shim';
import { ActionsPlugin } from './types';

export async function init(server: Server) {
export async function init(server: Legacy.Server) {
const { initializerContext, coreSetup, coreStart, pluginsSetup, pluginsStart } = shim(server);

const plugin = new Plugin(initializerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sinon from 'sinon';
import { ExecutorError } from './executor_error';
import { ActionExecutor } from './action_executor';
import { ConcreteTaskInstance, TaskStatus } from '../../../task_manager/server';
import { ConcreteTaskInstance, TaskStatus } from '../../../../../plugins/task_manager/server';
import { TaskRunnerFactory } from './task_runner_factory';
import { actionTypeRegistryMock } from '../action_type_registry.mock';
import { actionExecutorMock } from './action_executor.mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ActionExecutorContract } from './action_executor';
import { ExecutorError } from './executor_error';
import { RunContext } from '../../../task_manager/server';
import { RunContext } from '../../../../../plugins/task_manager/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../../plugins/encrypted_saved_objects/server';
import { ActionTaskParams, GetBasePathFunction, SpaceIdToNamespaceFunction } from '../types';

Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Plugin {
const actionsConfigUtils = getActionsConfigurationUtilities(config as ActionsConfigType);
const actionTypeRegistry = new ActionTypeRegistry({
taskRunnerFactory,
taskManager: plugins.task_manager,
taskManager: plugins.taskManager,
actionsConfigUtils,
});
this.taskRunnerFactory = taskRunnerFactory;
Expand Down Expand Up @@ -164,7 +164,7 @@ export class Plugin {
});

const executeFn = createExecuteFunction({
taskManager: plugins.task_manager,
taskManager: plugins.taskManager,
getScopedSavedObjectsClient: core.savedObjects.getScopedSavedObjectsClient,
getBasePath,
});
Expand Down
31 changes: 10 additions & 21 deletions x-pack/legacy/plugins/actions/server/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import Hapi from 'hapi';
import { Legacy } from 'kibana';
import * as Rx from 'rxjs';
import { ActionsConfigType } from './types';
import { TaskManager } from '../../task_manager/server';
import {
TaskManagerStartContract,
TaskManagerSetupContract,
} from '../../../../plugins/task_manager/server';
import { getTaskManagerSetup, getTaskManagerStart } from '../../task_manager/server';
import { XPackMainPlugin } from '../../xpack_main/server/xpack_main';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
import { LegacySpacesPlugin as SpacesPluginStartContract } from '../../spaces';
Expand All @@ -24,31 +28,16 @@ import {
} from '../../../../../src/core/server';
import { LicensingPluginSetup } from '../../../../plugins/licensing/server';

// Extend PluginProperties to indicate which plugins are guaranteed to exist
// due to being marked as dependencies
interface Plugins extends Hapi.PluginProperties {
task_manager: TaskManager;
}

export interface Server extends Legacy.Server {
plugins: Plugins;
}

export interface KibanaConfig {
index: string;
}

/**
* Shim what we're thinking setup and start contracts will look like
*/
export type TaskManagerStartContract = Pick<TaskManager, 'schedule' | 'fetch' | 'remove'>;
export type XPackMainPluginSetupContract = Pick<XPackMainPlugin, 'registerFeature'>;
export type SecurityPluginSetupContract = Pick<SecurityPlugin, '__legacyCompat'>;
export type SecurityPluginStartContract = Pick<SecurityPlugin, 'authc'>;
export type TaskManagerSetupContract = Pick<
TaskManager,
'addMiddleware' | 'registerTaskDefinitions'
>;

/**
* New platform interfaces
Expand All @@ -74,7 +63,7 @@ export interface ActionsCoreStart {
}
export interface ActionsPluginsSetup {
security?: SecurityPluginSetupContract;
task_manager: TaskManagerSetupContract;
taskManager: TaskManagerSetupContract;
xpack_main: XPackMainPluginSetupContract;
encryptedSavedObjects: EncryptedSavedObjectsSetupContract;
licensing: LicensingPluginSetup;
Expand All @@ -83,7 +72,7 @@ export interface ActionsPluginsStart {
security?: SecurityPluginStartContract;
spaces: () => SpacesPluginStartContract | undefined;
encryptedSavedObjects: EncryptedSavedObjectsStartContract;
task_manager: TaskManagerStartContract;
taskManager: TaskManagerStartContract;
}

/**
Expand All @@ -92,7 +81,7 @@ export interface ActionsPluginsStart {
* @param server Hapi server instance
*/
export function shim(
server: Server
server: Legacy.Server
): {
initializerContext: ActionsPluginInitializerContext;
coreSetup: ActionsCoreSetup;
Expand Down Expand Up @@ -132,7 +121,7 @@ export function shim(

const pluginsSetup: ActionsPluginsSetup = {
security: newPlatform.setup.plugins.security as SecurityPluginSetupContract | undefined,
task_manager: server.plugins.task_manager,
taskManager: getTaskManagerSetup(server)!,
xpack_main: server.plugins.xpack_main,
encryptedSavedObjects: newPlatform.setup.plugins
.encryptedSavedObjects as EncryptedSavedObjectsSetupContract,
Expand All @@ -146,7 +135,7 @@ export function shim(
spaces: () => server.plugins.spaces,
encryptedSavedObjects: newPlatform.start.plugins
.encryptedSavedObjects as EncryptedSavedObjectsStartContract,
task_manager: server.plugins.task_manager,
taskManager: getTaskManagerStart(server)!,
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

import { TaskRunnerFactory } from './task_runner';
import { AlertTypeRegistry } from './alert_type_registry';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';

const taskManager = taskManagerMock.create();
import { taskManagerMock } from '../../../../plugins/task_manager/server/task_manager.mock';

const taskManager = taskManagerMock.setup();
const alertTypeRegistryParams = {
taskManager,
taskRunnerFactory: new TaskRunnerFactory(),
Expand Down
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/alerting/server/alert_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

import Boom from 'boom';
import { i18n } from '@kbn/i18n';
import { RunContext, TaskManagerSetupContract } from '../../../../plugins/task_manager/server';
import { TaskRunnerFactory } from './task_runner';
import { RunContext } from '../../task_manager';
import { TaskManagerSetupContract } from './shim';
import { AlertType } from './types';

interface ConstructorOptions {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import uuid from 'uuid';
import { schema } from '@kbn/config-schema';
import { AlertsClient } from './alerts_client';
import { savedObjectsClientMock, loggingServiceMock } from '../../../../../src/core/server/mocks';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { taskManagerMock } from '../../../../plugins/task_manager/server/task_manager.mock';
import { alertTypeRegistryMock } from './alert_type_registry.mock';
import { TaskStatus } from '../../task_manager/server';
import { TaskStatus } from '../../../../plugins/task_manager/server';
import { IntervalSchedule } from './types';
import { resolvable } from './test_utils';
import { encryptedSavedObjectsMock } from '../../../../plugins/encrypted_saved_objects/server/mocks';

const taskManager = taskManagerMock.create();
const taskManager = taskManagerMock.start();
const alertTypeRegistry = alertTypeRegistryMock.create();
const savedObjectsClient = savedObjectsClientMock.create();
const encryptedSavedObjects = encryptedSavedObjectsMock.createStart();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
AlertType,
IntervalSchedule,
} from './types';
import { TaskManagerStartContract } from './shim';
import { validateAlertTypeParams } from './lib';
import {
InvalidateAPIKeyParams,
CreateAPIKeyResult as SecurityPluginCreateAPIKeyResult,
InvalidateAPIKeyResult as SecurityPluginInvalidateAPIKeyResult,
} from '../../../../plugins/security/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../plugins/encrypted_saved_objects/server';
import { TaskManagerStartContract } from '../../../../plugins/task_manager/server';

type NormalizedAlertAction = Omit<AlertAction, 'actionTypeId'>;
export type CreateAPIKeyResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Request } from 'hapi';
import { AlertsClientFactory, ConstructorOpts } from './alerts_client_factory';
import { alertTypeRegistryMock } from './alert_type_registry.mock';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { taskManagerMock } from '../../../../plugins/task_manager/server/task_manager.mock';
import { KibanaRequest } from '../../../../../src/core/server';
import { loggingServiceMock } from '../../../../../src/core/server/mocks';
import { encryptedSavedObjectsMock } from '../../../../plugins/encrypted_saved_objects/server/mocks';
Expand All @@ -23,7 +23,7 @@ const securityPluginSetup = {
};
const alertsClientFactoryParams: jest.Mocked<ConstructorOpts> = {
logger: loggingServiceMock.create().get(),
taskManager: taskManagerMock.create(),
taskManager: taskManagerMock.start(),
alertTypeRegistry: alertTypeRegistryMock.create(),
getSpaceId: jest.fn(),
spaceIdToNamespace: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import Hapi from 'hapi';
import uuid from 'uuid';
import { AlertsClient } from './alerts_client';
import { AlertTypeRegistry, SpaceIdToNamespaceFunction } from './types';
import { SecurityPluginStartContract, TaskManagerStartContract } from './shim';
import { SecurityPluginStartContract } from './shim';
import { KibanaRequest, Logger } from '../../../../../src/core/server';
import { InvalidateAPIKeyParams } from '../../../../plugins/security/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../plugins/encrypted_saved_objects/server';
import { TaskManagerStartContract } from '../../../../plugins/task_manager/server';

export interface ConstructorOpts {
logger: Logger;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Plugin {
});

const alertTypeRegistry = new AlertTypeRegistry({
taskManager: plugins.task_manager,
taskManager: plugins.taskManager,
taskRunnerFactory: this.taskRunnerFactory,
});
this.alertTypeRegistry = alertTypeRegistry;
Expand Down Expand Up @@ -116,7 +116,7 @@ export class Plugin {
const alertsClientFactory = new AlertsClientFactory({
alertTypeRegistry: this.alertTypeRegistry!,
logger: this.logger,
taskManager: plugins.task_manager,
taskManager: plugins.taskManager,
securityPluginSetup: plugins.security,
encryptedSavedObjectsPlugin: plugins.encryptedSavedObjects,
spaceIdToNamespace,
Expand Down
Loading