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 most plugins to synchronous lifecycle #89562

Merged
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
37d965a
first pass
pgayvallet Jan 28, 2021
8bd7c21
migrate more plugins
pgayvallet Jan 28, 2021
235a656
migrate yet more plugins
pgayvallet Jan 28, 2021
19f8ee0
more oss plugins
pgayvallet Jan 28, 2021
d2325e2
fix test file
pgayvallet Jan 28, 2021
1f4beba
change Plugin signature on the client-side too
pgayvallet Jan 28, 2021
7f0816a
fix test types
pgayvallet Jan 29, 2021
36e4e4a
migrate OSS client-side plugins
pgayvallet Jan 29, 2021
f7efac0
migrate OSS client-side test plugins
pgayvallet Jan 29, 2021
9162085
migrate xpack client-side plugins
pgayvallet Jan 29, 2021
08659e5
revert fix attempt on fleet plugin
pgayvallet Jan 29, 2021
86e78b0
Merge remote-tracking branch 'upstream/master' into kbn-53268-migrate…
pgayvallet Jan 29, 2021
d9d830b
fix presentation start signature
pgayvallet Jan 29, 2021
147fe61
fix yet another signature
pgayvallet Jan 29, 2021
55d0a68
add warnings for server-side async plugins in dev mode
pgayvallet Jan 29, 2021
9d775f2
remove unused import
pgayvallet Jan 29, 2021
63651af
fix isPromise
pgayvallet Jan 29, 2021
d64d04f
Add client-side deprecations
pgayvallet Jan 29, 2021
daf9db0
update migration examples
pgayvallet Jan 29, 2021
1cbb228
update generated doc
pgayvallet Jan 29, 2021
fb4cb34
fix xpack unit tests
pgayvallet Jan 29, 2021
d3a24d0
nit
pgayvallet Jan 29, 2021
fdf73fe
(will be reverted) explicitly await for license to be ready in the au…
pgayvallet Jan 29, 2021
c13d07d
Revert "(will be reverted) explicitly await for license to be ready i…
pgayvallet Jan 29, 2021
c5f2fe5
restore await on on promise contracts
pgayvallet Jan 29, 2021
59740e4
Revert "(will be reverted) explicitly await for license to be ready i…
pgayvallet Jan 29, 2021
5635487
Revert "restore await on on promise contracts"
pgayvallet Jan 29, 2021
320dd5f
add delay before starting tests in FTR
pgayvallet Jan 29, 2021
e60592f
Merge remote-tracking branch 'upstream/master' into kbn-53268-migrate…
pgayvallet Feb 1, 2021
1dcfcd9
update deprecation ts doc
pgayvallet Feb 1, 2021
b6074c7
add explicit contract for monitoring setup
pgayvallet Feb 1, 2021
d686682
Merge remote-tracking branch 'upstream/master' into kbn-53268-migrate…
pgayvallet Feb 3, 2021
3267081
migrate monitoring plugin to sync
pgayvallet Feb 3, 2021
09850d8
Merge remote-tracking branch 'upstream/master' into kbn-53268-migrate…
pgayvallet Feb 3, 2021
6a4044f
change plugin timeout to 10sec
pgayvallet Feb 3, 2021
49127b3
Merge remote-tracking branch 'upstream/master' into kbn-53268-migrate…
pgayvallet Feb 4, 2021
da51a5a
Merge remote-tracking branch 'upstream/master' into kbn-53268-migrate…
pgayvallet Feb 8, 2021
7a31a69
use delay instead of silence
pgayvallet Feb 8, 2021
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: 5 additions & 7 deletions docs/developer/plugin/migrating-legacy-plugins-examples.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,20 @@ export function plugin(initializerContext: PluginInitializerContext) {
*plugins/my_plugin/(public|server)/plugin.ts*
[source,typescript]
----
import type { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { CoreSetup, Logger, Plugin, PluginInitializerContext, PluginName } from 'kibana/server';
import type { MyPluginConfig } from './config';

export class MyPlugin implements Plugin {
private readonly config$: Observable<MyPluginConfig>;
private readonly config: MyPluginConfig;
private readonly log: Logger;

constructor(private readonly initializerContext: PluginInitializerContext) {
this.log = initializerContext.logger.get();
this.config$ = initializerContext.config.create();
this.config = initializerContext.config.get<MyPluginConfig>();
}

public async setup(core: CoreSetup, deps: Record<PluginName, unknown>) {
const isEnabled = await this.config$.pipe(first()).toPromise();
public setup(core: CoreSetup, deps: Record<PluginName, unknown>) {
const { someConfigValue } = this.config;
}
}
----
Expand All @@ -96,7 +94,7 @@ Additionally, some plugins need to access the runtime env configuration.
[source,typescript]
----
export class MyPlugin implements Plugin {
public async setup(core: CoreSetup, deps: Record<PluginName, unknown>) {
public setup(core: CoreSetup, deps: Record<PluginName, unknown>) {
const { mode: { dev }, packageInfo: { version } } = this.initializerContext.env
}
----
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AsyncPlugin](./kibana-plugin-core-public.asyncplugin.md)

## AsyncPlugin interface

> Warning: This API is now obsolete.
>
> Asynchronous lifecycles are deprecated, and should be migrated to sync
>

A plugin with asynchronous lifecycle methods.

<b>Signature:</b>

```typescript
export interface AsyncPlugin<TSetup = void, TStart = void, TPluginsSetup extends object = object, TPluginsStart extends object = object>
```

## Methods

| Method | Description |
| --- | --- |
| [setup(core, plugins)](./kibana-plugin-core-public.asyncplugin.setup.md) | |
| [start(core, plugins)](./kibana-plugin-core-public.asyncplugin.start.md) | |
| [stop()](./kibana-plugin-core-public.asyncplugin.stop.md) | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AsyncPlugin](./kibana-plugin-core-public.asyncplugin.md) &gt; [setup](./kibana-plugin-core-public.asyncplugin.setup.md)

## AsyncPlugin.setup() method

<b>Signature:</b>

```typescript
setup(core: CoreSetup<TPluginsStart, TStart>, plugins: TPluginsSetup): TSetup | Promise<TSetup>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| core | <code>CoreSetup&lt;TPluginsStart, TStart&gt;</code> | |
| plugins | <code>TPluginsSetup</code> | |

<b>Returns:</b>

`TSetup | Promise<TSetup>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AsyncPlugin](./kibana-plugin-core-public.asyncplugin.md) &gt; [start](./kibana-plugin-core-public.asyncplugin.start.md)

## AsyncPlugin.start() method

<b>Signature:</b>

```typescript
start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| core | <code>CoreStart</code> | |
| plugins | <code>TPluginsStart</code> | |

<b>Returns:</b>

`TStart | Promise<TStart>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AsyncPlugin](./kibana-plugin-core-public.asyncplugin.md) &gt; [stop](./kibana-plugin-core-public.asyncplugin.stop.md)

## AsyncPlugin.stop() method

<b>Signature:</b>

```typescript
stop?(): void;
```
<b>Returns:</b>

`void`

1 change: 1 addition & 0 deletions docs/development/core/public/kibana-plugin-core-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ApplicationStart](./kibana-plugin-core-public.applicationstart.md) | |
| [AppMeta](./kibana-plugin-core-public.appmeta.md) | Input type for meta data for an application.<!-- -->Meta fields include <code>keywords</code> and <code>searchDeepLinks</code> Keywords is an array of string with which to associate the app, must include at least one unique string as an array. <code>searchDeepLinks</code> is an array of links that represent secondary in-app locations for the app. |
| [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) | |
| [AsyncPlugin](./kibana-plugin-core-public.asyncplugin.md) | A plugin with asynchronous lifecycle methods. |
| [Capabilities](./kibana-plugin-core-public.capabilities.md) | The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled. |
| [ChromeBadge](./kibana-plugin-core-public.chromebadge.md) | |
| [ChromeBrand](./kibana-plugin-core-public.chromebrand.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
setup(core: CoreSetup<TPluginsStart, TStart>, plugins: TPluginsSetup): TSetup | Promise<TSetup>;
setup(core: CoreSetup<TPluginsStart, TStart>, plugins: TPluginsSetup): TSetup;
```

## Parameters
Expand All @@ -19,5 +19,5 @@ setup(core: CoreSetup<TPluginsStart, TStart>, plugins: TPluginsSetup): TSetup |

<b>Returns:</b>

`TSetup | Promise<TSetup>`
`TSetup`

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;
start(core: CoreStart, plugins: TPluginsStart): TStart;
```

## Parameters
Expand All @@ -19,5 +19,5 @@ start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;

<b>Returns:</b>

`TStart | Promise<TStart>`
`TStart`

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The `plugin` export at the root of a plugin's `public` directory should conform
<b>Signature:</b>

```typescript
export declare type PluginInitializer<TSetup, TStart, TPluginsSetup extends object = object, TPluginsStart extends object = object> = (core: PluginInitializerContext) => Plugin<TSetup, TStart, TPluginsSetup, TPluginsStart>;
export declare type PluginInitializer<TSetup, TStart, TPluginsSetup extends object = object, TPluginsStart extends object = object> = (core: PluginInitializerContext) => Plugin<TSetup, TStart, TPluginsSetup, TPluginsStart> | AsyncPlugin<TSetup, TStart, TPluginsSetup, TPluginsStart>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [AsyncPlugin](./kibana-plugin-core-server.asyncplugin.md)

## AsyncPlugin interface

> Warning: This API is now obsolete.
>
> Asynchronous lifecycles are deprecated, and should be migrated to sync
>

A plugin with asynchronous lifecycle methods.

<b>Signature:</b>

```typescript
export interface AsyncPlugin<TSetup = void, TStart = void, TPluginsSetup extends object = object, TPluginsStart extends object = object>
```

## Methods

| Method | Description |
| --- | --- |
| [setup(core, plugins)](./kibana-plugin-core-server.asyncplugin.setup.md) | |
| [start(core, plugins)](./kibana-plugin-core-server.asyncplugin.start.md) | |
| [stop()](./kibana-plugin-core-server.asyncplugin.stop.md) | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [AsyncPlugin](./kibana-plugin-core-server.asyncplugin.md) &gt; [setup](./kibana-plugin-core-server.asyncplugin.setup.md)

## AsyncPlugin.setup() method

<b>Signature:</b>

```typescript
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise<TSetup>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| core | <code>CoreSetup</code> | |
| plugins | <code>TPluginsSetup</code> | |

<b>Returns:</b>

`TSetup | Promise<TSetup>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [AsyncPlugin](./kibana-plugin-core-server.asyncplugin.md) &gt; [start](./kibana-plugin-core-server.asyncplugin.start.md)

## AsyncPlugin.start() method

<b>Signature:</b>

```typescript
start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| core | <code>CoreStart</code> | |
| plugins | <code>TPluginsStart</code> | |

<b>Returns:</b>

`TStart | Promise<TStart>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [AsyncPlugin](./kibana-plugin-core-server.asyncplugin.md) &gt; [stop](./kibana-plugin-core-server.asyncplugin.stop.md)

## AsyncPlugin.stop() method

<b>Signature:</b>

```typescript
stop?(): void;
```
<b>Returns:</b>

`void`

1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [AppCategory](./kibana-plugin-core-server.appcategory.md) | A category definition for nav links to know where to sort them in the left hand nav |
| [AssistanceAPIResponse](./kibana-plugin-core-server.assistanceapiresponse.md) | |
| [AssistantAPIClientParams](./kibana-plugin-core-server.assistantapiclientparams.md) | |
| [AsyncPlugin](./kibana-plugin-core-server.asyncplugin.md) | A plugin with asynchronous lifecycle methods. |
| [Authenticated](./kibana-plugin-core-server.authenticated.md) | |
| [AuthNotHandled](./kibana-plugin-core-server.authnothandled.md) | |
| [AuthRedirected](./kibana-plugin-core-server.authredirected.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise<TSetup>;
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup;
```

## Parameters
Expand All @@ -19,5 +19,5 @@ setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise<TSetup>;

<b>Returns:</b>

`TSetup | Promise<TSetup>`
`TSetup`

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;
start(core: CoreStart, plugins: TPluginsStart): TStart;
```

## Parameters
Expand All @@ -19,5 +19,5 @@ start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;

<b>Returns:</b>

`TStart | Promise<TStart>`
`TStart`

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The `plugin` export at the root of a plugin's `server` directory should conform
<b>Signature:</b>

```typescript
export declare type PluginInitializer<TSetup, TStart, TPluginsSetup extends object = object, TPluginsStart extends object = object> = (core: PluginInitializerContext) => Plugin<TSetup, TStart, TPluginsSetup, TPluginsStart>;
export declare type PluginInitializer<TSetup, TStart, TPluginsSetup extends object = object, TPluginsStart extends object = object> = (core: PluginInitializerContext) => Plugin<TSetup, TStart, TPluginsSetup, TPluginsStart> | AsyncPlugin<TSetup, TStart, TPluginsSetup, TPluginsStart>;
```
2 changes: 1 addition & 1 deletion packages/kbn-std/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export { get } from './get';
export { mapToObject } from './map_to_object';
export { merge } from './merge';
export { pick } from './pick';
export { withTimeout } from './promise';
export { withTimeout, isPromise } from './promise';
export { isRelativeUrl, modifyUrl, getUrlOrigin, URLMeaningfulParts } from './url';
export { unset } from './unset';
export { getFlattenedObject } from './get_flattened_object';
Expand Down
29 changes: 28 additions & 1 deletion packages/kbn-std/src/promise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Public License, v 1.
*/

import { withTimeout } from './promise';
import { withTimeout, isPromise } from './promise';

const delay = (ms: number, resolveValue?: any) =>
new Promise((resolve) => setTimeout(resolve, ms, resolveValue));
Expand Down Expand Up @@ -50,3 +50,30 @@ describe('withTimeout', () => {
).rejects.toMatchInlineSnapshot(`[Error: from-promise]`);
});
});

describe('isPromise', () => {
it('returns true when arg is a Promise', () => {
expect(isPromise(Promise.resolve('foo'))).toEqual(true);
expect(isPromise(Promise.reject('foo').catch(() => undefined))).toEqual(true);
});

it('returns false when arg is not a Promise', () => {
expect(isPromise(12)).toEqual(false);
expect(isPromise('foo')).toEqual(false);
expect(isPromise({ hello: 'dolly' })).toEqual(false);
expect(isPromise([1, 2, 3])).toEqual(false);
});

it('returns false for objects with a non-function `then` property', () => {
expect(isPromise({ then: 'bar' })).toEqual(false);
});

it('returns false for null and undefined', () => {
expect(isPromise(null)).toEqual(false);
expect(isPromise(undefined)).toEqual(false);
});

it('returns true for Promise-Like objects', () => {
expect(isPromise({ then: () => 12 })).toEqual(true);
});
});
4 changes: 4 additions & 0 deletions packages/kbn-std/src/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export function withTimeout<T>({
new Promise((resolve, reject) => setTimeout(() => reject(new Error(errorMessage)), timeout)),
]) as Promise<T>;
}

export function isPromise<T>(maybePromise: T | Promise<T>): maybePromise is Promise<T> {
return maybePromise ? typeof (maybePromise as Promise<T>).then === 'function' : false;
}
2 changes: 2 additions & 0 deletions packages/kbn-test/src/functional_tests/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export async function runTests(options) {
try {
es = await runElasticsearch({ config, options: opts });
await runKibanaServer({ procs, config, options: opts });
// wait 5 seconds to let kibana startup completes
await silence(log, 5000);
spalger marked this conversation as resolved.
Show resolved Hide resolved
await runFtr({ configPath, options: opts });
} finally {
try {
Expand Down
Loading