-
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
[KP] use new ES client in SO service #72289
Conversation
We are aware of this, unfortunately, the rest-api-spec is not complete in that regard. We are working for improving the situation, I'll keep you posted.
We are using the rest-api-spec for generating the types, and as you can see they are listed as strings. I agree that it should be
This is how it's defined in the rest-api-spec, I'll ping the ES team for understanding if it's correct or is missing an option.
The client is not doing anything with the Elasticsearch response, so if a field is missing, it means that ES is not sending it out.
This is a bug in the types, I'll fix it :)
This is "correct", as import { ApiResponse } from './'
import { TransportRequestPromise } from './lib/Transport'
async function logError (fn: () => TransportRequestPromise<ApiResponse>): Promise<ApiResponse> {
try{
return await fn()
} catch(e){
console.log(e)
throw e
}
}
This is a fun one :P |
Pinging @elastic/kibana-platform (Team:Platform) |
Pinging @elastic/apm-ui (Team:apm) |
Pinging @elastic/ingest-management (Team:Ingest Management) |
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.
APM 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.
Some nits and comments, overall LGTM
@@ -109,6 +109,7 @@ export { | |||
LegacyAPICaller, | |||
FakeRequest, | |||
ScopeableRequest, | |||
ElasticsearchClient, |
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.
NIT: Why exposing it now? Should we wait until we officially exposes the API to plugins?
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.
I used it in the integration tests.
const esClient = getService('es'); |
I don't want to expose raw Client there. Also, exposing a type doesn't hurt us a lot.
src/core/server/saved_objects/service/lib/repository_es_client.ts
Outdated
Show resolved
Hide resolved
src/core/server/saved_objects/migrations/core/elastic_index.test.ts
Outdated
Show resolved
Hide resolved
src/core/server/saved_objects/migrations/core/index_migrator.test.ts
Outdated
Show resolved
Hide resolved
const deleteDocNotFound = deleteResponse.result === 'not_found'; | ||
const deleteIndexNotFound = | ||
deleteResponse.error && deleteResponse.error.type === 'index_not_found_exception'; | ||
const deleteDocNotFound = body.result === 'not_found'; |
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.
It was already like that, but wouldn't check on statusCode be better?
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.
I didn't want to take a risk to change this code without talking to an author. From the source code, it seems that there could be different reasons for Not found
response https://github.com/elastic/elasticsearch/blob/b7062391452dbe82c552fa2bb2d5a31f64667b1d/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java
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.
Upgrade Assistant changes LGTM, didn't test locally.
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.
Ingest Manager changes LGTM
@@ -56,7 +56,7 @@ export const createEndpointList = async ({ | |||
); | |||
return transformSavedObjectToExceptionList({ savedObject }); | |||
} catch (err) { | |||
if (err.status === 409) { |
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.
TODO: to make sure it's listed in the migration guide
💚 Build SucceededBuild metrics
History
To update your PR or re-run it, just comment with: |
* adapt retryCallCluster for new ES client * review comments * retry on 408 ResponseError * remove legacy retry functions * use Migrator Es client in SO migration * update migration tests * improve ES typings and mocks * migrate decorate ES errors * add repository es client * use new es client in so repository * update repository tests * fix migrator integration tests * declare _seq_no & _primary_term on get response. _source expect to be a string * make _sourceIncludes and refresh compatible with the client * add test for repository_es_client * move ApiResponse to es client mocks * TEMP: handle wait_for as true for deleteByNamespace * add tests for migration_es_client * TEMP: skip test for deleteByNamespace refresh * pass ignore as transport option in mget * log both es client and response errors * fix update method test failures * update deleteByNamespace refresh settings es doesn't support 'refresh: wait_for' for `updateByQuery` endpoint * update repository tests. we do not allow customising wait_for * do not delegate retry logic to es client * fix type errors after master merged * fix repository tests * fix security solutions code SO doesn't throw Error with status code anymore. Always use SO error helpers * switch error conditions to use SO error helpers * cleanup * address comments about mocks * use isResponseError helper * address comments * fix type errors Co-authored-by: pgayvallet <[email protected]>
* adapt retryCallCluster for new ES client * review comments * retry on 408 ResponseError * remove legacy retry functions * use Migrator Es client in SO migration * update migration tests * improve ES typings and mocks * migrate decorate ES errors * add repository es client * use new es client in so repository * update repository tests * fix migrator integration tests * declare _seq_no & _primary_term on get response. _source expect to be a string * make _sourceIncludes and refresh compatible with the client * add test for repository_es_client * move ApiResponse to es client mocks * TEMP: handle wait_for as true for deleteByNamespace * add tests for migration_es_client * TEMP: skip test for deleteByNamespace refresh * pass ignore as transport option in mget * log both es client and response errors * fix update method test failures * update deleteByNamespace refresh settings es doesn't support 'refresh: wait_for' for `updateByQuery` endpoint * update repository tests. we do not allow customising wait_for * do not delegate retry logic to es client * fix type errors after master merged * fix repository tests * fix security solutions code SO doesn't throw Error with status code anymore. Always use SO error helpers * switch error conditions to use SO error helpers * cleanup * address comments about mocks * use isResponseError helper * address comments * fix type errors Co-authored-by: pgayvallet <[email protected]> Co-authored-by: pgayvallet <[email protected]>
* master: (111 commits) Remove flaky note from gauge tests (elastic#73240) Convert functional vega tests to ts and unskip tests (elastic#72238) [Graph] Unskip graph tests (elastic#72291) Add default Elasticsearch credentials to docs (elastic#72617) [APM] Read body from indicesStats in upload-telemetry-data (elastic#72732) The directory in the command was missing the /generated directory and would cause all definitions to be regenerated in the wrong place. (elastic#72766) [KP] use new ES client in SO service (elastic#72289) [Security Solution][Exceptions] Prevents value list entries from co-existing with non value list entries (elastic#72995) Return EUI CSS to Shareable Runtime (elastic#72990) Removed useless karma test (elastic#73190) [INGEST_MANAGER] Make package config name blank for endpoint on Package Config create (elastic#73082) [Ingest Manager] Support DEGRADED state in fleet agent event (elastic#73104) [Security Solution][Detections] Change detections breadcrumb title (elastic#73059) [ML] Fixing unnecessary deleting job polling (elastic#73087) [ML] Fixing recognizer wizard create job button (elastic#73025) [Composable template] Preview composite template (elastic#72598) [Uptime] Use manual intervals for ping histogram (elastic#72928) [Security Solution][Endpoint] Task/policy save modal text change, remove duplicate policy details text (elastic#73130) [Maps] fix tile layer attibution text and attribution link validation errors (elastic#73160) skip ingest pipeline api tests ...
Summary
It should not affect public API since we return only the response body from SO API methods.
However, this change might affect plugins reading response
status
field from SO error bubbled to the Solutions code since ES error doesn't providestatus
field anymore (statusCode
is still provided).SavedObjectsErrorHelpers
. Plugins must use it because we are going to stop wrapping errors in theBoom
object Do not wrap SO errors in Boom #72441Comments on client integration problems @delvedor:
Comments on client integration problems @delvedor:
DeleteDocumentResponse
,GetResponse
andSearchResponse
manually from the legacy client interface.update
,bulk
methods interface incompatible. before:refresh: boolean | 'wait_for'
. after:refresh: 'true' | 'false' | 'wait_for'
kibana/src/core/server/saved_objects/service/lib/repository.ts
Lines 910 to 911 in e9ae3e9
It's possible to cast to String type, but it's rather clumsy in TS.
refresh?: boolean;
is it expected? shouldn't it have a compatible interface withrefresh: 'true' | 'false' | 'wait_for'
?_seq_no
,_primary_term
fields in ES document returned fromupdate
,get
methods https://www.elastic.co/guide/en/elasticsearch/reference/master/optimistic-concurrency-control.htmlGeneric
type containingignore?: number | number[];
, however, it had been failing argument validation until I movedignore: [404]
to the transport options.TransportRequestPromise
usage makes wrapping in an async function incompatiblecamelCase
request params renamed tosnake_case
. It's not mentioned in https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/breaking-changes.htmlChecklist
For maintainers