kibana/x-pack/plugins/timelines/public
Nathan Reese adf3b8b436
[search source] return rawResponse on search failure (#168389)
Closes https://github.com/elastic/kibana/issues/167099

#### Problem
`/bsearch` and `/search` APIs only return `error` key from elasticsearch
error response. This is problematic because Inspector needs
`rawResponse` to populate "Clusters and shards"

While working on this issue, I discovered another problem with how error
responses are added to inspector requestResponder. The `Error` instance
is added as `json` key. This is a little awkward since the response tab
just stringifies the contents of `json`, thus stringifing the Error
object instead of just the error body returned from API. This PR address
this problem by setting `json` to either `attributes` or `{ message }`.

#### Solution
PR updates `/bsearch` and `/search` APIs to return `{ attributes: {
error: ErrorCause, rawResponse }}` for failed responses. Solution
avoided changing KbnServerError and reportServerError since these
methods are used extensivly throughout Kibana (see
https://github.com/elastic/kibana/pull/167544#discussion_r1342460941 for
more details). Instead, KbnSearchError and reportSearchError are created
to report search error messages.

#### Test
1) install web logs sample data set
2) open discover
3) add filter
    ```
    {
      "error_query": {
        "indices": [
          {
            "error_type": "exception",
            "message": "local shard failure message 123",
            "name": "kibana_sample_data_logs",
            "shard_ids": [
              0
            ]
          }
        ]
      }
    }
    ```
4) Open inspector. Verify "Clusters and shards" tab is visible and
populated. Verify "Response" tab shows "error" and "rawResponse" keys.
<img width="500" alt="Screenshot 2023-10-09 at 9 29 16 AM"
src="461b0eb0-0502-4d48-a487-68025ef24d35">
<img width="500" alt="Screenshot 2023-10-09 at 9 29 06 AM"
src="9aff41eb-f771-48e3-a66d-1447689c2c6a">

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
2023-10-23 10:59:17 -06:00
..
assets
components Upgrade EUI to v86.0.0 (#163088) 2023-08-14 15:45:09 -05:00
hooks [search source] return rawResponse on search failure (#168389) 2023-10-23 10:59:17 -06:00
methods [Security Solution] Decompose Timelines TGrid component and moved to security_solution (#140151) 2022-12-06 07:26:55 -08:00
mock [Security Solution] Decompose Timelines TGrid component and moved to security_solution (#140151) 2022-12-06 07:26:55 -08:00
store/timeline [Security Solution] Decompose Timelines TGrid component and moved to security_solution (#140151) 2022-12-06 07:26:55 -08:00
index.ts [Security Solution] Decompose Timelines TGrid component and moved to security_solution (#140151) 2022-12-06 07:26:55 -08:00
plugin.ts [Security Solution] Decompose Timelines TGrid component and moved to security_solution (#140151) 2022-12-06 07:26:55 -08:00
types.ts Upgrade EUI to v86.0.0 (#163088) 2023-08-14 15:45:09 -05:00