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

Provide uiSettings service in NP #48413

Merged
merged 23 commits into from
Oct 28, 2019

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Oct 16, 2019

Summary

This PR:

  • provides UiSettings service in NP. UiSettingsClient is available via RequestHanlderContext. Plugins can access register in the setup phase.
  • rename getDefaults to getRegistered. Only found usage in the core plugins and updated accordingly. I decided to update them because plugins are about to start using this API and I don't want to change public API later. uiSettings internals still uses defaults term.
  • move ui settings routes to NP
  • moves integrations tests to NP
  • add integration tests for uiSettings service
  • add typings for test_utils
  • convert other core_plugins functional tests into TS. Sorry for the additional noize.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

Dev Docs

New platform plugins can register custom uiSettings via uiSettings.register method

// src/plugins/my-plugin/server/plugin.ts
setup(core: CoreSetup){
  core.uiSettings.register({
    'my-plugin:my-setting': {
      name: 'just-work',
      value: true,
      description: 'make it work',
      category: ['my-category'],
    },
  })
}

UiSettings client can be accessed:

  • via RequestHandlerContext on server-side:
(context, req, res) {
  const uiSettingsClient = context.core.uiSettings.client;
  const value = await uiSettings.get('myPlugin:key');
  // ...
}
  • via core interface in setup/start lifecycles on the client-side:
public start({ uiSettings }) {
  const value = uiSettings.get('myPlugin:key');

@mshustov mshustov added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.6.0 labels Oct 16, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

},
elasticsearch: {
adminClient: adminClient.asScoped(req),
dataClient: dataClient.asScoped(req),
},
uiSettings: {
client: coreSetup.uiSettings.asScopedToClient(savedObjectsClient),
Copy link
Contributor Author

@mshustov mshustov Oct 16, 2019

Choose a reason for hiding this comment

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

Note: There are several reasons to pass savedObjectsClient here:

  • Consistency. All context services use the same version of the client.
  • There is no way for uiSettings to declare a dependency on the saved object service at the moment. The current dependency graph is uiSettings -- used by --> legacy -- used by --> savedObjects.
    We can work around it exposing register via start contract as well, but it's not something we want to support in the long term.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@@ -52,8 +51,17 @@ export async function createOrUpgradeSavedConfig<T extends SavedObjectAttribute
// create the new SavedConfig
await savedObjectsClient.create('config', attributes, { id: version });
} catch (error) {
if (onWriteError) {
return onWriteError(error, attributes);
if (handleWriteErrors) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I inlined this logic to improve testability.

@elasticmachine
Copy link
Contributor

💔 Build Failed

const { uiSettings } = setup();
expect(uiSettings.assertUpdateAllowed('foo')).to.be(undefined);
});
it('throws 400 Boom error when keys is overridden', () => {
Copy link
Contributor Author

@mshustov mshustov Oct 18, 2019

Choose a reason for hiding this comment

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

covered by CannotOverrideError tests

});
});

describe('#getRaw()', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

covered by getAll tests

const userProvided: UserProvided = {};

// write the userValue for each key stored in the saved object that is not overridden
for (const [key, userValue] of Object.entries(await this.read(options))) {
Copy link
Contributor Author

@mshustov mshustov Oct 18, 2019

Choose a reason for hiding this comment

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

I haven't found someone utilizing them in LP.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@mshustov mshustov requested a review from a team as a code owner October 18, 2019 09:58
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -763,7 +765,7 @@ export type IScopedClusterClient = Pick<ScopedClusterClient, 'callAsCurrentUser'
export interface IUiSettingsClient {
get: <T extends SavedObjectAttribute = any>(key: string) => Promise<T>;
getAll: <T extends SavedObjectAttribute = any>() => Promise<Record<string, T>>;
getDefaults: () => Record<string, UiSettingsParams>;
getRegistered: () => Readonly<Record<string, UiSettingsParams>>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can still keep getDefaults for BWC with 3rd party plugins. I decided we don't want to have an additional API to maintain. Any objections?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@joshdover
Copy link
Contributor

ack: will review tomorrow, sorry would have done sooner but I didn't see it in the kibana-platform project 😅

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

Renovate changes LGTM

@mshustov
Copy link
Contributor Author

@joshdover my bad 😅

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

Can you update the uiExport table in the migration guide with a link to the docs for registering a uiSetting?

src/core/server/ui_settings/types.ts Outdated Show resolved Hide resolved
src/core/server/ui_settings/types.ts Show resolved Hide resolved
requiresPageReload?: boolean;
/** a flag indicating that value cannot be changed */
readonly?: boolean;
/** defines a type of UI element {@link UiSettingsType} */
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/core/server/ui_settings/types.ts Outdated Show resolved Hide resolved
src/core/server/ui_settings/types.ts Show resolved Hide resolved
src/core/server/ui_settings/types.ts Show resolved Hide resolved
src/core/MIGRATION.md Outdated Show resolved Hide resolved
src/core/server/ui_settings/types.ts Show resolved Hide resolved
Co-Authored-By: Josh Dover <me@joshdover.com>
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@mshustov
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mshustov mshustov merged commit b6591eb into elastic:master Oct 28, 2019
@mshustov mshustov deleted the issue-44994-ui-settings branch October 28, 2019 20:12
mshustov added a commit to mshustov/kibana that referenced this pull request Oct 28, 2019
* provide ui settins client via context

* update mocks

* update types and expose setDefaults to plugins

* move ui settings routes to NP

* add typings fro test kbn server

* move integration test & improve typings

* hide client private methods, update tests

* add unit tests for get_upgradable_config

* inline writeErrors into createOrUpgradeConfig to simplify testing

* regen docs

* add functional tests for ui_settings service

* unify test suites

* add types for sipertest in core_plugin tests

* tsify core_plugins tests

* add test for empty saved config

* update renovate

* rename get/setDefaults to reguster

* regen docs

* regen docs

* Update src/core/MIGRATION.md

Co-Authored-By: Josh Dover <me@joshdover.com>
mshustov added a commit that referenced this pull request Oct 29, 2019
* provide ui settins client via context

* update mocks

* update types and expose setDefaults to plugins

* move ui settings routes to NP

* add typings fro test kbn server

* move integration test & improve typings

* hide client private methods, update tests

* add unit tests for get_upgradable_config

* inline writeErrors into createOrUpgradeConfig to simplify testing

* regen docs

* add functional tests for ui_settings service

* unify test suites

* add types for sipertest in core_plugin tests

* tsify core_plugins tests

* add test for empty saved config

* update renovate

* rename get/setDefaults to reguster

* regen docs

* regen docs

* Update src/core/MIGRATION.md

Co-Authored-By: Josh Dover <me@joshdover.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants