Skip to content
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

feat(deployer): handle errors from corrupted resource data #1208

Merged

Conversation

oddgrd
Copy link
Contributor

@oddgrd oddgrd commented Sep 7, 2023

Description of change

We did not handle errors from corrupted resource data received in the deployer. With this change we will return an internal error with a message about which resource had corrupted data. Figuring out how the data can get corrupted is still a TODO.

How has this been tested? (if applicable)

Tested on local environment by deploying a rocket postgres project, and then manually editing the resource-recorder state and making the config for the postgres resource invalid JSON.

Errors from corrupted resource date:
For deployment the user will see this error in their logs:

ERROR {error="database::shared::postgres resource config should be valid JSON\n\nCaused by:\n    expected `:` at line 1 column 13"} shuttle_deployer::deployment::run: failed to parse resource data

For the resource list the tracing error will not be recorded in the deployer sqlite, I can only see it in the deployers docker logs:

2023-09-07T12:17:43.227645Z ERROR request{http.uri=/projects/postgres-rocket-app/services/postgres-rocket-app/resources http.method=GET request.path="/projects/:project_name/services/:service_name/resources" account.name="admin" request.params.service_name="postgres-rocket-app" request.params.project_name="postgres-rocket-app"}:get_service_resources{project_name=postgres-rocket-app service_name=postgres-rocket-app}: shuttle_deployer::handlers: failed to parse resource data error=database::shared::postgres resource config should be valid JSON

Caused by:
    expected `:` at line 1 column 13

// We collect into a Result so that if the response contains a resource with corrupted data,
// we terminate iteration and return error.
// TODO: investigate how the resource data can get corrupted.
.collect::<Result<Vec<_>>>()?
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 implementation errors on any corrupted resource, we could also tracing::error! the bad resource errors, and just return the OK ones. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I think returning what converted successfully is a good idea. That way the corrupted ones can be recreated and fixed.

Copy link
Contributor Author

@oddgrd oddgrd Sep 7, 2023

Choose a reason for hiding this comment

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

Refactored in 08af728, for deployment the user will see this error in their logs:

ERROR {error="database::shared::postgres resource config should be valid JSON\n\nCaused by:\n    expected `:` at line 1 column 13"} shuttle_deployer::deployment::run: failed to parse resource data

For the resource list the tracing error will not be recorded in the deployer sqlite (but maybe we will instrument it with deployment id for new logger?), I can only see it in the deployers docker logs:

2023-09-07T12:17:43.227645Z ERROR request{http.uri=/projects/postgres-rocket-app/services/postgres-rocket-app/resources http.method=GET request.path="/projects/:project_name/services/:service_name/resources" account.name="admin" request.params.service_name="postgres-rocket-app" request.params.project_name="postgres-rocket-app"}:get_service_resources{project_name=postgres-rocket-app service_name=postgres-rocket-app}: shuttle_deployer::handlers: failed to parse resource data error=database::shared::postgres resource config should be valid JSON

Caused by:
    expected `:` at line 1 column 13

Copy link
Member

@chesedo chesedo left a comment

Choose a reason for hiding this comment

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

Maybe we should do a best effort on the conversion

// We collect into a Result so that if the response contains a resource with corrupted data,
// we terminate iteration and return error.
// TODO: investigate how the resource data can get corrupted.
.collect::<Result<Vec<_>>>()?
Copy link
Member

Choose a reason for hiding this comment

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

I think returning what converted successfully is a good idea. That way the corrupted ones can be recreated and fixed.

Copy link
Contributor

@iulianbarbu iulianbarbu left a comment

Choose a reason for hiding this comment

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

LGTM! nit: just remember to modify the squashed commit or modify directly the PR title to conform to conventional commits.

@oddgrd oddgrd changed the title Feature/eng 1215 handle errors from corrupted resource data feat(deployer): handle errors from corrupted resource data Sep 7, 2023
Copy link
Member

@chesedo chesedo left a comment

Choose a reason for hiding this comment

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

LGTM

fn try_from(resource: record_request::Resource) -> Result<Self, Self::Error> {
let r#type = shuttle_common::resource::Type::from_str(resource.r#type.as_str())
.map_err(anyhow::Error::msg)
.context("resource type should have a valid resource string")?;
Copy link
Member

Choose a reason for hiding this comment

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

Proper error handling. This is nice 🤩

@oddgrd oddgrd merged commit d7b5b6a into main Sep 8, 2023
32 checks passed
@oddgrd oddgrd deleted the feature/eng-1215-handle-errors-from-corrupted-resource-data branch September 8, 2023 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants