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

grpc over http/2 poc #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gauravAshok
Copy link
Collaborator

@gauravAshok gauravAshok commented Jun 25, 2023

Just a poc to try out the grpc. Vertx recently rolled out a new support for grpc.

TODO:
./gradlew run not working.
cleanup grpc setup.
setup code to perform additional "handling" for grpc requests as well. Http api and grpc api should behave same.
setup & test grpc / http requests over tls connections.

How to try grpc flow?
Use Postman / insomnia. I tried with insomnia and it seemed to work.

@gauravAshok gauravAshok changed the title grpc over http2.0 poc grpc over http/2 poc Jun 25, 2023
@@ -58,6 +87,8 @@ public void start(Promise<Void> startPromise) {
HttpServerOptions options = new HttpServerOptions();
// TODO: why?
options.setDecompressionSupported(false);
options.setAlpnVersions(Arrays.asList(HttpVersion.HTTP_2, HttpVersion.HTTP_1_1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

DEFAULT_ALPN_VERSIONS constant ?

String errorMsg = String.format("Fail to load class %s.", className);
log.error(errorMsg, e);
throw new InvalidConfigException(e);
throw new InvalidConfigException(String.format("Fail to load class %s.", className), e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any thoughts for removing logging ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

logging error and then throwing the same leads to redundant logs.

For eg:

Before

2023-06-26 12:19:05 ERROR CoreServices:85 - Fail to load class com.flipkart.varadhi.pulsar.PulsarStackProvider.
java.lang.ClassNotFoundException: com.flipkart.varadhi.pulsar.PulsarStackProvider
        at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
        at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:?]
        at java.lang.Class.forName(Class.java:375) ~[?:?]
        at com.flipkart.varadhi.CoreServices.loadClass(CoreServices.java:79) [main/:?]
        at com.flipkart.varadhi.CoreServices.setupMessagingStackProvider(CoreServices.java:71) [main/:?]
        at com.flipkart.varadhi.CoreServices.<init>(CoreServices.java:41) [main/:?]
        at com.flipkart.varadhi.Server.main(Server.java:22) [main/:?]
2023-06-26 12:19:05 ERROR Server:27 - Failed to initialise the server.
com.flipkart.varadhi.exceptions.InvalidConfigException: com.flipkart.varadhi.pulsar.PulsarStackProvider
        at com.flipkart.varadhi.CoreServices.loadClass(CoreServices.java:86) ~[main/:?]
        at com.flipkart.varadhi.CoreServices.setupMessagingStackProvider(CoreServices.java:71) ~[main/:?]
        at com.flipkart.varadhi.CoreServices.<init>(CoreServices.java:41) ~[main/:?]
        at com.flipkart.varadhi.Server.main(Server.java:22) [main/:?]
Caused by: java.lang.ClassNotFoundException: com.flipkart.varadhi.pulsar.PulsarStackProvider
        at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
        at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:?]
        at java.lang.Class.forName(Class.java:375) ~[?:?]
        at com.flipkart.varadhi.CoreServices.loadClass(CoreServices.java:79) ~[main/:?]
        ... 3 more
Failed to initialise the server:com.flipkart.varadhi.exceptions.InvalidConfigException: com.flipkart.varadhi.pulsar.PulsarStackProvider

After

2023-06-26 12:19:53 ERROR Server:27 - Failed to initialise the server.
com.flipkart.varadhi.exceptions.InvalidConfigException: Fail to load class com.flipkart.varadhi.pulsar.PulsarStackProvider.
        at com.flipkart.varadhi.CoreServices.loadClass(CoreServices.java:84) ~[main/:?]
        at com.flipkart.varadhi.CoreServices.setupMessagingStackProvider(CoreServices.java:71) ~[main/:?]
        at com.flipkart.varadhi.CoreServices.<init>(CoreServices.java:41) ~[main/:?]
        at com.flipkart.varadhi.Server.main(Server.java:22) [main/:?]
Caused by: java.lang.ClassNotFoundException: com.flipkart.varadhi.pulsar.PulsarStackProvider
        at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
        at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:?]
        at java.lang.Class.forName(Class.java:375) ~[?:?]
        at com.flipkart.varadhi.CoreServices.loadClass(CoreServices.java:79) ~[main/:?]
        ... 3 more

Copy link
Collaborator Author

@gauravAshok gauravAshok Jun 26, 2023

Choose a reason for hiding this comment

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

I try to follow the rule for error logs which says: Don't log if you are throwing. can log if you are handling.

Copy link
Collaborator

Choose a reason for hiding this comment

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

generally I tend to follow log at source of the event to capture all data along that leads to exception.
But I guess, we can avoid exception logging from that and keep only data part and leave exception logging to either default exception handler at base or log where it is being handled ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can still capture what we want to capture in the "exception" that we are throwing.

.path("/topics/produce")
.method(HttpMethod.POST)
.handler(rc -> Extensions.RoutingContextExtension.endRequestWithResponse(rc, 200, "0001"));

Copy link
Collaborator

Choose a reason for hiding this comment

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

Planning to keep it or move it appropriately to ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ya. its a TODO, will fix it in this PR.

Copy link
Collaborator

@kmrdhruv kmrdhruv left a comment

Choose a reason for hiding this comment

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

refactoring changes LGTM.
for grpc, lets put it in appropriate location.

@gauravAshok
Copy link
Collaborator Author

refactoring changes LGTM. for grpc, lets put it in appropriate location.

I pulled the refactoring changes into a different PR and merged that in master. This PR now only contains grpc specific additions.

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