-
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
pass elasticsearch response to browser as a stream #193060
Conversation
/ci |
/ci |
/ci |
/ci |
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.
log_entry_search
test LGTM
src/plugins/data/common/search/strategies/es_search/response_utils.test.ts
Show resolved
Hide resolved
|
||
/** | ||
* Get the `total`/`loaded` for this response (see `IKibanaSearchResponse`). Note that `skipped` is | ||
* not included as it is already included in `successful`. | ||
* @internal | ||
*/ | ||
export function getTotalLoaded(response: estypes.SearchResponse<unknown>) { | ||
if (!response._shards) return {}; |
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.
Looking at the estypes.SearchResponse
type this should never happen. Have you encountered a case where _shards
property doesn't exist in response?
} | ||
) | ||
.then((rawResponse) => { | ||
const response = rawResponse.body!; |
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.
too much trust here, probably better to avoid non-null assertion since everything else here seems soo fragile
const error = (response as unknown as Record<string, unknown>).error; | ||
if (error) { |
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.
Does this error surfaced only with the stream
configuration?
Because if yes we shouldn't solve it here, but probably in a more deeper substrate. Feels wrong to handle an error from something that should be a valid response
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, this only comes up with streams
'kbn-is-restored': response.isRestored ? '?1' : '?0', | ||
'kbn-search-request-params': JSON.stringify(response.requestParams), |
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.
Can we improve the naming here, in particular, the kbn-is-restored
doesn't describe much of what is restored.
Would be great if we could move these headers into some reused const.
...request, | ||
...searchOptions, | ||
}), | ||
.post<IKibanaSearchResponse>( |
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.
You can probably change this type to IKibanaSearchResponse | ErrorResponseBase
ErrorResponseBase
comes from elasticsearch client and seems to the the type of response that is returned by ES when you have an error. To test it you can created a custom DSL filter with a wrong syntax like
{
"match_ph": {
"bytes": 21212
}
}
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 is very strange that we never considered using this type in our code. ES always return 200
even if there is an error in the query, it look like it just throw other status code if the call itself is wrong, not if the response is wrong.
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.
no idea, but my goal was to keep the scope of this pr as limited as possible.
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.
Changes looks good to me
💚 Build Succeeded
Metrics [docs]Module Count
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
cc @ppisljar |
Remove decoding and re-encoding of the ES-response from Kibana-server. Resolves elastic#189640
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
Remove decoding and re-encoding of the ES-response from Kibana-server. Resolves elastic#189640 (cherry picked from commit 7b81bcf)
…205811) # Backport This will backport the following commits from `main` to `8.x`: - [pass elasticsearch response to browser as a stream (#193060)](#193060) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Peter Pisljar","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-07T11:19:13Z","message":"pass elasticsearch response to browser as a stream (#193060)\n\nRemove decoding and re-encoding of the ES-response from Kibana-server.\r\nResolves https://github.com/elastic/kibana/issues/189640","sha":"7b81bcf60a7fbc287fdfe2aa6b44009b04024229","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Search","backport","release_note:skip","backport:skip","v9.0.0","ci:project-deploy-observability","v8.18.0"],"number":193060,"url":"https://github.com/elastic/kibana/pull/193060","mergeCommit":{"message":"pass elasticsearch response to browser as a stream (#193060)\n\nRemove decoding and re-encoding of the ES-response from Kibana-server.\r\nResolves https://github.com/elastic/kibana/issues/189640","sha":"7b81bcf60a7fbc287fdfe2aa6b44009b04024229"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193060","number":193060,"mergeCommit":{"message":"pass elasticsearch response to browser as a stream (#193060)\n\nRemove decoding and re-encoding of the ES-response from Kibana-server.\r\nResolves https://github.com/elastic/kibana/issues/189640","sha":"7b81bcf60a7fbc287fdfe2aa6b44009b04024229"}},{"branch":"8.18","label":"v8.18.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Peter Pisljar <[email protected]>
Remove decoding and re-encoding of the ES-response from Kibana-server. Resolves #189640
How to test:
when using ese or async esql search strategies (discover, lens, maps, ....) you should see in the network tab of developer tools that the responses to your requests come directly from es and they should be gzipped