Elasticsearch client: no longer default to using meta: true#124488
Elasticsearch client: no longer default to using meta: true#124488pgayvallet merged 87 commits intoelastic:mainfrom
meta: true#124488Conversation
| ): this; | ||
| } | ||
|
|
||
| const createMockedApi = < |
There was a problem hiding this comment.
We need tests for the mocks now 😄
There was a problem hiding this comment.
Oh, that's right 😅 . will add them
src/core/server/elasticsearch/version_check/ensure_es_version.ts
Outdated
Show resolved
Hide resolved
| 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.
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.
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>
yuliacech
left a comment
There was a problem hiding this comment.
Thanks a lot, @pgayvallet!
Deployment Management changes LGTM 🚀
(Logged an unrelated search profiler issue here)
x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.ts
Show resolved
Hide resolved
FrankHassanabad
left a comment
There was a problem hiding this comment.
Went through the changes owned by me. 👍 , nothing bad I could find. Thanks.
nickpeihl
left a comment
There was a problem hiding this comment.
file_upload and geo_containment changes lgtm!
weltenwort
left a comment
There was a problem hiding this comment.
infra and monitoring changes LGTM, thank you!
crob611
left a comment
There was a problem hiding this comment.
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
KibanaClientinterface in favor of the vanillaClientmeta: trueoption in our client's transportWhat is this about?
The
8.0version of@elastic/elasticsearchchanged the behavior of the client to only return thebodyby default, unless themeta: trueoption 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: trueto all ES client calls and using our ownKibanaClientinterface 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
KibanaClientinterface, 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
ElasticsearchClientmockTo ease the testing of the ES API, especially the behavior where the return of the client's API differs depending on the
metaoption, this PR adapts core's ES client mock to add additional mocking functions toElasticsearchClientMock:mockResponsemockResponseOncemockResponseImplementationmockResponseImplementationOnceThese methods handle the
metaoption internally, to either only return thebodyor the wholeresponsedepending on the providedmetaoption'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.bodyto pass validation_.get(response, 'body.X.Y')@ts-ignore-errorusage on the line of the API callsClientorElasticsearchClient(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: