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

UI settings move to NP #47590

Merged
merged 31 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7d67d1c
add tests for logWithMetadata in LP
mshustov Oct 7, 2019
9d716d8
allow passing metadata to log in NP & LP
mshustov Oct 7, 2019
9de2388
move ui_settings_client to NP
mshustov Oct 8, 2019
846a19a
add ui_settings config
mshustov Oct 8, 2019
890f932
add ui_settings_service
mshustov Oct 8, 2019
7ab41d5
switch to NP logging
mshustov Oct 8, 2019
ca428cf
export types
mshustov Oct 8, 2019
a302ee0
bootstrap uiSettings service in NP
mshustov Oct 8, 2019
9a5b3bc
pass NP uiSettings to LP
mshustov Oct 8, 2019
34c30fa
move ui_settings mock to NP
mshustov Oct 8, 2019
3fde85f
add test for mixin and switch to NP logger
mshustov Oct 8, 2019
625d1e7
make UiSettingsClient.getDefaults sync as it is
mshustov Oct 8, 2019
0bbd53b
ui_settings_client uses private fields
mshustov Oct 8, 2019
c5c790e
ui_settings_client uses private methods
mshustov Oct 8, 2019
0b3c60d
keep uiSettings config validation in NP only
mshustov Oct 8, 2019
081ddad
update mocks
mshustov Oct 9, 2019
03edda9
core context should know it is mocked
mshustov Oct 9, 2019
4169d5c
add tests for ui_settings_service
mshustov Oct 9, 2019
a515643
remove unused code from ui_settings_mixin test
mshustov Oct 9, 2019
fa37fa9
improve types in ui_settings_mixin test
mshustov Oct 9, 2019
7493525
gen docs
mshustov Oct 9, 2019
481d0e5
test moved to NP
mshustov Oct 9, 2019
4b2872b
set pkg version in tests explicitly
mshustov Oct 9, 2019
72305fc
update mocks in tests
mshustov Oct 9, 2019
1090981
Merge branch 'master' into ui-settings-move-np
mshustov Oct 16, 2019
c5ddad4
UiSettingsServiceSetup --> InternalUiSettingsServiceSetup
mshustov Oct 16, 2019
cfd156e
add links to types
mshustov Oct 16, 2019
b4b081b
address eli comment
mshustov Oct 16, 2019
22b123c
Merge branch 'master' into ui-settings-move-np
mshustov Oct 16, 2019
11bc4a9
regen docs
mshustov Oct 16, 2019
bebf920
remove unused types
mshustov Oct 16, 2019
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
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ module.exports = {
'!src/core/server/index.ts',
'!src/core/server/mocks.ts',
'!src/core/server/types.ts',
// for absolute imports until fixed in
// https://github.com/elastic/kibana/issues/36096
'!src/core/server/types',
'!src/core/server/*.test.mocks.ts',

'src/plugins/**/public/**/*',
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [get](./kibana-plugin-server.iuisettingsclient.get.md)

## IUiSettingsClient.get property

Retrieves uiSettings values set by the user with fallbacks to default values if not specified.

<b>Signature:</b>

```typescript
get: <T extends SavedObjectAttribute = any>(key: string) => Promise<T>;
```
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [getAll](./kibana-plugin-server.iuisettingsclient.getall.md)

## IUiSettingsClient.getAll property

Retrieves a set of all uiSettings values set by the user with fallbacks to default values if not specified.

<b>Signature:</b>

```typescript
getAll: <T extends SavedObjectAttribute = any>() => Promise<Record<string, T>>;
```
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [getDefaults](./kibana-plugin-server.iuisettingsclient.getdefaults.md)

## IUiSettingsClient.getDefaults property

Returns uiSettings default values [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md)

<b>Signature:</b>

```typescript
getDefaults: () => Record<string, UiSettingsParams>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [getUserProvided](./kibana-plugin-server.iuisettingsclient.getuserprovided.md)

## IUiSettingsClient.getUserProvided property

Retrieves a set of all uiSettings values set by the user.

<b>Signature:</b>

```typescript
getUserProvided: <T extends SavedObjectAttribute = any>() => Promise<Record<string, {
userValue?: T;
isOverridden?: boolean;
}>>;
```
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [isOverridden](./kibana-plugin-server.iuisettingsclient.isoverridden.md)

## IUiSettingsClient.isOverridden property

Shows whether the uiSettings value set by the user.

<b>Signature:</b>

```typescript
isOverridden: (key: string) => boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md)

## IUiSettingsClient interface

Service that provides access to the UiSettings stored in elasticsearch.

<b>Signature:</b>

```typescript
export interface IUiSettingsClient
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [get](./kibana-plugin-server.iuisettingsclient.get.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;(key: string) =&gt; Promise&lt;T&gt;</code> | Retrieves uiSettings values set by the user with fallbacks to default values if not specified. |
| [getAll](./kibana-plugin-server.iuisettingsclient.getall.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;() =&gt; Promise&lt;Record&lt;string, T&gt;&gt;</code> | Retrieves a set of all uiSettings values set by the user with fallbacks to default values if not specified. |
| [getDefaults](./kibana-plugin-server.iuisettingsclient.getdefaults.md) | <code>() =&gt; Record&lt;string, UiSettingsParams&gt;</code> | Returns uiSettings default values [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) |
| [getUserProvided](./kibana-plugin-server.iuisettingsclient.getuserprovided.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;() =&gt; Promise&lt;Record&lt;string, {</code><br/><code> userValue?: T;</code><br/><code> isOverridden?: boolean;</code><br/><code> }&gt;&gt;</code> | Retrieves a set of all uiSettings values set by the user. |
| [isOverridden](./kibana-plugin-server.iuisettingsclient.isoverridden.md) | <code>(key: string) =&gt; boolean</code> | Shows whether the uiSettings value set by the user. |
| [remove](./kibana-plugin-server.iuisettingsclient.remove.md) | <code>(key: string) =&gt; Promise&lt;void&gt;</code> | Removes uiSettings value by key. |
| [removeMany](./kibana-plugin-server.iuisettingsclient.removemany.md) | <code>(keys: string[]) =&gt; Promise&lt;void&gt;</code> | Removes multiple uiSettings values by keys. |
| [set](./kibana-plugin-server.iuisettingsclient.set.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;(key: string, value: T) =&gt; Promise&lt;void&gt;</code> | Writes uiSettings value and marks it as set by the user. |
| [setMany](./kibana-plugin-server.iuisettingsclient.setmany.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;(changes: Record&lt;string, T&gt;) =&gt; Promise&lt;void&gt;</code> | Writes multiple uiSettings values and marks them as set by the user. |

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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [remove](./kibana-plugin-server.iuisettingsclient.remove.md)

## IUiSettingsClient.remove property

Removes uiSettings value by key.

<b>Signature:</b>

```typescript
remove: (key: string) => Promise<void>;
```
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [removeMany](./kibana-plugin-server.iuisettingsclient.removemany.md)

## IUiSettingsClient.removeMany property

Removes multiple uiSettings values by keys.

<b>Signature:</b>

```typescript
removeMany: (keys: string[]) => Promise<void>;
```
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [set](./kibana-plugin-server.iuisettingsclient.set.md)

## IUiSettingsClient.set property

Writes uiSettings value and marks it as set by the user.

<b>Signature:</b>

```typescript
set: <T extends SavedObjectAttribute = any>(key: string, value: T) => Promise<void>;
```
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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [setMany](./kibana-plugin-server.iuisettingsclient.setmany.md)

## IUiSettingsClient.setMany property

Writes multiple uiSettings values and marks them as set by the user.

<b>Signature:</b>

```typescript
setMany: <T extends SavedObjectAttribute = any>(changes: Record<string, T>) => Promise<void>;
```
3 changes: 3 additions & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) | A tiny abstraction for TCP socket. |
| [IndexSettingsDeprecationInfo](./kibana-plugin-server.indexsettingsdeprecationinfo.md) | |
| [IRouter](./kibana-plugin-server.irouter.md) | Registers route handlers for specified resource path and method. See [RouteConfig](./kibana-plugin-server.routeconfig.md) and [RequestHandler](./kibana-plugin-server.requesthandler.md) for more information about arguments to route registrations. |
| [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) | Service that provides access to the UiSettings stored in elasticsearch. |
| [KibanaRequestRoute](./kibana-plugin-server.kibanarequestroute.md) | Request specific route information exposed to a handler. |
| [LegacyRequest](./kibana-plugin-server.legacyrequest.md) | |
| [LegacyServiceSetupDeps](./kibana-plugin-server.legacyservicesetupdeps.md) | |
Expand Down Expand Up @@ -111,6 +112,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SessionStorage](./kibana-plugin-server.sessionstorage.md) | Provides an interface to store and retrieve data across requests. |
| [SessionStorageCookieOptions](./kibana-plugin-server.sessionstoragecookieoptions.md) | Configuration used to create HTTP session storage based on top of cookie mechanism. |
| [SessionStorageFactory](./kibana-plugin-server.sessionstoragefactory.md) | SessionStorage factory to bind one to an incoming request |
| [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) | UiSettings parameters defined by the plugins. |

## Variables

Expand Down Expand Up @@ -162,4 +164,5 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectAttributeSingle](./kibana-plugin-server.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) |
| [SavedObjectsClientContract](./kibana-plugin-server.savedobjectsclientcontract.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state.<!-- -->\#\# SavedObjectsClient errors<!-- -->Since the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:<!-- -->1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md)<!-- -->Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the <code>isXYZError()</code> helpers exposed at <code>SavedObjectsErrorHelpers</code> should be used to understand and manage error responses from the <code>SavedObjectsClient</code>.<!-- -->Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for <code>error.body.error.type</code> or doing substring checks on <code>error.body.error.reason</code>, just use the helpers to understand the meaning of the error:<!-- -->\`\`\`<!-- -->js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }<!-- -->if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }<!-- -->// always rethrow the error unless you handle it throw error; \`\`\`<!-- -->\#\#\# 404s from missing index<!-- -->From the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.<!-- -->At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.<!-- -->From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.<!-- -->\#\#\# 503s from missing index<!-- -->Unlike all other methods, create requests are supposed to succeed even when the Kibana index does not exist because it will be automatically created by elasticsearch. When that is not the case it is because Elasticsearch's <code>action.auto_create_index</code> setting prevents it from being created automatically so we throw a special 503 with the intention of informing the user that their Elasticsearch settings need to be updated.<!-- -->See [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) See [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) |
| [SavedObjectsClientWrapperFactory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) | Describes the factory used to create instances of Saved Objects Client Wrappers. |
| [UiSettingsType](./kibana-plugin-server.uisettingstype.md) | UI element type to represent the settings. |

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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [category](./kibana-plugin-server.uisettingsparams.category.md)

## UiSettingsParams.category property

used to group the configured setting in the UI

<b>Signature:</b>

```typescript
category: string[];
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [description](./kibana-plugin-server.uisettingsparams.description.md)

## UiSettingsParams.description property

description provided to a user in UI

<b>Signature:</b>

```typescript
description: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md)

## UiSettingsParams interface

UiSettings parameters defined by the plugins.

<b>Signature:</b>

```typescript
export interface UiSettingsParams
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [category](./kibana-plugin-server.uisettingsparams.category.md) | <code>string[]</code> | used to group the configured setting in the UI |
| [description](./kibana-plugin-server.uisettingsparams.description.md) | <code>string</code> | description provided to a user in UI |
| [name](./kibana-plugin-server.uisettingsparams.name.md) | <code>string</code> | title in the UI |
| [optionLabels](./kibana-plugin-server.uisettingsparams.optionlabels.md) | <code>Record&lt;string, string&gt;</code> | text labels for 'select' type UI element |
| [options](./kibana-plugin-server.uisettingsparams.options.md) | <code>string[]</code> | a range of valid values |
| [readonly](./kibana-plugin-server.uisettingsparams.readonly.md) | <code>boolean</code> | a flag indicating that value cannot be changed |
| [requiresPageReload](./kibana-plugin-server.uisettingsparams.requirespagereload.md) | <code>boolean</code> | a flag indicating whether new value applying requires page reloading |
| [type](./kibana-plugin-server.uisettingsparams.type.md) | <code>UiSettingsType</code> | defines a type of UI element [UiSettingsType](./kibana-plugin-server.uisettingstype.md) |
| [value](./kibana-plugin-server.uisettingsparams.value.md) | <code>SavedObjectAttribute</code> | default value to fall back to if a user doesn't provide any |

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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [name](./kibana-plugin-server.uisettingsparams.name.md)

## UiSettingsParams.name property

title in the UI

<b>Signature:</b>

```typescript
name: string;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [optionLabels](./kibana-plugin-server.uisettingsparams.optionlabels.md)

## UiSettingsParams.optionLabels property

text labels for 'select' type UI element

<b>Signature:</b>

```typescript
optionLabels?: Record<string, string>;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [options](./kibana-plugin-server.uisettingsparams.options.md)

## UiSettingsParams.options property

a range of valid values

<b>Signature:</b>

```typescript
options?: string[];
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [readonly](./kibana-plugin-server.uisettingsparams.readonly.md)

## UiSettingsParams.readonly property

a flag indicating that value cannot be changed

<b>Signature:</b>

```typescript
readonly?: boolean;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [requiresPageReload](./kibana-plugin-server.uisettingsparams.requirespagereload.md)

## UiSettingsParams.requiresPageReload property

a flag indicating whether new value applying requires page reloading

<b>Signature:</b>

```typescript
requiresPageReload?: boolean;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [type](./kibana-plugin-server.uisettingsparams.type.md)

## UiSettingsParams.type property

defines a type of UI element [UiSettingsType](./kibana-plugin-server.uisettingstype.md)

<b>Signature:</b>

```typescript
type?: UiSettingsType;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [value](./kibana-plugin-server.uisettingsparams.value.md)

## UiSettingsParams.value property

default value to fall back to if a user doesn't provide any

<b>Signature:</b>

```typescript
value: SavedObjectAttribute;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsType](./kibana-plugin-server.uisettingstype.md)

## UiSettingsType type

UI element type to represent the settings.

<b>Signature:</b>

```typescript
export declare type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string';
```
Loading