Skip to content

[Fleet] Fix epm endpoints return errors#171722

Merged
criamico merged 12 commits intoelastic:mainfrom
criamico:2606_fix_epm_return_errors
Nov 27, 2023
Merged

[Fleet] Fix epm endpoints return errors#171722
criamico merged 12 commits intoelastic:mainfrom
criamico:2606_fix_epm_return_errors

Conversation

@criamico
Copy link
Contributor

@criamico criamico commented Nov 22, 2023

Summary

[Fleet] Improve error handling on epm endpoints.

Currently most errors occurring when doing any operation with packages will throw and result in a 500 in 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 Error with FleetError; it calls Logger.error and 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

@criamico criamico self-assigned this Nov 22, 2023
@criamico criamico added the Team:Fleet Team label for Observability Data Collection Fleet team label Nov 22, 2023
@ghost
Copy link

ghost commented Nov 22, 2023

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@criamico
Copy link
Contributor Author

@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`
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, that is indeed the template obtained from the package. I'll change it to PackageInvalidArchiveError

@criamico criamico marked this pull request as ready for review November 23, 2023 11:39
@criamico criamico requested a review from a team as a code owner November 23, 2023 11:39
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@kibanamachine kibanamachine requested a review from a team November 23, 2023 12:13
Copy link
Member

@sphilipse sphilipse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving as code owner for CI auto-commit

@nchaulet nchaulet self-requested a review November 23, 2023 13:45
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice to use typed errors on these cases.

throw new Error(`Error template for ${templateIndexPattern} contains a final_pipeline`);
throw new PackageESError(
`Error template for ${templateIndexPattern} contains a final_pipeline`
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

logger.warn(`Cannot rollover data stream [${dataStreamName}] due to error: ${error}`);
throw new PackageESError(
`Cannot rollover data stream [${dataStreamName}] due to error: ${error}`
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 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}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@criamico
Copy link
Contributor Author

criamico commented Nov 23, 2023

@jsoriano

Do we have tests covering these cases? Should we take the opportunity to add more tests around package installation?

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why that change in that PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an auto commit. Probably was already fixed by some other PR, I'll see if I get any conflicts when I merge

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that PR, code LGTM 🚀 (after typecheck are fixed)

@criamico
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @criamico

@criamico criamico merged commit 8d7816c into elastic:main Nov 27, 2023
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Nov 27, 2023
@criamico criamico deleted the 2606_fix_epm_return_errors branch November 27, 2023 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v8.12.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants