-
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
Elasticsearch client: no longer default to using meta: true
#124488
Elasticsearch client: no longer default to using meta: true
#124488
Conversation
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.
ML, Transforms and File Upload changes LGTM
): this; | ||
} | ||
|
||
const createMockedApi = < |
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.
We need tests for the mocks now 😄
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.
Oh, that's right 😅 . will add them
src/core/server/elasticsearch/version_check/ensure_es_version.ts
Outdated
Show resolved
Hide resolved
@@ -28,7 +28,7 @@ const methods = [ | |||
|
|||
type MethodName = typeof methods[number]; | |||
|
|||
export type RepositoryEsClient = Pick<ElasticsearchClient, MethodName>; | |||
export type RepositoryEsClient = Pick<ElasticsearchClient, MethodName | 'transport'>; |
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.
Do we really need to provide it in the RepositoryEsClient
? Is it possible to migrate from transport
to an ES method?
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.
We just need it because of the client API definition (unfortunately), we're not using it.
Removing it causes errors such as
proc [tsc] src/core/server/saved_objects/service/lib/repository.ts:2210:49 - error TS2769: No overload matches this call.
proc [tsc] Overload 1 of 3, '(this: That, params: import("/kibana/node_modules/@elastic/elasticsearch/lib/api/types").GetRequest | import("/kibana/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey").GetRequest, options?: TransportRequestOptionsWithOutMeta | undefined): Promise<...>', gave the following error.
proc [tsc] The 'this' context of type 'RepositoryEsClient' is not assignable to method's 'this' of type 'That'.
proc [tsc] Overload 2 of 3, '(this: That, params: import("/kibana/node_modules/@elastic/elasticsearch/lib/api/types").GetRequest | import("/kibana/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey").GetRequest, options?: TransportRequestOptionsWithMeta | undefined): Promise<...>', gave the following error.
proc [tsc] The 'this' context of type 'RepositoryEsClient' is not assignable to method's 'this' of type 'That'.
proc [tsc] Overload 3 of 3, '(this: That, params: import("/kibana/node_modules/@elastic/elasticsearch/lib/api/types").GetRequest | import("/kibana/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey").GetRequest, options?: TransportRequestOptions | undefined): Promise<...>', gave the following error.
proc [tsc] The 'this' context of type 'RepositoryEsClient' is not assignable to method's 'this' of type 'That'.
proc [tsc]
proc [tsc] 2210 const { body, statusCode, headers } = await this.client.get<SavedObjectsRawDocSource>
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.
Thanks a lot, @pgayvallet!
Deployment Management changes LGTM 🚀
(Logged an unrelated search profiler issue here)
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.
Fleet changes LGTM. One nit suggestion.
Nice removal of a little boilerplate, and I think it's a good breaking change 🎉 . Wonder if we should rename the asResponse
option we have on our public http client in Core to meta
to match?
x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.ts
Show resolved
Hide resolved
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.
Went through the changes owned by me. 👍 , nothing bad I could find. Thanks.
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.
file_upload and geo_containment changes lgtm!
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.
Reporting changes LGTM
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.
infra
and monitoring
changes LGTM, thank you!
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.
Tested changes to Presentation Team and everything looks and works as expected ✅
💚 Build SucceededMetrics [docs]Public APIs missing comments
Public APIs missing exports
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
A planned, merged on green CI despite having some missing reviews. |
This is not a failed rebase
Summary
Fix #116095
KibanaClient
interface in favor of the vanillaClient
meta: true
option in our client's transportWhat is this about?
The
8.0
version of@elastic/elasticsearch
changed the behavior of the client to only return thebody
by default, unless themeta: true
option is specified, in which case it returns a{ body, statusCode, headers, warnings }
struct as in did in7.x
. This was a very significant breaking change.Which is why, when we migrated to this version of the client in #113950, we decided to force the old behavior by injecting
meta: true
to all ES client calls and using our ownKibanaClient
interface shim-ing the old signatures to reduce the impact of this library upgrade in the initial PR.This PR is the direct follow up of #113950, and get rid of the
KibanaClient
interface, switch to using the behavior of a vanillaClient
, and adapt the client usages across the whole codebase to properly use the changed API.See #116095 for more context
New
ElasticsearchClient
mockTo ease the testing of the ES API, especially the behavior where the return of the client's API differs depending on the
meta
option, this PR adapts core's ES client mock to add additional mocking functions toElasticsearchClientMock
:mockResponse
mockResponseOnce
mockResponseImplementation
mockResponseImplementationOnce
These methods handle the
meta
option internally, to either only return thebody
or the wholeresponse
depending on the providedmeta
option's value.To codeowners
All usages of the client were, in theory, adapted in this PR.
Note that if some features are not properly covered by FTR tests, some usages may have been missed, as some practices can shallow typescript errors:
Record<>
based ES responses causingresponse.body
to pass validation_.get(response, 'body.X.Y')
@ts-ignore-error
usage on the line of the API callsClient
orElasticsearchClient
(e.g the APM client or ML client).js
) filesIf you are aware that some of your owned features are not properly test-covered, please focus on those during the review and double check that no client call was missed.
Regarding the test changes, I tried as much as possible to use the new client mock functions to make sure that the returns were correctly of the body or response shapes, but in some cases, such as manual mocks not using core's ES client mock, I couldn't, and had to just change the return values of the mock to return the body instead of the whole response. Improving the tests to properly use core's ES client mock is considered out of scope of this PR and should eventually be performed by the individual code owners as follow-ups, if they think it's necessary.
Checklist
Risk Matrix
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: