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

Support grpc-web-text #2938

Merged
merged 15 commits into from
Jul 30, 2020
Merged

Support grpc-web-text #2938

merged 15 commits into from
Jul 30, 2020

Conversation

minwoox
Copy link
Member

@minwoox minwoox commented Jul 27, 2020

Motivation:
Currently, we only support grpc-web, not grpc-web-text.
It would be nice if we support both.

Modifications:

  • GrpcService now supports all GrpcSerializationFormats by default.
  • ArmeriaMessageFramer and ArmeriaMessageDeframer now takes the additional boolean flag which indicates encoding decoding base64
  • Add gRPC-web it test with akka-grpc
    • The official grpc-java does not support grpc-web so we use akka-grpc for it testing

Result:

TO-do:

  • Support trailer parsing in GrpcWebUtil.

Motivation:
Currently, we only support grpc-web, not grpc-web-text.
It would be nice if we support both.

Modifications:
- `ArmeriaMessageFramer` and `ArmeriaMessageDeframer` now takes the additional boolean flag which indicates encoding decoding base64
- Add gRPC-web it test with akka-grpc
  - The official grpc-java does not support grpc-web so we use akka-grpc for it testing

Result:
- You can now use grpc-web-text using Armeria client and server.
@minwoox minwoox added this to the 0.99.9 milestone Jul 27, 2020
@codecov
Copy link

codecov bot commented Jul 27, 2020

Codecov Report

Merging #2938 into master will decrease coverage by 0.01%.
The diff coverage is 84.21%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2938      +/-   ##
============================================
- Coverage     73.22%   73.21%   -0.02%     
- Complexity    12198    12209      +11     
============================================
  Files          1061     1062       +1     
  Lines         47273    47343      +70     
  Branches       5967     5979      +12     
============================================
+ Hits          34614    34660      +46     
- Misses         9643     9656      +13     
- Partials       3016     3027      +11     
Impacted Files Coverage Δ Complexity Δ
...inecorp/armeria/client/grpc/GrpcClientOptions.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...corp/armeria/unsafe/grpc/GrpcUnsafeBufferUtil.java 73.33% <0.00%> (-5.24%) 4.00 <0.00> (ø)
.../com/linecorp/armeria/client/grpc/GrpcWebUtil.java 66.66% <60.00%> (-2.09%) 2.00 <2.00> (ø)
...ia/internal/common/grpc/GrpcMessageMarshaller.java 64.48% <66.66%> (-1.23%) 18.00 <0.00> (ø)
...rmeria/internal/client/grpc/ArmeriaClientCall.java 81.34% <77.77%> (+0.19%) 48.00 <6.00> (ø)
...inecorp/armeria/server/grpc/ArmeriaServerCall.java 87.22% <83.33%> (+1.00%) 77.00 <0.00> (-1.00) ⬆️
...rp/armeria/common/grpc/protocol/Base64Decoder.java 84.61% <84.61%> (ø) 9.00 <9.00> (?)
.../armeria/client/grpc/protocol/UnaryGrpcClient.java 77.04% <100.00%> (ø) 8.00 <0.00> (ø)
...a/common/grpc/protocol/ArmeriaMessageDeframer.java 73.68% <100.00%> (+1.13%) 51.00 <0.00> (+3.00)
...ria/common/grpc/protocol/ArmeriaMessageFramer.java 93.65% <100.00%> (+1.05%) 25.00 <1.00> (+3.00)
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23b89a5...d13089d. Read the comment docs.

dependencies.yml Outdated Show resolved Hide resolved
trustin pushed a commit to line/gradle-scripts that referenced this pull request Jul 28, 2020
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

How about updating the *-grpc.mdx?

@minwoox
Copy link
Member Author

minwoox commented Jul 29, 2020

How about updating the *-grpc.mdx?

Thanks!, updated client-grpc.mdx.
I think server-grpc.mdx doesn't need a change so I just left it. 😉

