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

Generate Kotlin gRPC Stubs #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

t0rr3sp3dr0
Copy link

This patch modifies build configuration files to generate gRPC Stubs for Kotlin and place them inside the built artifact. The changes were based on official tutorials on how to configure maven-protobuf-plugin to generate Kotlin gRPC Stubs (https://github.com/grpc/grpc-kotlin/tree/master/compiler) and how to build Kotlin with Maven (https://kotlinlang.org/docs/maven.html).

In the built JAR, for each ServiceGrpc class generated from a gRPC service definition on proto files, a new class called ServiceGrpcKt is introduced with the Kotlin interface. I've tested it on a Java-only project to make sure it doesn't cause any problem.

image

The built artifact is available on JitPack: https://jitpack.io/#t0rr3sp3dr0/java-control-plane/3bd90153d9.

Closes #168

Signed-off-by: Pedro Tôrres <t0rr3sp3dr0@gmail.com>
@codecov-commenter
Copy link

Codecov Report

Merging #169 (3bd9015) into main (06f2735) will decrease coverage by 0.10%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #169      +/-   ##
============================================
- Coverage     88.26%   88.16%   -0.11%     
+ Complexity      298      297       -1     
============================================
  Files            31       31              
  Lines           980      980              
  Branches         78       78              
============================================
- Hits            865      864       -1     
  Misses           85       85              
- Partials         30       31       +1     
Impacted Files Coverage Δ
.../io/envoyproxy/controlplane/cache/SimpleCache.java 82.97% <0.00%> (-0.71%) ⬇️

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 800cb5e...3bd9015. Read the comment docs.

@slonka
Copy link
Member

slonka commented Jun 6, 2021

Hi, I will test it in Envoy-Control and check if it works and if it does i'll review it and merge it.

@t0rr3sp3dr0
Copy link
Author

Hi @slonka! Were you able to verify this works?

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need coroutines for that?

Copy link
Author

Choose a reason for hiding this comment

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

In Kotlin, the base implementations of gRPC services use coroutines to deal with blocking operations. This way, developers don't need to deal with StreamObservers like they have to do in Java and just implement a suspend function that returns the object directly.

Java implementation:
https://github.com/grpc/grpc-java/blob/c540229d79c6d8d29da34d22c3c5add2138bdc87/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java#L81-L89

Kotlin implementation:
https://github.com/grpc/grpc-kotlin/blob/b7d06483bf597cd4a10e3ed2ef52b21ca95c80ad/examples/server/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldServer.kt#L48-L53

@slonka
Copy link
Member

slonka commented Jun 23, 2021

Hi @t0rr3sp3dr0 - sorry for the delay. I've run into a bit of a problem, after leaving Allegro I no longer can release SNAPSHOTs of java-control-plane. I'm getting permissions denied. Maybe @lukidzi can help out. I'm using the same token as before, and even created a new one.

@t0rr3sp3dr0
Copy link
Author

@slonka and @lukidzi, do you have an update here?

@t0rr3sp3dr0
Copy link
Author

@slonka and @lukidzi, sorry to bother you again, but I really need to get this PR merged.

We have been using a fork of the project with this patch applied so we could move forward internally while this PR wasn’t merged. But we weren’t expecting to still be relying on the fork 6 months later.

@t0rr3sp3dr0
Copy link
Author

@rulex123 and @onemanbucket, are you able to take a look on this PR?

@t0rr3sp3dr0
Copy link
Author

@rulex123 and @onemanbucket, sorry to ping you again, but it seems you are the only ones contributing to this repository at the moment. I even sent a message on the control-plane-dev channel on Slack to find other maintainers, but got no answer (https://envoyproxy.slack.com/archives/C7LDJTM6Z/p1644537207034489).

I would appreciate if you could review this patch.

@t0rr3sp3dr0
Copy link
Author

Hi everyone!

Sorry to tag all the project maintainers here, but I've been trying to get someone to review this PR for over 9 months now and I've had no success so far.

If someone can take a look here, I'd really appreciate it! 🙂

@Automaat @Ferdudas97 @b-hoyt @chemicL @gawarz @joeyb @kukulam-allegro @lukidzi @mpuncel @ramaraochavali @slonka @snowp

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.

Generate Kotlin gRPC Stubs
3 participants