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

Introduce preboot lifecycle stage #103636

Merged
merged 21 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6751a1c
Implement `preboot` lifecycle stage.
azasypkin Jul 7, 2021
ef6b84d
Update example plugin and code ownership.
azasypkin Jul 12, 2021
4c5b03d
Expose `basePath` service to `preboot` plugins.
azasypkin Jul 12, 2021
3865b2e
Review#1: handle review feedback (better types and nits).
azasypkin Jul 13, 2021
f042ff8
Review#1: keep both `setup` and `preboot` methods in `EnvironmentServ…
azasypkin Jul 13, 2021
e9ffa9c
Review#1: use clearer reason for the configuration reload during preb…
azasypkin Jul 14, 2021
adb070d
Update usage collection integration test.
azasypkin Jul 14, 2021
bf16f85
Fix xpack_legacy and apm tests,
azasypkin Jul 14, 2021
3366592
Use separate `PluginSystem` instances for preboot and standard plugins.
azasypkin Jul 14, 2021
428d8b6
Merge branch 'master' into issue-xxx-preboot-poc
azasypkin Jul 15, 2021
36f6eef
Review#1: dont try to stop `preboot` plugins system twice.
azasypkin Jul 15, 2021
d90a252
Review#1: dont try to stop `preboot` HTTP server twice.
azasypkin Jul 15, 2021
496edc5
Update latest ingegration tests from upstream.
azasypkin Jul 15, 2021
53662b8
Add basic `preboot` HTTP server intergration tests.
azasypkin Jul 15, 2021
ded628f
Review#2: limit a number of ES config fields we expose to preboot plu…
azasypkin Jul 16, 2021
c3b8ede
Review#2: implement `UiSettingsDefaultsClient`.
azasypkin Jul 16, 2021
f3ed02d
Review#2: skip plugin start if `config.initialize` is not set.
azasypkin Jul 16, 2021
5a04d48
Merge branch 'master' into issue-xxx-preboot-poc
azasypkin Jul 16, 2021
ac78c45
Review#3: improve `PluginsService` tests.
azasypkin Jul 16, 2021
89ffdb8
Merge branch 'master' into issue-xxx-preboot-poc
azasypkin Jul 19, 2021
2d27ce4
Review#3: fix typos in docs and error message.
azasypkin Jul 19, 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
10 changes: 6 additions & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@
#CC# /x-pack/plugins/translations/ @elastic/kibana-localization @elastic/kibana-core

# Security
/src/core/server/csp/ @elastic/kibana-security @elastic/kibana-core
/src/core/server/csp/ @elastic/kibana-security @elastic/kibana-core
/src/plugins/security_oss/ @elastic/kibana-security
/src/plugins/spaces_oss/ @elastic/kibana-security
/src/plugins/user_setup/ @elastic/kibana-security
/test/security_functional/ @elastic/kibana-security
/x-pack/plugins/spaces/ @elastic/kibana-security
/x-pack/plugins/encrypted_saved_objects/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/plugins/spaces/ @elastic/kibana-security
/x-pack/plugins/encrypted_saved_objects/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/test/api_integration/apis/security/ @elastic/kibana-security
/x-pack/test/ui_capabilities/ @elastic/kibana-security
/x-pack/test/encrypted_saved_objects_api_integration/ @elastic/kibana-security
Expand All @@ -265,6 +265,8 @@
/x-pack/test/security_functional/ @elastic/kibana-security
/x-pack/test/spaces_api_integration/ @elastic/kibana-security
/x-pack/test/saved_object_api_integration/ @elastic/kibana-security
/src/core/server/csp/ @elastic/kibana-security @elastic/kibana-core
/examples/preboot_example/ @elastic/kibana-security @elastic/kibana-core
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget to remove this file when backporting the PR to 7.x

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do, thanks for the note! We need to agree if we want to backport this though - we need this only for 8.0, but I can imagine how problematic other 7.x Core-related backports will become if we don't backport.

#CC# /x-pack/plugins/security/ @elastic/kibana-security

# Kibana Alerting Services
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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; [CorePreboot](./kibana-plugin-core-server.corepreboot.md) &gt; [elasticsearch](./kibana-plugin-core-server.corepreboot.elasticsearch.md)

## CorePreboot.elasticsearch property

[ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md)

<b>Signature:</b>

```typescript
elasticsearch: ElasticsearchServicePreboot;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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; [CorePreboot](./kibana-plugin-core-server.corepreboot.md) &gt; [http](./kibana-plugin-core-server.corepreboot.http.md)

## CorePreboot.http property

[HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md)

<b>Signature:</b>

```typescript
http: HttpServicePreboot;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- 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; [CorePreboot](./kibana-plugin-core-server.corepreboot.md)

## CorePreboot interface

Context passed to the `setup` method of `preboot` plugins.

<b>Signature:</b>

```typescript
export interface CorePreboot
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [elasticsearch](./kibana-plugin-core-server.corepreboot.elasticsearch.md) | <code>ElasticsearchServicePreboot</code> | [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md) |
| [http](./kibana-plugin-core-server.corepreboot.http.md) | <code>HttpServicePreboot</code> | [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md) |
| [preboot](./kibana-plugin-core-server.corepreboot.preboot.md) | <code>PrebootServicePreboot</code> | [PrebootServicePreboot](./kibana-plugin-core-server.prebootservicepreboot.md) |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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; [CorePreboot](./kibana-plugin-core-server.corepreboot.md) &gt; [preboot](./kibana-plugin-core-server.corepreboot.preboot.md)

## CorePreboot.preboot property

[PrebootServicePreboot](./kibana-plugin-core-server.prebootservicepreboot.md)

<b>Signature:</b>

```typescript
preboot: PrebootServicePreboot;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## CoreSetup interface

Context passed to the plugins `setup` method.
Context passed to the `setup` method of `standard` plugins.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface DiscoveredPlugin
| [optionalPlugins](./kibana-plugin-core-server.discoveredplugin.optionalplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
| [requiredBundles](./kibana-plugin-core-server.discoveredplugin.requiredbundles.md) | <code>readonly PluginName[]</code> | List of plugin ids that this plugin's UI code imports modules from that are not in <code>requiredPlugins</code>. |
| [requiredPlugins](./kibana-plugin-core-server.discoveredplugin.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |
| [type](./kibana-plugin-core-server.discoveredplugin.type.md) | <code>PluginType</code> | Type of the plugin, defaults to <code>standard</code>. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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; [DiscoveredPlugin](./kibana-plugin-core-server.discoveredplugin.md) &gt; [type](./kibana-plugin-core-server.discoveredplugin.type.md)

## DiscoveredPlugin.type property

Type of the plugin, defaults to `standard`<!-- -->.

<b>Signature:</b>

```typescript
readonly type: PluginType;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- 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; [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md) &gt; [config](./kibana-plugin-core-server.elasticsearchservicepreboot.config.md)

## ElasticsearchServicePreboot.config property

Default Elasticsearch config.

<b>Signature:</b>

```typescript
readonly config: ElasticsearchConfig;
```

## Example


```js
const defaultConfig = core.elasticsearch.config;

```

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; [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md) &gt; [createClient](./kibana-plugin-core-server.elasticsearchservicepreboot.createclient.md)

## ElasticsearchServicePreboot.createClient property

Create application specific Elasticsearch cluster API client with customized config. See [IClusterClient](./kibana-plugin-core-server.iclusterclient.md)<!-- -->.

<b>Signature:</b>

```typescript
readonly createClient: (type: string, clientConfig?: Partial<ElasticsearchClientConfig>) => ICustomClusterClient;
```

## Example


```js
const client = elasticsearch.createClient('my-app-name', config);
const data = await client.asInternalUser.search();

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- 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; [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md)

## ElasticsearchServicePreboot interface


<b>Signature:</b>

```typescript
export interface ElasticsearchServicePreboot
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [config](./kibana-plugin-core-server.elasticsearchservicepreboot.config.md) | <code>ElasticsearchConfig</code> | Default Elasticsearch config. |
| [createClient](./kibana-plugin-core-server.elasticsearchservicepreboot.createclient.md) | <code>(type: string, clientConfig?: Partial&lt;ElasticsearchClientConfig&gt;) =&gt; ICustomClusterClient</code> | Create application specific Elasticsearch cluster API client with customized config. See [IClusterClient](./kibana-plugin-core-server.iclusterclient.md)<!-- -->. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!-- 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; [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md)

## HttpServicePreboot interface

Kibana HTTP Service provides an abstraction to work with the HTTP stack at the `preboot` stage. This functionality allows Kibana to serve user requests even before Kibana becomes fully operational. Only Core and `preboot` plugins can define HTTP routes at this stage.

<b>Signature:</b>

```typescript
export interface HttpServicePreboot
```

## Example

To handle an incoming request in your preboot plugin you should: - Use `@kbn/config-schema` package to create a schema to validate the request `params`<!-- -->, `query`<!-- -->, and `body`<!-- -->. Every incoming request will be validated against the created schema. If validation failed, the request is rejected with `400` status and `Bad request` error without calling the route's handler. To opt out of validating the request, specify `false`<!-- -->.

```ts
import { schema, TypeOf } from '@kbn/config-schema';
const validate = {
params: schema.object({
id: schema.string(),
}),
};

```
- Declare a function to respond to incoming request. The function will receive `request` object containing request details: url, headers, matched route, as well as validated `params`<!-- -->, `query`<!-- -->, `body`<!-- -->. And `response` object instructing HTTP server to create HTTP response with information sent back to the client as the response body, headers, and HTTP status. Any exception raised during the handler call will generate `500 Server error` response and log error details for further investigation. See below for returning custom error responses.

```ts
const handler = async (context: RequestHandlerContext, request: KibanaRequest, response: ResponseFactory) => {
const data = await findObject(request.params.id);
// creates a command to respond with 'not found' error
if (!data) {
return response.notFound();
}
// creates a command to send found data to the client and set response headers
return response.ok({
body: data,
headers: { 'content-type': 'application/json' }
});
}

```
\* - Acquire `preboot` [IRouter](./kibana-plugin-core-server.irouter.md) instance and register route handler for GET request to 'path/<!-- -->{<!-- -->id<!-- -->}<!-- -->' path.

```ts
import { schema, TypeOf } from '@kbn/config-schema';

const validate = {
params: schema.object({
id: schema.string(),
}),
};

httpPreboot.registerRoutes('my-plugin', (router) => {
router.get({ path: 'path/{id}', validate }, async (context, request, response) => {
const data = await findObject(request.params.id);
if (!data) {
return response.notFound();
}
return response.ok({
body: data,
headers: { 'content-type': 'application/json' }
});
});
});

```

## Methods

| Method | Description |
| --- | --- |
| [registerRoutes(path, callback)](./kibana-plugin-core-server.httpservicepreboot.registerroutes.md) | Provides ability to acquire <code>preboot</code> [IRouter](./kibana-plugin-core-server.irouter.md) instance for a particular top-level path and register handler functions for any number of nested routes. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- 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; [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md) &gt; [registerRoutes](./kibana-plugin-core-server.httpservicepreboot.registerroutes.md)

## HttpServicePreboot.registerRoutes() method

Provides ability to acquire `preboot` [IRouter](./kibana-plugin-core-server.irouter.md) instance for a particular top-level path and register handler functions for any number of nested routes.

<b>Signature:</b>

```typescript
registerRoutes(path: string, callback: (router: IRouter) => void): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| path | <code>string</code> | |
| callback | <code>(router: IRouter) =&gt; void</code> | |

<b>Returns:</b>

`void`

## Remarks

Each route can have only one handler function, which is executed when the route is matched. See the [IRouter](./kibana-plugin-core-server.irouter.md) documentation for more information.

## Example


```ts
registerRoutes('my-plugin', (router) => {
// handler is called when '/my-plugin/path' resource is requested with `GET` method
router.get({ path: '/path', validate: false }, (context, req, res) => res.ok({ content: 'ok' }));
});

```

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## KibanaExecutionContext.id property

unique value to indentify find the source
unique value to identify the source

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface KibanaExecutionContext
| Property | Type | Description |
| --- | --- | --- |
| [description](./kibana-plugin-core-server.kibanaexecutioncontext.description.md) | <code>string</code> | human readable description. For example, a vis title, action name |
| [id](./kibana-plugin-core-server.kibanaexecutioncontext.id.md) | <code>string</code> | unique value to indentify find the source |
| [id](./kibana-plugin-core-server.kibanaexecutioncontext.id.md) | <code>string</code> | unique value to identify the source |
| [name](./kibana-plugin-core-server.kibanaexecutioncontext.name.md) | <code>string</code> | public name of a user-facing feature |
| [type](./kibana-plugin-core-server.kibanaexecutioncontext.type.md) | <code>string</code> | Kibana application initated an operation. Can be narrowed to an enum later. |
| [url](./kibana-plugin-core-server.kibanaexecutioncontext.url.md) | <code>string</code> | in browser - url to navigate to a current page, on server - endpoint path, for task: task SO url |
Expand Down
Loading