Skip to content

Commit

Permalink
Merge branch 'master' into ingest/edit-ds
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Apr 29, 2020
2 parents 47a5274 + 2e410d8 commit 13d2482
Show file tree
Hide file tree
Showing 788 changed files with 7,387 additions and 3,438 deletions.
2 changes: 1 addition & 1 deletion .ci/Jenkinsfile_coverage
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
library 'kibana-pipeline-library'
kibanaLibrary.load() // load from the Jenkins instance

kibanaPipeline(timeoutMinutes: 180) {
kibanaPipeline(timeoutMinutes: 240) {
catchErrors {
withEnv([
'CODE_COVERAGE=1', // Needed for multiple ci scripts, such as remote.ts, test/scripts/*.sh, schema.js, etc.
Expand Down
65 changes: 34 additions & 31 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
node_modules
bower_components
/data
/optimize
/build
/target
**/*.js.snap
**/graphql/types.ts
/.es
/plugins
/build
/built_assets
/data
/html_docs
/src/plugins/data/common/es_query/kuery/ast/_generated_/**
/src/plugins/vis_type_timelion/public/_generated_/**
/src/legacy/ui/public/flot-charts
/optimize
/plugins
/test/fixtures/scenarios
/src/legacy/core_plugins/console/public/webpackShims
/x-pack/build
node_modules
target

!/.eslintrc.js

# plugin overrides
/src/core/lib/kbn_internal_native_observable
/src/legacy/core_plugins/console/public/tests/webpackShims
/src/legacy/core_plugins/console/public/webpackShims
/src/legacy/plugin_discovery/plugin_pack/__tests__/fixtures/plugins/broken
/src/legacy/ui/public/flot-charts
/src/legacy/ui/public/utils/decode_geo_hash.js
/src/plugins/data/common/es_query/kuery/ast/_generated_/**
/src/plugins/vis_type_timelion/public/_generated_/**
/src/plugins/vis_type_timelion/public/webpackShims/jquery.flot.*
/src/core/lib/kbn_internal_native_observable
/packages/*/target
/packages/eslint-config-kibana
/packages/kbn-pm/dist
/packages/kbn-plugin-generator/sao_template/template
/packages/kbn-ui-framework/dist
/packages/kbn-ui-framework/doc_site/build
/packages/kbn-ui-framework/generator-kui/*/templates/
/packages/kbn-test/src/functional_test_runner/__tests__/fixtures/
/packages/kbn-test/src/functional_test_runner/lib/config/__tests__/fixtures/
/x-pack/legacy/plugins/maps/public/vendor/**
/x-pack/coverage
/x-pack/build
/x-pack/legacy/plugins/**/__tests__/fixtures/**
/packages/kbn-interpreter/src/common/lib/grammar.js
/x-pack/legacy/plugins/apm/e2e/cypress/**/snapshots.js
/x-pack/legacy/plugins/canvas/canvas_plugin
/x-pack/legacy/plugins/canvas/canvas_plugin_src/lib/flot-charts
/x-pack/legacy/plugins/canvas/shareable_runtime/build
/x-pack/legacy/plugins/canvas/storybook
/x-pack/legacy/plugins/canvas/canvas_plugin_src/lib/flot-charts
/x-pack/legacy/plugins/infra/common/graphql/types.ts
/x-pack/legacy/plugins/infra/public/graphql/types.ts
/x-pack/legacy/plugins/infra/server/graphql/types.ts
/x-pack/legacy/plugins/apm/e2e/cypress/**/snapshots.js
/src/legacy/plugin_discovery/plugin_pack/__tests__/fixtures/plugins/broken
**/graphql/types.ts
**/*.js.snap
!/.eslintrc.js
/x-pack/legacy/plugins/maps/public/vendor/**

# package overrides
/packages/eslint-config-kibana
/packages/kbn-interpreter/src/common/lib/grammar.js
/packages/kbn-plugin-generator/sao_template/template
/packages/kbn-pm/dist
/packages/kbn-test/src/functional_test_runner/__tests__/fixtures/
/packages/kbn-test/src/functional_test_runner/lib/config/__tests__/fixtures/
/packages/kbn-ui-framework/dist
/packages/kbn-ui-framework/doc_site/build
/packages/kbn-ui-framework/generator-kui/*/templates/

31 changes: 13 additions & 18 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
/x-pack/legacy/plugins/ingest_manager/ @elastic/ingest-management
/x-pack/plugins/observability/ @elastic/logs-metrics-ui @elastic/apm-ui @elastic/uptime @elastic/ingest-management
/x-pack/legacy/plugins/monitoring/ @elastic/stack-monitoring-ui
/x-pack/legacy/plugins/uptime @elastic/uptime
/x-pack/plugins/uptime @elastic/uptime

# Machine Learning
Expand Down Expand Up @@ -167,16 +166,13 @@
/x-pack/plugins/telemetry_collection_xpack/ @elastic/pulse

# Kibana Alerting Services
/x-pack/legacy/plugins/alerting/ @elastic/kibana-alerting-services
/x-pack/legacy/plugins/actions/ @elastic/kibana-alerting-services
/x-pack/plugins/alerting/ @elastic/kibana-alerting-services
/x-pack/plugins/actions/ @elastic/kibana-alerting-services
/x-pack/plugins/event_log/ @elastic/kibana-alerting-services
/x-pack/plugins/task_manager/ @elastic/kibana-alerting-services
/x-pack/test/alerting_api_integration/ @elastic/kibana-alerting-services
/x-pack/test/plugin_api_integration/plugins/task_manager/ @elastic/kibana-alerting-services
/x-pack/test/plugin_api_integration/test_suites/task_manager/ @elastic/kibana-alerting-services
/x-pack/legacy/plugins/triggers_actions_ui/ @elastic/kibana-alerting-services
/x-pack/plugins/triggers_actions_ui/ @elastic/kibana-alerting-services
/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/ @elastic/kibana-alerting-services
/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/ @elastic/kibana-alerting-services
Expand Down Expand Up @@ -209,22 +205,21 @@
/x-pack/plugins/watcher/ @elastic/es-ui

# Endpoint
/x-pack/plugins/endpoint/ @elastic/endpoint-app-team
/x-pack/test/api_integration/apis/endpoint/ @elastic/endpoint-app-team
/x-pack/test/endpoint_api_integration_no_ingest/ @elastic/endpoint-app-team
/x-pack/test/functional_endpoint/ @elastic/endpoint-app-team
/x-pack/test/functional_endpoint_ingest_failure/ @elastic/endpoint-app-team
/x-pack/test/functional/es_archives/endpoint/ @elastic/endpoint-app-team
/x-pack/test/plugin_functional/plugins/resolver_test/ @elastic/endpoint-app-team
/x-pack/test/plugin_functional/test_suites/resolver/ @elastic/endpoint-app-team
/x-pack/plugins/endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/api_integration/apis/endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/endpoint_api_integration_no_ingest/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/functional_endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/functional_endpoint_ingest_failure/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/functional/es_archives/endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/plugin_functional/plugins/resolver_test/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/plugin_functional/test_suites/resolver/ @elastic/endpoint-app-team @elastic/siem

# SIEM
/x-pack/legacy/plugins/siem/ @elastic/siem
/x-pack/plugins/siem/ @elastic/siem
/x-pack/test/detection_engine_api_integration @elastic/siem
/x-pack/test/api_integration/apis/siem @elastic/siem
/x-pack/plugins/case @elastic/siem
/x-pack/plugins/lists @elastic/siem
/x-pack/plugins/siem/ @elastic/siem @elastic/endpoint-app-team
/x-pack/test/detection_engine_api_integration @elastic/siem @elastic/endpoint-app-team
/x-pack/test/api_integration/apis/siem @elastic/siem @elastic/endpoint-app-team
/x-pack/plugins/case @elastic/siem @elastic/endpoint-app-team
/x-pack/plugins/lists @elastic/siem @elastic/endpoint-app-team

# Security Intelligence And Analytics
/x-pack/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics
11 changes: 3 additions & 8 deletions packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ISTANBUL_PRESET_PATH = require.resolve('@kbn/babel-preset/istanbul_preset'
const BABEL_PRESET_PATH = require.resolve('@kbn/babel-preset/webpack_preset');

const STATIC_BUNDLE_PLUGINS = [
// { id: 'data', dirname: 'data' },
{ id: 'data', dirname: 'data' },
{ id: 'kibanaReact', dirname: 'kibana_react' },
{ id: 'kibanaUtils', dirname: 'kibana_utils' },
{ id: 'esUiShared', dirname: 'es_ui_shared' },
Expand All @@ -60,13 +60,8 @@ function dynamicExternals(bundle: Bundle, context: string, request: string) {
return;
}

// don't allow any static bundle to rely on other static bundles
if (STATIC_BUNDLE_PLUGINS.some(p => bundle.id === p.id)) {
return;
}

// ignore requests that don't include a /data/public, /kibana_react/public, or
// /kibana_utils/public segment as a cheap way to avoid doing path resolution
// ignore requests that don't include a /{dirname}/public for one of our
// "static" bundles as a cheap way to avoid doing path resolution
// for paths that couldn't possibly resolve to what we're looking for
const reqToStaticBundle = STATIC_BUNDLE_PLUGINS.some(p =>
request.includes(`/${p.dirname}/public`)
Expand Down
8 changes: 8 additions & 0 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,14 @@
'@types/semver',
],
},
{
groupSlug: 'set-value',
groupName: 'set-value related packages',
packageNames: [
'set-value',
'@types/set-value',
],
},
{
groupSlug: 'sinon',
groupName: 'sinon related packages',
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/plugins/plugin.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const mockPlugin = {
};
export const mockInitializer = jest.fn(() => mockPlugin);

export const mockPluginLoader = jest.fn().mockResolvedValue(mockInitializer);
export const mockPluginReader = jest.fn(() => mockInitializer);

jest.mock('./plugin_loader', () => ({
loadPluginBundle: mockPluginLoader,
jest.mock('./plugin_reader', () => ({
read: mockPluginReader,
}));
47 changes: 14 additions & 33 deletions src/core/public/plugins/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { mockInitializer, mockPlugin, mockPluginLoader } from './plugin.test.mocks';
import { mockInitializer, mockPlugin, mockPluginReader } from './plugin.test.mocks';

import { DiscoveredPlugin } from '../../server';
import { coreMock } from '../mocks';
Expand All @@ -38,67 +38,49 @@ function createManifest(
let plugin: PluginWrapper<unknown, Record<string, unknown>>;
const opaqueId = Symbol();
const initializerContext = coreMock.createPluginInitializerContext();
const addBasePath = (path: string) => path;

beforeEach(() => {
mockPluginLoader.mockClear();
mockPluginReader.mockClear();
mockPlugin.setup.mockClear();
mockPlugin.start.mockClear();
mockPlugin.stop.mockClear();
plugin = new PluginWrapper(createManifest('plugin-a'), opaqueId, initializerContext);
});

describe('PluginWrapper', () => {
test('`load` calls loadPluginBundle', () => {
plugin.load(addBasePath);
expect(mockPluginLoader).toHaveBeenCalledWith(addBasePath, 'plugin-a');
});

test('`setup` fails if load is not called first', async () => {
await expect(plugin.setup({} as any, {} as any)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Plugin \\"plugin-a\\" can't be setup since its bundle isn't loaded."`
);
});

test('`setup` fails if plugin.setup is not a function', async () => {
mockInitializer.mockReturnValueOnce({ start: jest.fn() } as any);
await plugin.load(addBasePath);
await expect(plugin.setup({} as any, {} as any)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Instance of plugin \\"plugin-a\\" does not define \\"setup\\" function."`
);
});

test('`setup` fails if plugin.start is not a function', async () => {
mockInitializer.mockReturnValueOnce({ setup: jest.fn() } as any);
await plugin.load(addBasePath);
await expect(plugin.setup({} as any, {} as any)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Instance of plugin \\"plugin-a\\" does not define \\"start\\" function."`
);
});

test('`setup` calls initializer with initializer context', async () => {
await plugin.load(addBasePath);
await plugin.setup({} as any, {} as any);
expect(mockInitializer).toHaveBeenCalledWith(initializerContext);
});

test('`setup` calls plugin.setup with context and dependencies', async () => {
await plugin.load(addBasePath);
const context = { any: 'thing' } as any;
const deps = { otherDep: 'value' };
await plugin.setup(context, deps);
expect(mockPlugin.setup).toHaveBeenCalledWith(context, deps);
});

test('`start` fails if setup is not called first', async () => {
await plugin.load(addBasePath);
await expect(plugin.start({} as any, {} as any)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Plugin \\"plugin-a\\" can't be started since it isn't set up."`
);
});

test('`start` calls plugin.start with context and dependencies', async () => {
await plugin.load(addBasePath);
await plugin.setup({} as any, {} as any);
const context = { any: 'thing' } as any;
const deps = { otherDep: 'value' };
Expand All @@ -114,20 +96,21 @@ describe('PluginWrapper', () => {
};

let startDependenciesResolved = false;
mockPluginLoader.mockResolvedValueOnce(() => ({
setup: jest.fn(),
start: async () => {
// Add small delay to ensure startDependencies is not resolved until after the plugin instance's start resolves.
await new Promise(resolve => setTimeout(resolve, 10));
expect(startDependenciesResolved).toBe(false);
return pluginStartContract;
},
}));
await plugin.load(addBasePath);
mockPluginReader.mockReturnValueOnce(
jest.fn(() => ({
setup: jest.fn(),
start: jest.fn(async () => {
// Add small delay to ensure startDependencies is not resolved until after the plugin instance's start resolves.
await new Promise(resolve => setTimeout(resolve, 10));
expect(startDependenciesResolved).toBe(false);
return pluginStartContract;
}),
stop: jest.fn(),
}))
);
await plugin.setup({} as any, {} as any);
const context = { any: 'thing' } as any;
const deps = { otherDep: 'value' };

// Add promise callback prior to calling `start` to ensure calls in `setup` will not resolve before `start` is
// called.
const startDependenciesCheck = plugin.startDependencies.then(res => {
Expand All @@ -145,15 +128,13 @@ describe('PluginWrapper', () => {
});

test('`stop` calls plugin.stop', async () => {
await plugin.load(addBasePath);
await plugin.setup({} as any, {} as any);
await plugin.stop();
expect(mockPlugin.stop).toHaveBeenCalled();
});

test('`stop` does not fail if plugin.stop does not exist', async () => {
mockInitializer.mockReturnValueOnce({ setup: jest.fn(), start: jest.fn() } as any);
await plugin.load(addBasePath);
await plugin.setup({} as any, {} as any);
expect(() => plugin.stop()).not.toThrow();
});
Expand Down
28 changes: 9 additions & 19 deletions src/core/public/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Subject } from 'rxjs';
import { first } from 'rxjs/operators';
import { DiscoveredPlugin, PluginOpaqueId } from '../../server';
import { PluginInitializerContext } from './plugin_context';
import { loadPluginBundle } from './plugin_loader';
import { read } from './plugin_reader';
import { CoreStart, CoreSetup } from '..';

/**
Expand Down Expand Up @@ -69,7 +69,6 @@ export class PluginWrapper<
public readonly configPath: DiscoveredPlugin['configPath'];
public readonly requiredPlugins: DiscoveredPlugin['requiredPlugins'];
public readonly optionalPlugins: DiscoveredPlugin['optionalPlugins'];
private initializer?: PluginInitializer<TSetup, TStart, TPluginsSetup, TPluginsStart>;
private instance?: Plugin<TSetup, TStart, TPluginsSetup, TPluginsStart>;

private readonly startDependencies$ = new Subject<[CoreStart, TPluginsStart, TStart]>();
Expand All @@ -86,18 +85,6 @@ export class PluginWrapper<
this.optionalPlugins = discoveredPlugin.optionalPlugins;
}

/**
* Loads the plugin's bundle into the browser. Should be called in parallel with all plugins
* using `Promise.all`. Must be called before `setup`.
* @param addBasePath Function that adds the base path to a string for plugin bundle path.
*/
public async load(addBasePath: (path: string) => string) {
this.initializer = await loadPluginBundle<TSetup, TStart, TPluginsSetup, TPluginsStart>(
addBasePath,
this.name
);
}

/**
* Instantiates plugin and calls `setup` function exposed by the plugin initializer.
* @param setupContext Context that consists of various core services tailored specifically
Expand Down Expand Up @@ -146,11 +133,14 @@ export class PluginWrapper<
}

private async createPluginInstance() {
if (this.initializer === undefined) {
throw new Error(`Plugin "${this.name}" can't be setup since its bundle isn't loaded.`);
}

const instance = this.initializer(this.initializerContext);
const initializer = read(this.name) as PluginInitializer<
TSetup,
TStart,
TPluginsSetup,
TPluginsStart
>;

const instance = initializer(this.initializerContext);

if (typeof instance.setup !== 'function') {
throw new Error(`Instance of plugin "${this.name}" does not define "setup" function.`);
Expand Down
Loading

0 comments on commit 13d2482

Please sign in to comment.