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

Expose elasticsearch config schema #57655

Merged
merged 5 commits into from
Feb 21, 2020
Merged

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Feb 14, 2020

Summary

Closes #56872, #56618
Required to unblock Monitoring plugin migration.

Plugins are allowed to create a custom elasticsearch config that will be used for custom elasticsearch clients. Although I only found that monitoring allows to re-define elasticsearch config values.

// monitoring_config
import { elasticsearchSchema } from 'src/core/server';
const schema = elasticsearchSchema;
// monitoring_plugin
const config$ = config.create().pipe(map(rawConfig => new ElasticsearchConfig(rawConfig)));
// note all this logic belongs to elasticsearch service so far
const client$ = config$.pipe(map(config => elasticsearch.createClient('monitoring', config));

The current implementation is the most straightforward and there are several things that I don't like:

  • exporting elasticsearch schema and ElasticsearchConfig class increases API surface
  • elasticsearch schema and ElasticsearchConfig are tightly coupled and could not be used separately, which is not obvious.
  • it's easy to misuse config$ and ignore config updates.
  • @kbn/config-schema doesn't allow to re-write validation rules locally. YAGNI, but I can imagine such a requirement in the future.

I think we can live with it for some time, but I assume we may want to refactor this part. To get rid of ElasticsearchConfig class of to move elasticsearch config validation to the platform, for example. Should I open a discussion about it or we are okay with the current approach?

// elasticsearch config
const elasticsearchSchema = schema.object({
   //...
  clients: schema.recordOf(schema.string(), elasticsearchSchema);
});
// kibana.yml
elasticsearch.clients.monitoring.requestTimeout: 30000
// monitoring_plugin
const client$ = elasticsearch.getClient('monitoring'));

For maintainers

@mshustov mshustov added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform labels Feb 14, 2020
@mshustov mshustov requested a review from a team as a code owner February 14, 2020 08:53
@elasticmachine
Copy link
Contributor

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

@mshustov mshustov added release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v8.0.0 labels Feb 14, 2020
@joshdover
Copy link
Contributor

We could expose an Observable interface that consumes the raw config and produces clients:

// on ElasticsearchSetup
// This would automatically swap out client instances under-the-hood just like
// dataClient
createClusterClient(config$: Observable<ElasticsearchConfigType>): ClusterClient;

// in plugin code

export const config = {
  schema: schema.object({
    monitoringCluster: coreConfig.elasticsearch.schema
  })
}

class Plugin {
  setup(core) {
    const monitoringCluster = core.elasticsearch.createClusterClient$(
      this.config$.pipe(map(c => c.monitoringCluster))
    );
  }
}

@rudolf
Copy link
Contributor

rudolf commented Feb 17, 2020

I like the suggestion of a createClusterClient method.

@mshustov
Copy link
Contributor Author

@joshdover @rudolf any actionable comments to merge this PR?

@mshustov
Copy link
Contributor Author

@elasticmachine merge upstream

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.

Don't have any reason to block on this, but one suggestion might be to mark these exports as @alpha since we may (will?) change these later.

```typescript
config: {
elasticsearch: {
schema: import("@kbn/config-schema").ObjectType<{
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow api-extractor, this is ugly 🙁

@mshustov
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mshustov mshustov merged commit a08070e into elastic:master Feb 21, 2020
@mshustov mshustov deleted the issue-56872 branch February 21, 2020 08:32
mshustov added a commit to mshustov/kibana that referenced this pull request Feb 21, 2020
* expose elasticsearch config schema

* update docs

* mark export as alpha since it can be deleted

Co-authored-by: Elastic Machine <[email protected]>
jloleysens added a commit to jloleysens/kibana that referenced this pull request Feb 21, 2020
…-out-of-legacy

* 'master' of github.com:elastic/kibana: (109 commits)
  document difference between log record formats (elastic#57798)
  Expose elasticsearch config schema (elastic#57655)
  [ui/agg_response/tabify] update types for search/expressions/build_tabular_inspector_data.ts (elastic#58130)
  [SIEM] Cleans Cypress tests code (elastic#58134)
  fix: 🐛 make dev server Storybook builds work again (elastic#58188)
  Prevent core savedObjects plugin from being overridden (elastic#58193)
  Expose serverBasePath on client-side (elastic#58070)
  Fix legend sizing on area charts (elastic#58083)
  Drilldown plugin (elastic#58097)
  [skip-ci] Fix broken links to saved objects APIs in MIGRATION.md (elastic#58033)
  [ML] New Platform server shim: update datafeed routes (elastic#57739)
  Add flag for building static storybook site (elastic#58050)
  add monaco to kbn/ui-shared-deps and load required features for all uses (elastic#58075)
  [SIEM] Let us try out code owners for a little while and see what happens
  Add throttle param to Alerting readme (elastic#57609)
  [NP] Move ui/saved_objects to NP (elastic#57452)
  [Logs UI]  Fix column reordering in settings page (elastic#58104)
  Fix browser date format (elastic#57714)
  Add filter for ILM phase to Index Management (revert elastic#45486) (elastic#57402)
  Clarify Precision function in Timelion Kibana (elastic#58031)
  ...

# Conflicts:
#	x-pack/.i18nrc.json
mshustov added a commit that referenced this pull request Feb 21, 2020
* expose elasticsearch config schema

* update docs

* mark export as alpha since it can be deleted

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 21, 2020
…_improve-advanced-settings-save

* commit '02efb01c481f9f24d8d707f06dfc68b2fb805001': (43 commits)
  [Endpoint] Add a flyout to alert list. (elastic#57926)
  Make sure index pattern has fields before parsing (elastic#58242)
  Sanitize workpad before sending to API (elastic#57704)
  [ML] Transform: Support multi-line JSON notation in advanced editor (elastic#58015)
  [Endpoint] Refactor Management List Tests (elastic#58148)
  [kbn/optimizer] include bootstrap cache key in optimizer cache key (elastic#58176)
  Do not refresh color scale on each lookup (elastic#57792)
  Updating to @elastic/[email protected] (elastic#54662)
  Trigger context (elastic#57870)
  [ML] Transforms: Adds clone feature to transforms list. (elastic#57837)
  [ML] New Platform server shim: update fields service routes (elastic#58060)
  [Endpoint] EMT-184: change endpoints to metadata up and down the code base. (elastic#58038)
  document difference between log record formats (elastic#57798)
  Expose elasticsearch config schema (elastic#57655)
  [ui/agg_response/tabify] update types for search/expressions/build_tabular_inspector_data.ts (elastic#58130)
  [SIEM] Cleans Cypress tests code (elastic#58134)
  fix: 🐛 make dev server Storybook builds work again (elastic#58188)
  Prevent core savedObjects plugin from being overridden (elastic#58193)
  Expose serverBasePath on client-side (elastic#58070)
  Fix legend sizing on area charts (elastic#58083)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate cluster client with singular .hosts config does not work
5 participants