[Fleet] Fix epm endpoints return errors#171722
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
@elasticmachine merge upstream |
| throw new Error(`Error template for ${templateIndexPattern} contains a final_pipeline`); | ||
| throw new PackageESError( | ||
| `Error template for ${templateIndexPattern} contains a final_pipeline` | ||
| ); |
There was a problem hiding this comment.
I'm just not sure if these errors should be a 500. I found a few that happen when dealing with ES but I'm not totally sure what the correct response should be.
There was a problem hiding this comment.
The template here refers to the template obtained from the package? If this depends only on the content of the package this should probably be a PackageInvalidArchiveError, or some other error indicating that the package is invalid, and produce a 4xx error.
Btw, since elastic/package-spec#587, we are more strict on what can be defined in the index template settings and we don't allow final_pipeline, so a package with final_pipeline in the template settings is indeed invalid.
There was a problem hiding this comment.
I think you're right, that is indeed the template obtained from the package. I'll change it to PackageInvalidArchiveError
|
Pinging @elastic/fleet (Team:Fleet) |
sphilipse
left a comment
There was a problem hiding this comment.
approving as code owner for CI auto-commit
jsoriano
left a comment
There was a problem hiding this comment.
Great to see more specific errors for each case 👍
Do we have tests covering these cases? Should we take the opportunity to add more tests around package installation?
| throw new Error('Invalid key'); | ||
| throw new PackageInvalidArchiveError( | ||
| `Error while compiling agent template: Invalid key ${lastKeyPart}` | ||
| ); |
There was a problem hiding this comment.
👍 nice to use typed errors on these cases.
x-pack/plugins/fleet/server/services/epm/elasticsearch/ilm/install.ts
Outdated
Show resolved
Hide resolved
| throw new Error(`Error template for ${templateIndexPattern} contains a final_pipeline`); | ||
| throw new PackageESError( | ||
| `Error template for ${templateIndexPattern} contains a final_pipeline` | ||
| ); |
There was a problem hiding this comment.
The template here refers to the template obtained from the package? If this depends only on the content of the package this should probably be a PackageInvalidArchiveError, or some other error indicating that the package is invalid, and produce a 4xx error.
Btw, since elastic/package-spec#587, we are more strict on what can be defined in the index template settings and we don't allow final_pipeline, so a package with final_pipeline in the template settings is indeed invalid.
x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts
Outdated
Show resolved
Hide resolved
| logger.warn(`Cannot rollover data stream [${dataStreamName}] due to error: ${error}`); | ||
| throw new PackageESError( | ||
| `Cannot rollover data stream [${dataStreamName}] due to error: ${error}` | ||
| ); |
There was a problem hiding this comment.
👍 this actually looks like a case where we should return a 500 error.
| throw new Error(`could not update lifecycle settings for ${dataStreamName}: ${err.message}`); | ||
| logger.warn(`Could not update lifecycle settings for ${dataStreamName}: ${err.message}`); | ||
| throw new PackageESError( | ||
| `Could not update lifecycle settings for ${dataStreamName}: ${err.message}` |
There was a problem hiding this comment.
I wonder if this can happen because the new settings are invalid, in this case we should produce a 400 error. But I am fine with producing a 500 error by now.
There was a problem hiding this comment.
I'll add a comment to it so we can reconsider it in the future.
| } catch (err) { | ||
| throw new Error(`could not update index template settings for ${dataStreamName}`); | ||
| logger.warn(`Could not update index template settings for ${dataStreamName}`); | ||
| throw new PackageESError(`Could not update index template settings for ${dataStreamName}`); |
There was a problem hiding this comment.
Same thing here. If the new index template settings are invalid this should produce a 400 error. But I am fine with leaving this as a 500 error if we don't have a way to discern the cases.
Great question, we don't have coverage for all these cases. I'm adding some of them but I'm not even sure how to repro some edge cases. |
| <EuiFlexItem grow={false}> | ||
| <EuiLink onClick={() => createConnector()}> | ||
| <EuiLink | ||
| data-test-subj="serverlessSearchConnectorIngestionPanelSetUpAConnectorLink" |
There was a problem hiding this comment.
nit: why that change in that PR?
There was a problem hiding this comment.
This was an auto commit. Probably was already fixed by some other PR, I'll see if I get any conflicts when I merge
nchaulet
left a comment
There was a problem hiding this comment.
Thanks for that PR, code LGTM 🚀 (after typecheck are fixed)
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @criamico |
Summary
[Fleet] Improve error handling on epm endpoints.
Currently most errors occurring when doing any operation with packages will throw and result in a
500in the correspondent endpoint.This PR is an attempts to handle those errors in a more comprehensive way and to return meaningful responses.
Where I can I'm replacing the generic
ErrorwithFleetError; it callsLogger.errorand checks if the error belongs to a specific type, if not defaults to 500.The error described in elastic/integrations#8268 will now return a 400: https://github.com/elastic/kibana/pull/171722/files#diff-952b3c1842d5d24d9e70833cae1683e2d78df7b489dc99665dab723cc10927c1R349-R352
Checklist