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

Don't expose Elasticsearch client as Observable #53824

Merged
merged 14 commits into from
Jan 8, 2020

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Dec 27, 2019

Summary

Closes #53267
TODO:

  • decide whether we want to use observables internally in context.
  • decide whether we want to maintain both admin & data client
    see related discussion in the parent task.

Checklist

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

For maintainers

Dev docs

Elasticsearch clients aren't exposed via the Observable interface anymore. Elasticsearch client provides a static API that handles all elasticsearch config updates under the hood, transparent to the end-user.

const client = core.elasticsearch.dataClient;
const data = await client.callAsInternalUser('endpoint');

@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 Dec 27, 2019
@elasticmachine
Copy link
Contributor

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

@mshustov mshustov marked this pull request as ready for review December 30, 2019 09:33
@mshustov mshustov requested review from a team as code owners December 30, 2019 09:33
Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Security/Spaces changes LGTM.

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

This seems definitely better in term of developer experience.

this.adminClient = await core.elasticsearch.adminClient$.pipe(first()).toPromise();
this.adminClient = core.elasticsearch.adminClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

Proof by usage that the PR was needed.

src/core/server/elasticsearch/cluster_client.ts Outdated Show resolved Hide resolved
Comment on lines -65 to +100
createSetupContract: createSetupContractMock,
createInternalSetup: createInternalSetupContractMock,
createSetup: createSetupContractMock,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'm in favor of this 'new' naming without the contract suffix, however this is inconsistent with every other service mocks we got. Should we decide to go with this and change the others when we can?

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 think we should unify this naming. Right now we have inconsistency across the codebase. example
Should we add this to NP conventions and fix all the mocks?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is minor, but I think we should

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created #54229

Comment on lines +113 to +117
async callAsCurrentUser(
endpoint: string,
clientParams: Record<string, any> = {},
options?: CallAPIOptions
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: does explicitly typing the clients to IClusterClient avoid to redefine the callAsXXXUser parameter types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. TS complaints Parameter '...' implicitly has an 'any' type

Copy link
Contributor

Choose a reason for hiding this comment

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

😞

Comment on lines +73 to +80
it('returns data and admin client as a part of the contract', async () => {
const mockAdminClusterClientInstance = elasticsearchServiceMock.createClusterClient();
const mockDataClusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);

const setupContract = await elasticsearchService.setup(deps);
Copy link
Contributor

@pgayvallet pgayvallet Jan 6, 2020

Choose a reason for hiding this comment

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

Do we have any reasons to keep this now? (the filter I mean. Comment is unrelated to the actual test file)

filter(() => {
if (this.subscription !== undefined) {
this.log.error('Clients cannot be changed after they are created');
return false;
}
return true;
}),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand, our code is ready for runtime config updates, but we don't have such requirements at the moment.

@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 56041f0 into elastic:master Jan 8, 2020
@mshustov mshustov deleted the issue-53267-no-more-observables branch January 8, 2020 09:01
mshustov added a commit to mshustov/kibana that referenced this pull request Jan 8, 2020
* expose ES clients without observables

* expose observable-less api to plugins

* update core api and mocks

* update plugins

* NP SO & legacy use updated API

* update SO tests

* update TSDocs

* update types

* update docs

* document createCluster analog in np

* typo
mshustov added a commit that referenced this pull request Jan 8, 2020
* expose ES clients without observables

* expose observable-less api to plugins

* update core api and mocks

* update plugins

* NP SO & legacy use updated API

* update SO tests

* update TSDocs

* update types

* update docs

* document createCluster analog in np

* typo
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 8, 2020
* master: (55 commits)
  [ui/public/utils] Copy rarely used items to where they are consumed (elastic#53819)
  set AppArch team as an owner of the search endpoints (elastic#54131)
  Don't expose Elasticsearch client as Observable (elastic#53824)
  [SIEM] Cleanup unnecessary use of enzyme-to-json (elastic#53980)
  fix ui exports doc (elastic#54138)
  change markdown element title (elastic#54194)
  [Logs UI] Refactor log position to hooks (elastic#53540)
  [SIEM] Implement NP Plugin Setup (elastic#54030)
  [DOCS] Updates ML links (elastic#53613)
  sort renovate packages in config
  Spaces - fix flakey api tests (elastic#54154)
  Remove dependency that was causing effect to re-execute infinitely. (elastic#54160)
  [dev/run] expose unexpected flags as more than just names (elastic#54080)
  [DOCS] Moves index pattern doc to Discover (elastic#53347)
  [SIEM] Cleanup React imports (elastic#53981)
  Update eslint related packages (elastic#54107)
  [Uptime] Added date range filter into expanded list query (elastic#52609)
  [SIEM] Add react/display-name eslint rule (elastic#53107)
  [SIEM] Enable eslint prefer-template rule (elastic#53983)
  Elasticsearch snapshots automation (elastic#53706)
  ...
mbondyra added a commit to mbondyra/kibana that referenced this pull request Jan 8, 2020
….com:mbondyra/kibana into IS-50036_show-sum-for-a-field-with-formatter

* 'IS-50036_show-sum-for-a-field-with-formatter' of github.com:mbondyra/kibana:
  [Telemetry] Fix license page crashing on telemetry.enabled: fa… (elastic#54174)
  [ui/public/utils] Copy rarely used items to where they are consumed (elastic#53819)
  set AppArch team as an owner of the search endpoints (elastic#54131)
  Don't expose Elasticsearch client as Observable (elastic#53824)
  [SIEM] Cleanup unnecessary use of enzyme-to-json (elastic#53980)
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Sorry for the late review :(

@rudolf
Copy link
Contributor

rudolf commented Jan 9, 2020

Oh ignore me, I missed the publishReplay(1)

),
publishReplay(1)
) as ConnectableObservable<CoreClusterClients>;

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:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. 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.

[Core] Don't expose Elasticsearch client as Observable
6 participants