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 method stream type to generated code #172

Merged
merged 4 commits into from
Dec 8, 2023
Merged

Add method stream type to generated code #172

merged 4 commits into from
Dec 8, 2023

Conversation

pkwarren
Copy link
Contributor

@pkwarren pkwarren commented Dec 7, 2023

It is useful to have the stream type in the generated code (similar to other Connect implementations). In the future we may use this information to optimize stream handling - for example, avoiding the pipe/duplex/oneshot for server streaming calls to enable Connect over HTTP/1.1. Update the generator to include the stream type in the generated code.

Additionally, move the HTTP method to the HTTPRequest class - mutating a method spec to determine which HTTP method to use seems wrong. We should keep MethodSpec to contain only fields set from the generator.

It is useful to have the stream type in the generated code (similar to
other Connect implementations). In the future we may use this
information to optimize stream handling - for example, avoiding the
pipe/duplex/oneshot for server streaming calls to enable Connect over
HTTP/1.1. Update the generator to include the stream type in the
generated code.

Additionally, move the HTTP method to the HTTPRequest class - mutating a
method spec to determine which HTTP method to use seems wrong. We should
keep MethodSpec to contain only fields set from the generator.
@pkwarren pkwarren requested a review from jhump December 7, 2023 23:41
*/
class MethodSpec<Input : Any, Output : Any>(
val path: String,
val requestClass: KClass<Input>,
val responseClass: KClass<Output>,
val idempotency: Idempotency = Idempotency.UNKNOWN,
val method: String = Method.POST_METHOD,
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 did not make sense to live on the MethodSpec - it should have lived on the HTTPRequest. Now the MethodSpec type only contains fields assigned by the code generator.

@@ -216,7 +216,7 @@ class ProtocolClient(
isComplete = true
when (streamResult.code) {
Code.OK -> channel.close()
else -> channel.close(streamResult.connectException() ?: ConnectException(code = streamResult.code))
else -> channel.close(streamResult.connectException() ?: ConnectException(code = streamResult.code, exception = streamResult.cause))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were a few places where we were missing specifying the ConnectException's underlying cause (if set).

Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

Only one real remark (other two are little nits). Otherwise LG

Comment on lines 33 to 34
val idempotency: Idempotency = Idempotency.UNKNOWN,
val method: String = Method.POST_METHOD,
val streamType: StreamType = StreamType.UNKNOWN,
Copy link
Member

Choose a reason for hiding this comment

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

This unknown value seems a little scary. How will it impact things? Is it necessary for backwards-compatibility with older generated code? What could go wrong if older code is paired with this newer runtime -- would it mean that the GET HTTP verb is never used and interceptors would see the wrong value for stream type? I think it might be safer to make this a non-optional parameter with no default and remove the UNKNOWN sentinel enum entry. Users must re-generate their code when they update to newer version of the library.

Copy link
Contributor Author

@pkwarren pkwarren Dec 8, 2023

Choose a reason for hiding this comment

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

I went back and forth on this. Having UNKNOWN also matches connect-go and grpc-java. connect-swift doesn't have an unknown type.

It was less about the compatibility with existing generated code as this is still pre-v1 and it should be expected that consumers keep the runtime libraries in sync with the generated code. I'll make the change to make it required.

Copy link
Member

Choose a reason for hiding this comment

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

I know connect-go has this because there's no real support for enums in Go, and it's just good practice for the default/zero value to be a sentinel of this sort. But in kotlin and java, it's much less clear why you'd include one. With grpc-java, it's likely because that supports server-side, too, and if you want to create an "unknown method handler", it's most correct for it to report to handler/interceptor code that the stream type is unknown.

@pkwarren pkwarren requested a review from jhump December 8, 2023 15:20
Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

LGTM!

@pkwarren pkwarren merged commit f834eed into main Dec 8, 2023
7 checks passed
@pkwarren pkwarren deleted the pkw/stream-type branch December 8, 2023 15:50
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.

2 participants