[search source] return rawResponse on search failure#168389
[search source] return rawResponse on search failure#168389nreese merged 30 commits intoelastic:mainfrom
Conversation
…-ref HEAD~1..HEAD --fix'
ce23841 to
9191337
Compare
…-ref HEAD~1..HEAD --fix'
…-ref HEAD~1..HEAD --fix'
…-ref HEAD~1..HEAD --fix'
…-ref HEAD~1..HEAD --fix'
|
@elasticmachine merge upstream |
|
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
davismcphee
left a comment
There was a problem hiding this comment.
Code changes LGTM! Just left a couple of minor comments.
Otherwise my only concern is related to backward compatibility. Does changing the error response of the /search and /bsearch endpoints risk breaking backward compatibility in a Serverless upgrade scenario (i.e. backend and frontend versions off by 1)? This is less of a concern while Serverless is in private preview, but something to be mindful of regardless.
Also, unrelated to this PR, but I noticed the inspector uses X failured shard(s) in the title, which looks a little odd. Should it instead say X failed shard(s)?

| if (e instanceof KbnSearchError) return e; | ||
| return new KbnSearchError( | ||
| e.message ?? 'Unknown error', | ||
| e instanceof errors.ResponseError ? e.statusCode! : 500, |
There was a problem hiding this comment.
How do we know e.statusCode isn't null here?
| expect(error.body.attributes).toBe(indexNotFoundException.error); | ||
| expect(error.body.attributes).toEqual({ | ||
| error: indexNotFoundException.error, | ||
| rawResponse: undefined, |
There was a problem hiding this comment.
Is there a scenario we can test for here where rawResponse isn't undefined too?
There was a problem hiding this comment.
I can add a test case to API integration tests that verifies rawResponse is returned. These tests are all just mocks, where as API integration tests test actual code paths.
There was a problem hiding this comment.
That instead also works for me 👍
I am not sure I see the problem. It says "1 failed shard" when there is a single shard failure and "3 failed shards" when there are multiple shard failures. This seems like proper english. Could you explain further? |
"1 failed shard" makes sense, but currently it's "1 failured shard". There's an additional "ur" in "failed" currently. |
Thanks, I see that now. I can open a separate PR to resolve |
drewdaemon
left a comment
There was a problem hiding this comment.
Lens changes make sense to me. I left one question.
Search changes are owned by Discovery, so nothing needed from me there.
| if (e.attributes?.error?.reason) { | ||
| return getNestedErrorClause(e.attributes.error); | ||
| } | ||
| if (e.attributes?.error?.caused_by) { |
There was a problem hiding this comment.
Not sure I understand why this guard was inserted. It doesn't look like we gated the logic by the existence of caused_by before.
There was a problem hiding this comment.
attributes.error is typed as optional.
There was a problem hiding this comment.
It looks like the previous logic assumed that caused_by was defined (type cast) which it must always have been since getNestedErrorClause would have errored if passed undefined.
Given this, I think changing from casting to checking is okay because it should not change the amount of times this branch gets entered.
|
@elasticmachine merge upstream |
| // Skipping to unblock: https://github.com/elastic/kibana/pull/168389 | ||
| describe.skip('With anomalies data', () => { |
There was a problem hiding this comment.
I can reproduce this when running locally with Network throttling. Create an issue to follow it up: #169507
There was a problem hiding this comment.
Could you please check if the error you had was the same as #168709, if so, can you please try unskipping the test?
There was a problem hiding this comment.
I removed skip, it is not longer needed now that test has been fixed
| if (e.attributes?.error?.reason) { | ||
| return getNestedErrorClause(e.attributes.error); | ||
| } | ||
| if (e.attributes?.error?.caused_by) { |
There was a problem hiding this comment.
It looks like the previous logic assumed that caused_by was defined (type cast) which it must always have been since getNestedErrorClause would have errored if passed undefined.
Given this, I think changing from casting to checking is okay because it should not change the amount of times this branch gets entered.
PhilippeOberti
left a comment
There was a problem hiding this comment.
LGTM for the Threat Hunting Investigations team!
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
Closes #167099
Problem
/bsearchand/searchAPIs only returnerrorkey from elasticsearch error response. This is problematic because Inspector needsrawResponseto populate "Clusters and shards"While working on this issue, I discovered another problem with how error responses are added to inspector requestResponder. The
Errorinstance is added asjsonkey. This is a little awkward since the response tab just stringifies the contents ofjson, thus stringifing the Error object instead of just the error body returned from API. This PR address this problem by settingjsonto eitherattributesor{ message }.Solution
PR updates
/bsearchand/searchAPIs to return{ attributes: { error: ErrorCause, rawResponse }}for failed responses. Solution avoided changing KbnServerError and reportServerError since these methods are used extensivly throughout Kibana (see #167544 (comment) for more details). Instead, KbnSearchError and reportSearchError are created to report search error messages.Test