-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[Console] Fix autocomplete_entities API crash when response size is too big #140569
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
[Console] Fix autocomplete_entities API crash when response size is too big #140569
Conversation
e5ae3dd
to
db5e2b5
Compare
src/plugins/console/server/routes/api/console/autocomplete_entities/register_get_route.ts
Outdated
Show resolved
Hide resolved
db5e2b5
to
01ae4c0
Compare
08a9cb0
to
434ac82
Compare
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.
Going through the changes and at first glance looks fine, I was wondering though how can I test this locally to make sure it works? 🤔
c4f19ef
to
db281e3
Compare
491bf97
to
3b75822
Compare
Closing this PR as the issue was fixed by #143428 |
2de7634
to
f94b90b
Compare
Thanks for the review @alisonelizabeth! I've addressed your feedback with f94b90b and a31e406. We have existing API integration tests for autocomplete_entities, but they are not very extensive. I've added a few more tests to cover the response format. |
Verified the api integration tests through the flaky test runner ~200 times https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1539 |
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 for addressing my feedback! I left a couple nits in the API integration tests. Let me know what you think. I'm going to go ahead and approve to unblock you.
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @mibragimov |
…oo big (elastic#140569) Fixes elastic#144310 ### Summary This PR addresses the issue of the Kibana instance restarting when the response size is too big for the `autocomplete_entities` API. This happens when a cluster has a large number of mappings and we try to retrieve them all on the server side with `esClient.asInternalUser.indices.getMapping()`. esClient does not handle large responses well and throws an error that causes the Kibana instance to restart. As node's max [string length](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#description) is 2^28-1 (~512MB) if the response size is over 512MB, it will throw an error with the message "Invalid string length". The fix is to use the raw http request to retrieve the mappings instead of esClient and check the response size before sending it to the client. If the response size is too big, we will return an empty object and log the error in the server logs. #### Proposed changes - Remove ES JS client requests and use native Node.js HTTP client instead - Limit the response size to 10MB for the `autocomplete_entities` API #### How to test this PR locally To test this out, you will need to connect Kibana to a remote cluster with a large number of mappings. We created a patch file that you can apply to your local Kibana instance to test this PR. Since the patch file contains credentials, we can't share it publicly. Please reach out to me if you would like to test this PR. I will share the patch file and the instructions to apply it. Co-authored-by: Muhammad Ibragimov <muhammad.ibragimov@elastic.co> (cherry picked from commit 0e01401)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…e is too big (#140569) (#145051) # Backport This will backport the following commits from `main` to `8.5`: - [[Console] Fix autocomplete_entities API crash when response size is too big (#140569)](#140569) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Muhammad Ibragimov","email":"53621505+mibragimov@users.noreply.github.com"},"sourceCommit":{"committedDate":"2022-11-11T10:43:52Z","message":"[Console] Fix autocomplete_entities API crash when response size is too big (#140569)\n\nFixes https://github.com/elastic/kibana/issues/144310\r\n\r\n### Summary\r\n\r\nThis PR addresses the issue of the Kibana instance restarting when the\r\nresponse size is too big for the `autocomplete_entities` API. This\r\nhappens when a cluster has a large number of mappings and we try to\r\nretrieve them all on the server side with\r\n`esClient.asInternalUser.indices.getMapping()`. esClient does not handle\r\nlarge responses well and throws an error that causes the Kibana instance\r\nto restart. As node's max [string\r\nlength](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#description)\r\nis 2^28-1 (~512MB) if the response size is over 512MB, it will throw an\r\nerror with the message \"Invalid string length\".\r\n\r\nThe fix is to use the raw http request to retrieve the mappings instead\r\nof esClient and check the response size before sending it to the client.\r\nIf the response size is too big, we will return an empty object and log\r\nthe error in the server logs.\r\n\r\n#### Proposed changes\r\n\r\n- Remove ES JS client requests and use native Node.js HTTP client\r\ninstead\r\n- Limit the response size to 10MB for the `autocomplete_entities` API\r\n\r\n#### How to test this PR locally\r\nTo test this out, you will need to connect Kibana to a remote cluster\r\nwith a large number of mappings. We created a patch file that you can\r\napply to your local Kibana instance to test this PR. Since the patch\r\nfile contains credentials, we can't share it publicly. Please reach out\r\nto me if you would like to test this PR. I will share the patch file and\r\nthe instructions to apply it.\r\n\r\nCo-authored-by: Muhammad Ibragimov <muhammad.ibragimov@elastic.co>","sha":"0e0140181faf65ad3041e22fc053e49c76f2ce47","branchLabelMapping":{"^v8.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Feature:Dev Tools","release_note:fix","Team:Deployment Management","backport:prev-minor","v8.6.0"],"number":140569,"url":"https://github.com/elastic/kibana/pull/140569","mergeCommit":{"message":"[Console] Fix autocomplete_entities API crash when response size is too big (#140569)\n\nFixes https://github.com/elastic/kibana/issues/144310\r\n\r\n### Summary\r\n\r\nThis PR addresses the issue of the Kibana instance restarting when the\r\nresponse size is too big for the `autocomplete_entities` API. This\r\nhappens when a cluster has a large number of mappings and we try to\r\nretrieve them all on the server side with\r\n`esClient.asInternalUser.indices.getMapping()`. esClient does not handle\r\nlarge responses well and throws an error that causes the Kibana instance\r\nto restart. As node's max [string\r\nlength](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#description)\r\nis 2^28-1 (~512MB) if the response size is over 512MB, it will throw an\r\nerror with the message \"Invalid string length\".\r\n\r\nThe fix is to use the raw http request to retrieve the mappings instead\r\nof esClient and check the response size before sending it to the client.\r\nIf the response size is too big, we will return an empty object and log\r\nthe error in the server logs.\r\n\r\n#### Proposed changes\r\n\r\n- Remove ES JS client requests and use native Node.js HTTP client\r\ninstead\r\n- Limit the response size to 10MB for the `autocomplete_entities` API\r\n\r\n#### How to test this PR locally\r\nTo test this out, you will need to connect Kibana to a remote cluster\r\nwith a large number of mappings. We created a patch file that you can\r\napply to your local Kibana instance to test this PR. Since the patch\r\nfile contains credentials, we can't share it publicly. Please reach out\r\nto me if you would like to test this PR. I will share the patch file and\r\nthe instructions to apply it.\r\n\r\nCo-authored-by: Muhammad Ibragimov <muhammad.ibragimov@elastic.co>","sha":"0e0140181faf65ad3041e22fc053e49c76f2ce47"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.6.0","labelRegex":"^v8.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/140569","number":140569,"mergeCommit":{"message":"[Console] Fix autocomplete_entities API crash when response size is too big (#140569)\n\nFixes https://github.com/elastic/kibana/issues/144310\r\n\r\n### Summary\r\n\r\nThis PR addresses the issue of the Kibana instance restarting when the\r\nresponse size is too big for the `autocomplete_entities` API. This\r\nhappens when a cluster has a large number of mappings and we try to\r\nretrieve them all on the server side with\r\n`esClient.asInternalUser.indices.getMapping()`. esClient does not handle\r\nlarge responses well and throws an error that causes the Kibana instance\r\nto restart. As node's max [string\r\nlength](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#description)\r\nis 2^28-1 (~512MB) if the response size is over 512MB, it will throw an\r\nerror with the message \"Invalid string length\".\r\n\r\nThe fix is to use the raw http request to retrieve the mappings instead\r\nof esClient and check the response size before sending it to the client.\r\nIf the response size is too big, we will return an empty object and log\r\nthe error in the server logs.\r\n\r\n#### Proposed changes\r\n\r\n- Remove ES JS client requests and use native Node.js HTTP client\r\ninstead\r\n- Limit the response size to 10MB for the `autocomplete_entities` API\r\n\r\n#### How to test this PR locally\r\nTo test this out, you will need to connect Kibana to a remote cluster\r\nwith a large number of mappings. We created a patch file that you can\r\napply to your local Kibana instance to test this PR. Since the patch\r\nfile contains credentials, we can't share it publicly. Please reach out\r\nto me if you would like to test this PR. I will share the patch file and\r\nthe instructions to apply it.\r\n\r\nCo-authored-by: Muhammad Ibragimov <muhammad.ibragimov@elastic.co>","sha":"0e0140181faf65ad3041e22fc053e49c76f2ce47"}}]}] BACKPORT--> Co-authored-by: Muhammad Ibragimov <53621505+mibragimov@users.noreply.github.com>
Changing |
Fixes #144310
Summary
This PR addresses the issue of the Kibana instance restarting when the response size is too big for the
autocomplete_entities
API. This happens when a cluster has a large number of mappings and we try to retrieve them all on the server side withesClient.asInternalUser.indices.getMapping()
. esClient does not handle large responses well and throws an error that causes the Kibana instance to restart. As node's max string length is 2^28-1 (~512MB) if the response size is over 512MB, it will throw an error with the message "Invalid string length".The fix is to use the raw http request to retrieve the mappings instead of esClient and check the response size before sending it to the client. If the response size is too big, we will return an empty object and log the error in the server logs.
Proposed changes
autocomplete_entities
APIHow to test this PR locally
To test this out, you will need to connect Kibana to a remote cluster with a large number of mappings. We created a patch file that you can apply to your local Kibana instance to test this PR. Since the patch file contains credentials, we can't share it publicly. Please reach out to me if you would like to test this PR. I will share the patch file and the instructions to apply it.