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

Add stable codec interface and implementations #460

Merged
merged 5 commits into from
Feb 21, 2023

Conversation

jchadwick-buf
Copy link
Contributor

@jchadwick-buf jchadwick-buf commented Feb 14, 2023

Unfortunately, protobuf offers no story whatsoever for canonicalization of protobuf or protojson output. It seems the best we can get is to just make it deterministic within each implementation.

Related issues:

codec.go Outdated Show resolved Hide resolved
// If this function returns false, the data returned from Marshal and
// MarshalStable are considered valid text and may be used in contexts
// where text is expected.
IsBinary() bool
Copy link
Member

Choose a reason for hiding this comment

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

Codecs shouldn't need to expose anything about their format.

Copy link
Contributor Author

@jchadwick-buf jchadwick-buf Feb 14, 2023

Choose a reason for hiding this comment

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

Importantly, for Connect GET support, we need to know whether or not the URL data is/needs to be base64 encoded or not. The codec itself could handle this without exposing this detail, but that breaks transparency: there would be no way for a middlebox to know for sure how to translate a Connect GET request to an ordinary Connect Unary request or gRPC request. Unless we change the Connect GET design, this bit does need to escape the codec one way or another.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed with John here. To make Envoy and other middleboxes work, the runtime needs to know whether the encoded data is text or binary.

codec.go Show resolved Hide resolved
Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

I think unit tests for the codecs are appropriate now. I leaned toward end-to-end tests during connect's development b/c they were more robust to refactoring and gave me a better feel for the user experience.

Can you add a few tests? Otherwise this looks great.

codec.go Outdated Show resolved Hide resolved
@jchadwick-buf
Copy link
Contributor Author

Added tests and unexported the interface. The tests are a bit anemic at this point in time, if anyone has any ideas for how they could be expanded with more edge cases I'd like to. I'm working on stuff a bit out of order at the moment.

Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

LGTM! Think the testing could be improved a bit, but as long as those changes are confined to codec_test.go this can land without further review.

&pingv1.PingRequest{Text: "text", Number: 1},
[]byte(`{"number":"1","text":"text"}`),
)
}
Copy link
Member

Choose a reason for hiding this comment

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

A few suggestions to improve test coverage:

  • I always like testing/quick to do these sorts of round-trip testing. There are a handful of examples in this repository.
  • Rather than directly asserting the wire format, can we create a protobuf message with a map[string]string and assert that repeatedly marshaling it always produces the same output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a little tricky but I think I have made tests that work how you wanted.

@jchadwick-buf
Copy link
Contributor Author

Changes were confined to codec_test.go other than adding the Codec interface into stableCodec. Since stableCodec is not exported and only for our usage I think that should be OK. Going to merge into the get-support branch as per Akshay's direction.

@jchadwick-buf jchadwick-buf merged commit 5caa69e into get-support Feb 21, 2023
@jchadwick-buf jchadwick-buf deleted the stable-codec branch February 21, 2023 20:28
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