@@ -65,7 +65,7 @@
public final class GrpcServiceBuilder {

private static final Set<SerializationFormat> DEFAULT_SUPPORTED_SERIALIZATION_FORMATS =
ImmutableSet.of(GrpcSerializationFormats.PROTO, GrpcSerializationFormats.PROTO_WEB);
GrpcSerializationFormats.values();
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to support all GrpcSerializationFormats by default because there's no regression on performance and @ikhoon sometimes forgets about specifying JSON format when he's doing some test. 🤣 /cc @anuraaga

ImmutableSet.of(GrpcSerializationFormats.PROTO, GrpcSerializationFormats.PROTO_WEB);
ImmutableSet.of(GrpcSerializationFormats.PROTO,
GrpcSerializationFormats.PROTO_WEB,
GrpcSerializationFormats.PROTO_WEB_TEXT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you enable all gRPC protocols by default?
Most of Armeria users use gRPC-Java and com.google.protobuf.Message. Armeria can encode and decode the messages by default.

Even though Armeria does not support ScalaPB JSON by default. 😅
Any thoughts? @anuraaga

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops... Ditto 🤣

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Finally! 🎉

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Nice work! @minwoox

@trustin trustin merged commit 878684c into line:master Jul 30, 2020
import io.netty.util.ByteProcessor;

/**
* A stateful Base64decoder. Unlike {@link Base64#getDecoder()}, this decoder does not end when it meets
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* A stateful Base64decoder. Unlike {@link Base64#getDecoder()}, this decoder does not end when it meets
* A stateful Base64decoder. Unlike {@link io.netty.handler.codec.base64.Base64Decoder}, this decoder does not end when it meets

Important to describe the difference in this fork, not behavior vs JDK.


// White space, Equals sign or better
if (decodedByte < EQUALS_SIGN_ENC) {
// Ignore the white space.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we ignore white space, that seems like malformed base64?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me raise an exception. 😄

decodedSecond.release();
}

private static List<ByteBuf> fragmentRandomly(byte[] bytes) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should generate test cases randomly, it's very hard to be convinced this class is actually a complete test for base64, can you write a more concrete, easy to reason about test suite? Of course this is a big reason I didn't want to implement it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm working on a PR that supports compression and decoding base64 in GrpcWebUtil.
Let me work on this in that PR. 😄

@trustin
Copy link
Member

trustin commented Jul 30, 2020

@anuraaga Please keep commenting. We'll send a follow up PR for them. 🙇

@minwoox minwoox deleted the grpc-web-text branch July 30, 2020 04:29
minwoox added a commit to minwoox/armeria that referenced this pull request Jul 30, 2020
Address the comments from @anuraaga
trustin pushed a commit that referenced this pull request Jul 31, 2020
Motivation:
The [spec](https://tools.ietf.org/html/rfc4648#section-3.1) says that
```
Implementations MUST NOT add line feeds to base-encoded data unless
the specification referring to this document explicitly directs base
encoders to add line feeds after a specific number of characters.
```
So we should not add line-feed when base64 encoding.

Motivations:
- Do not add line-feed when base64 encoding.
- Address comments from @anuraaga in #2938.

Result:
- grpc-web-text does not contain line-feed characters.
minwoox added a commit to minwoox/armeria that referenced this pull request Jul 31, 2020
Motivation:
I made a mistake in line#2938 that the `ByteBufInputStream` is not closed.

Modification:
- Close `ByteBufInputStream`

Result:
- Less leaks
trustin pushed a commit that referenced this pull request Jul 31, 2020
Motivation:
I made a mistake in #2938 that the `ByteBufInputStream` is not closed.

Modification:
- Close `ByteBufInputStream`

Result:
- Less leaks
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Motivation:
Currently, we only support grpc-web, not grpc-web-text.
It would be nice if we support both.

Modifications:
- `GrpcService` now supports all `GrpcSerializationFormats` by default.
- `ArmeriaMessageFramer` and `ArmeriaMessageDeframer` now takes the additional boolean flag which indicates encoding decoding base64
- Add gRPC-web it test with akka-grpc
  - The official grpc-java does not support grpc-web so we use akka-grpc for it testing

Result:
- You can now use grpc-web-text using Armeria client and server.
- Close line#2911
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
…e#2946)

Motivation:
The [spec](https://tools.ietf.org/html/rfc4648#section-3.1) says that
```
Implementations MUST NOT add line feeds to base-encoded data unless
the specification referring to this document explicitly directs base
encoders to add line feeds after a specific number of characters.
```
So we should not add line-feed when base64 encoding.

Motivations:
- Do not add line-feed when base64 encoding.
- Address comments from @anuraaga in line#2938.

Result:
- grpc-web-text does not contain line-feed characters.
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Motivation:
I made a mistake in line#2938 that the `ByteBufInputStream` is not closed.

Modification:
- Close `ByteBufInputStream`

Result:
- Less leaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gRPC web text support
4 participants