-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add new elasticsearch client #69905
Merged
pgayvallet
merged 55 commits into
elastic:master
from
pgayvallet:kbn-35508-add-new-es-client
Jul 8, 2020
Merged
Add new elasticsearch client #69905
Changes from 5 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
10f0846
add "@elastic/elasticsearch" to dependencies
pgayvallet e923ce5
first POC of new client
pgayvallet 175e0cb
add logging
pgayvallet f56a506
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 24ac36b
add generation script for client facade API and implementation
pgayvallet 024f3df
add back keepAlive
pgayvallet cfa547a
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet eecd780
add exports from client
pgayvallet 8c6c9fc
add new client mocks
pgayvallet c7a2cf1
add some doc
pgayvallet 193fecc
fix API usages
pgayvallet b8935d7
rename legacy client to legacy in service
pgayvallet f268e63
rename currently unused config/client observable
pgayvallet 73f68b8
wire new client to service & update mocks
pgayvallet 2c5a489
fix mock type
pgayvallet c7ae6aa
export client types
pgayvallet 93d05ee
add transport.request
pgayvallet 4156411
more doc
pgayvallet 5a3fd9c
migrate version_check to new client
pgayvallet 71a27bb
fix default port logic
pgayvallet e48f3ad
rename legacy client mocks
pgayvallet bdacda3
move legacy client mocks to legacy folder
pgayvallet 152b6dc
start adding tests
pgayvallet b265759
add configure_client tests
pgayvallet 9e356e8
add get_client_facade tests
pgayvallet 353253f
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 7e49f65
bump client to 7.8
pgayvallet bda204e
add cluster_client tests
pgayvallet 28b8cfc
expose new client on internal contract only
pgayvallet 8cd1ed2
revert using the new client for es version check
pgayvallet 205c100
add service level test for new client
pgayvallet 7819166
update generated API
pgayvallet d1cdb0a
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 80bfc97
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet bf18e61
Revert "rename legacy client mocks"
pgayvallet 6c4ff93
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 8a397d0
address some review comments
pgayvallet 533212b
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 0a09aee
revert ts-expect-error from unowned files
pgayvallet 1a68ea1
move response mocks to mocks.ts
pgayvallet f956fb4
Remove generated facade, use ES Client directly
pgayvallet 56db6c4
log queries even in case of error
pgayvallet d6f1c9d
nits
pgayvallet 83b7246
use direct properties instead of accessors
pgayvallet a764b10
handle async closing of client
pgayvallet 9d272ba
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 3f1d9bd
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 88ae350
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet cb242e7
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 413a97d
review nits
pgayvallet c0d7f3a
ElasticSearchClient -> ElasticsearchClient
pgayvallet 022e4a2
add test for encoded querystring
pgayvallet 0dc69b4
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet 5acfe96
adapt test file
pgayvallet f059964
Merge remote-tracking branch 'upstream/master' into kbn-35508-add-new…
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
require('../src/setup_node_env'); | ||
require('../src/dev/generate_es_client'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ConnectionOptions as TlsConnectionOptions } from 'tls'; | ||
import { URL } from 'url'; | ||
import { Duration } from 'moment'; | ||
import { ClientOptions, NodeOptions } from '@elastic/elasticsearch'; | ||
import { ElasticsearchConfig } from '../elasticsearch_config'; | ||
|
||
/** | ||
* @privateRemarks Config that consumers can pass to the Elasticsearch JS client is complex and includes | ||
* not only entries from standard `elasticsearch.*` yaml config, but also some Elasticsearch JS | ||
* client specific options like `keepAlive` or `plugins` (that eventually will be deprecated). | ||
* | ||
* @public | ||
*/ | ||
export type ElasticsearchClientConfig = Pick< | ||
ElasticsearchConfig, | ||
| 'customHeaders' | ||
| 'logQueries' | ||
| 'sniffOnStart' | ||
| 'sniffOnConnectionFault' | ||
| 'requestHeadersWhitelist' | ||
| 'sniffInterval' | ||
| 'hosts' | ||
| 'username' | ||
| 'password' | ||
> & { | ||
pingTimeout?: ElasticsearchConfig['pingTimeout'] | ClientOptions['pingTimeout']; | ||
requestTimeout?: ElasticsearchConfig['requestTimeout'] | ClientOptions['requestTimeout']; | ||
ssl?: Partial<ElasticsearchConfig['ssl']>; | ||
}; | ||
|
||
export function parseClientOptions( | ||
config: ElasticsearchClientConfig, | ||
scoped: boolean | ||
): ClientOptions { | ||
const clientOptions: ClientOptions = { | ||
sniffOnStart: config.sniffOnStart, | ||
sniffOnConnectionFault: config.sniffOnConnectionFault, | ||
headers: config.customHeaders, | ||
pgayvallet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
if (config.pingTimeout != null) { | ||
clientOptions.pingTimeout = getDurationAsMs(config.pingTimeout); | ||
} | ||
if (config.requestTimeout != null) { | ||
clientOptions.requestTimeout = getDurationAsMs(config.requestTimeout); | ||
} | ||
if (config.sniffInterval) { | ||
clientOptions.sniffInterval = getDurationAsMs(config.sniffInterval); | ||
} | ||
|
||
// TODO: this can either be done globally here or by host in convertHost. | ||
// Not sure which option is the best. | ||
if (config.username && config.password) { | ||
clientOptions.auth = { | ||
username: config.username, | ||
password: config.password, | ||
}; | ||
} | ||
|
||
clientOptions.nodes = config.hosts.map((host) => convertHost(host, !scoped, config)); | ||
|
||
if (config.ssl) { | ||
clientOptions.ssl = generateSslConfig( | ||
config.ssl, | ||
scoped && !config.ssl.alwaysPresentCertificate | ||
); | ||
} | ||
|
||
return clientOptions; | ||
} | ||
|
||
const generateSslConfig = ( | ||
sslConfig: Required<ElasticsearchClientConfig>['ssl'], | ||
ignoreCertAndKey: boolean | ||
): TlsConnectionOptions => { | ||
const ssl: TlsConnectionOptions = { | ||
ca: sslConfig.certificateAuthorities, | ||
}; | ||
|
||
const verificationMode = sslConfig.verificationMode; | ||
switch (verificationMode) { | ||
case 'none': | ||
ssl.rejectUnauthorized = false; | ||
break; | ||
case 'certificate': | ||
ssl.rejectUnauthorized = true; | ||
// by default, NodeJS is checking the server identify | ||
ssl.checkServerIdentity = () => undefined; | ||
break; | ||
case 'full': | ||
ssl.rejectUnauthorized = true; | ||
break; | ||
default: | ||
throw new Error(`Unknown ssl verificationMode: ${verificationMode}`); | ||
} | ||
|
||
// Add client certificate and key if required by elasticsearch | ||
if (!ignoreCertAndKey && sslConfig.certificate && sslConfig.key) { | ||
ssl.cert = sslConfig.certificate; | ||
ssl.key = sslConfig.key; | ||
ssl.passphrase = sslConfig.keyPassphrase; | ||
} | ||
|
||
return ssl; | ||
}; | ||
|
||
const convertHost = ( | ||
host: string, | ||
needAuth: boolean, | ||
{ username, password }: ElasticsearchClientConfig | ||
): NodeOptions => { | ||
const url = new URL(host); | ||
const isHTTPS = url.protocol === 'https:'; | ||
url.port = url.port ?? isHTTPS ? '443' : '80'; | ||
if (needAuth && username && password) { | ||
url.username = username; | ||
url.password = password; | ||
} | ||
|
||
return { | ||
url, | ||
}; | ||
}; | ||
|
||
const getDurationAsMs = (duration: number | Duration) => | ||
typeof duration === 'number' ? duration : duration.asMilliseconds(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client follows the stack versioning, meaning that using the client
7.x
in kibanamaster
will cause issues. You should use the clientmaster
branch.Currently, we are not publishing any
8.x
version on npm, but we could do it if it does help you.Here you can find the compatibility table of the client.
If you want to install the master branch of the client:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the client released separately for every Stack release? Should it be another place to sync across the Stack when bumping a Kibana version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do a release for every
major.minor
of the stack, patches are released as soon as it's needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, this may be quite problematic AFAIK, as kibana master is targeting 8.0, but the current branch (7.9 atm for example) is targeting 7.X
That means that we would need to have different versions (with potential differences in APIs) between our kibana master branch and our next-release branch?
This feels like it could become a backport nightmare, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@delvedor Can you elaborate on the typical changes between versions? If newer versions only change to support or remove new or deprecated ES functionality then this shouldn't cause any problems for us that aren't already caused by ES.
But if elasticsearch-js plans to make breaking changes to it's API signatures this adds an additional maintenance burden and we will have to migrate all code within the release timeframe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client follows semantic versioning, so there will never be a breaking change between minor or patch releases, but there might be between majors.
Minor releases are always additive, in a generic minor release you will find new ES endpoints and some additional features of the client, for example, in the last 2/3 minors, client helpers have been added.
If the client needs to do a breaking change, which can be dropping the support for a specific version of Node, remove/change a configuration option, or drop an API, that will happen in a major release.
The only parts of the client that could have a breaking change between minors are the helpers and the type definitions, which are still experimental (even if they are stable and not expected to change unless there is a very good reason).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client does prereleases as soon as there is a feature freeze, if you take a look at the published versions on npm you will see few rcs.