Skip to content

fix(sync): Extract error message from gRPC error#477

Closed
erezrokah wants to merge 2 commits intocloudquery:mainfrom
erezrokah:fix/extract_grpc_error_message
Closed

fix(sync): Extract error message from gRPC error#477
erezrokah wants to merge 2 commits intocloudquery:mainfrom
erezrokah:fix/extract_grpc_error_message

Conversation

@erezrokah
Copy link
Copy Markdown
Member

Summary

Related to cloudquery/cloudquery#4707.
Errors returned from a gRPC call have both a status and a message. We don't really use the status, but when we wrap the error it always gets printed, see:
https://github.com/grpc/grpc-go/blob/eeb9afa1f6b6388152955eeca8926e36ca94c768/internal/status/status.go#L140

We can easily extract just the message and print only that.
Before:

Error: failed to sync source aws: failed to fetch resources from stream: rpc error: code = Unknown desc = failed to sync resources: failed to create execution client for source plugin aws: no enabled accounts instantiated

After:

Error: failed to sync source aws: failed to sync resources: failed to create execution client for source plugin aws: no enabled accounts instantiated

We should do this for all gRPC calls, but I'll do that in follow up PRs so I can test it


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@github-actions github-actions bot added the fix label Dec 8, 2022
if err == io.EOF {
return nil
}
return fmt.Errorf("failed to fetch resources from stream: %w", err)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

failed to fetch resources from stream is incorrect (similar to #462 (comment)), as error can be anything returned from

func (s *SourceServer) Sync2(req *pb.Sync2_Request, stream pb.Source_Sync2Server) error {
so not necessarily means something with the stream

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 8, 2022

⏱️ Benchmark results

Comparing with cdcef5d

  • DefaultConcurrency-2 resources/s: 11,625 ⬇️ 3.42% decrease vs. cdcef5d
  • Glob-2 ns/op: 162.5 ⬇️ 28.18% decrease vs. cdcef5d
  • TablesWithChildrenDefaultConcurrency-2 resources/s: 29,562 ⬆️ 9.61% increase vs. cdcef5d
  • BufferedScanner-2 ns/op: 9.388 ⬇️ 36.34% decrease vs. cdcef5d
  • LogReader-2 ns/op: 30.75 ⬇️ 30.57% decrease vs. cdcef5d

@erezrokah
Copy link
Copy Markdown
Member Author

Next step to probably do #462 (comment)

Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

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

What is the value of extracting it rather than printing it as is (without more code) with the grpc= given this error comes from grpc so basically we are hiding more information just because the string is a bit long?

@erezrokah
Copy link
Copy Markdown
Member Author

erezrokah commented Dec 11, 2022

given this error comes from grpc so basically we are hiding more information just because the string is a bit long?

This is not a gRPC error. This is an application level error and we almost always print rpc error: code = Unknown desc = which has no value. See also bullet 2. in #485 (comment) and issue #462.

Also explained in #477 (comment)

kodiakhq bot pushed a commit that referenced this pull request Dec 11, 2022


Related to #462 and also #477.
Two reasons for this change:
1. We shouldn't be using `codes.Internal` as it's generated internally by gRPC so we won't be able to distinguish between gRPC protocol errors and application level errors, see https://github.com/grpc/grpc-go/blob/eeb9afa1f6b6388152955eeca8926e36ca94c768/codes/codes.go#L166.
2. We don't really do anything with the code at the moment, it's only printed in a confusing way (see #477)

---
@erezrokah erezrokah changed the title fix(sync): Extract gRPC error message fix(sync): Extract error message from gRPC error Dec 11, 2022
@github-actions github-actions bot added fix and removed fix labels Dec 11, 2022
@yevgenypats
Copy link
Copy Markdown
Contributor

yevgenypats commented Dec 11, 2022

given this error comes from grpc so basically we are hiding more information just because the string is a bit long?

This is not a gRPC error. This is an application level error and we almost always print rpc error: code = Unknown desc = which has no value. See also bullet 2. in #485 (comment) and issue #462.

Also explained in #477 (comment)

Right now we don't have a way to send application level errors (as those are mostly done via logs apart from config errors). We can implement this type of behaviour and add a field to the protocol but it's not the right place to do it over grpc errors.

@erezrokah
Copy link
Copy Markdown
Member Author

erezrokah commented Dec 11, 2022

We can implement this type of behaviour and add a field to the protocol but it's not the right place to do it over grpc errors.

Agree we should not do it as a part of gRPC errors, hence #487. We don't need to add anything to the protocol as errdetails already has all the things generated (but this should be discussed as a part of #487)

This PR doesn't change error handling, its meant to only remove the status print rpc error: code = Unknown desc as we're not using it anywhere nor it's useful to the user, pending a better solution.

@erezrokah
Copy link
Copy Markdown
Member Author

Closing since I think the fixes in #530 should be enough for now. We can re-visit this in the future

@erezrokah erezrokah closed this Dec 27, 2022
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.

3 participants