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

Implement generic grpc handlers #4295

Merged
merged 9 commits into from
Nov 16, 2022
Merged

Conversation

rbair23
Copy link
Member

@rbair23 rbair23 commented Nov 15, 2022

The classes defined in this PR are pretty close to production ready and represent a best-effort at how to do this properly. Please review carefully:

  • The use of metrics (is this right?). I was unable to reuse the metrics classes in services today because the mono-service module cannot be referenced from the hedera-app module (mono-service is not a proper module today)
  • I added Helidon to the build. I may be able to revert and use plain Netty with minimal changes (I did it once before in the POC). Or we can keep Helidon. I'm torn on it.
  • I updated a few library version numbers in settings.gradle.kts

This implementation is plumbed into IngestWorkflow and QueryWorkflow, but both those workflows are no-ops at the moment (implemented by different issues). As such, this code doesn't actually do anything yet, other than parse incoming bytes and returning empty bytes.

@codecov
Copy link

codecov bot commented Nov 15, 2022

Codecov Report

Base: 0.00% // Head: 96.45% // Increases project coverage by +96.45% 🎉

Coverage data is based on head (5bbb13e) compared to base (a86e228).
Patch coverage: 83.73% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff               @@
##             develop    #4295       +/-   ##
==============================================
+ Coverage           0   96.45%   +96.45%     
- Complexity         0    15029    +15029     
==============================================
  Files              0     1010     +1010     
  Lines              0    42810    +42810     
  Branches           0     4338     +4338     
==============================================
+ Hits               0    41294    +41294     
- Misses             0      764      +764     
- Partials           0      752      +752     
Impacted Files Coverage Δ
...-app/src/main/java/com/hedera/node/app/Hedera.java 0.00% <0.00%> (ø)
.../node/app/workflows/ingest/IngestWorkflowImpl.java 0.00% <0.00%> (ø)
...ra/node/app/workflows/query/QueryWorkflowImpl.java 0.00% <0.00%> (ø)
.../main/java/com/hedera/node/app/SessionContext.java 100.00% <100.00%> (ø)
...a/com/hedera/node/app/grpc/GrpcServiceBuilder.java 100.00% <100.00%> (ø)
...va/com/hedera/node/app/grpc/KnownLengthStream.java 100.00% <100.00%> (ø)
...main/java/com/hedera/node/app/grpc/MethodBase.java 100.00% <100.00%> (ø)
.../java/com/hedera/node/app/grpc/NoopMarshaller.java 100.00% <100.00%> (ø)
...ain/java/com/hedera/node/app/grpc/QueryMethod.java 100.00% <100.00%> (ø)
...va/com/hedera/node/app/grpc/TransactionMethod.java 100.00% <100.00%> (ø)
... and 1000 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tinker-michaelj
Copy link
Collaborator

The use of metrics (is this right?). I was unable to reuse the metrics classes in services today because the mono-service module cannot be referenced from the hedera-app module (mono-service is not a proper module today)

I think the exact names of the metrics are important for the Elastic ingest pipelines; but not an urgent concern.

I updated a few library version numbers in settings.gradle.kts

There may be a version conflict with the io.grpc version coming in via com.hedera.hashgraph:hedera-protobuf-java-api, which is at 1.39.0; I guess we should just bump that one!

Copy link
Collaborator

@tinker-michaelj tinker-michaelj left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@Neeharika-Sompalli Neeharika-Sompalli left a comment

Choose a reason for hiding this comment

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

LGTM ! Few Javadocs missing and have a question on TODOs.

Copy link
Member

@mhess-swl mhess-swl left a comment

Choose a reason for hiding this comment

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

Overall looks great!! Just a couple small comments

@rbair23
Copy link
Member Author

rbair23 commented Nov 16, 2022

Yay, grpc package has 100% Line, Method, and Class coverage :-). There is one case that is only covered in integration tests, which bothers me, and I don't have any tests for metrics. I will add the tests for metrics with issue #4293

Signed-off-by: Richard Bair <[email protected]>
@rbair23
Copy link
Member Author

rbair23 commented Nov 16, 2022

Yay, grpc package has 100% Line, Method, and Class coverage :-). There is one case that is only covered in integration tests, which bothers me, and I don't have any tests for metrics. I will add the tests for metrics with issue #4293

OK, added the test case that bothered me. Sonar is still going to complain because I didn't add tests for Hedera.java, but this is intentional, as this class is not "real" or ready for prime-time. Refactoring that and testing it will come, though probably mainly through itest, which doesn't look like is used for coverage...

@rbair23 rbair23 merged commit aa552a4 into develop Nov 16, 2022
@rbair23 rbair23 deleted the 04203-Implement-generic-grpc-handlers branch November 16, 2022 13:28
@rbair23 rbair23 self-assigned this Nov 16, 2022
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

84.6% 84.6% Coverage
0.0% 0.0% Duplication

// Use when you need logging
bundle("logging", listOf("log4j-api", "log4j-core"))
bundle("logging", listOf("log4j-api", "log4j-core", "log4j-slf4j", "slf4j-api"))
Copy link
Member

Choose a reason for hiding this comment

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

I would not define a logging bundle that contains all this dependencies since some should not be available at compiletime.

From my point of view we should only have a completive dependency to slf4j-api in all new modules. log4j-slf4j and log4j-api / log4j-core should be defined as runtime-only dependencies.

I assume we have the same problem with some other bundles. That's why I'm not a fan of bundles: You can not do the compile / runtime split.

@@ -59,6 +64,9 @@ extraJavaModuleInfo {
automaticModule("io.prometheus:simpleclient_httpserver", "io.prometheus.simpleclient.httpserver")

automaticModule("j2objc-annotations-1.3.jar", "j2objc.annotations")
automaticModule("io.perfmark:perfmark-api", "perfmark.api")
Copy link
Member

Choose a reason for hiding this comment

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

io.perfmark:perfmark-api:0.26.0 defines io.perfmark as automatic module name. We should use the same.

Suggested change
automaticModule("io.perfmark:perfmark-api", "perfmark.api")
automaticModule("io.perfmark:perfmark-api", "io.perfmark")

@@ -59,6 +64,9 @@ extraJavaModuleInfo {
automaticModule("io.prometheus:simpleclient_httpserver", "io.prometheus.simpleclient.httpserver")

automaticModule("j2objc-annotations-1.3.jar", "j2objc.annotations")
automaticModule("io.perfmark:perfmark-api", "perfmark.api")

automaticModule("org.eclipse.microprofile.health:microprofile-health-api", "microprofile.health.api")
Copy link
Member

Choose a reason for hiding this comment

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

ARHG! Unbelievable that such project does not have at least an automatic module name. Created an issue: microprofile/microprofile-health#322

@@ -30,6 +30,11 @@ extraJavaModuleInfo {

automaticModule("io.grpc:grpc-api", "io.grpc.api")
automaticModule("io.grpc:grpc-netty", "io.grpc.netty")
automaticModule("io.grpc:grpc-stub", "grpc.stub")
Copy link
Member

Choose a reason for hiding this comment

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

@@ -21,4 +21,9 @@ description = "Hedera Application - SPI"

dependencies {
implementation(libs.hapi)
implementation(libs.jsr305.annotation)
Copy link
Member

Choose a reason for hiding this comment

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

compileOnly should be used

* @return A reference to the builder.
*/
public @Nonnull GrpcServiceBuilder query(@Nonnull String methodName) {
if (Objects.requireNonNull(methodName).isBlank()) {
Copy link
Member

Choose a reason for hiding this comment

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

should we use the helper methods of the platform commons module for such checks? Still do not now if we want to expose such functionality in the platform or recreate it in the services.

@Nonnull String serviceName,
@Nonnull IngestWorkflow ingestWorkflow,
@Nonnull QueryWorkflow queryWorkflow) {
this.ingestWorkflow = Objects.requireNonNull(ingestWorkflow);
Copy link
Member

Choose a reason for hiding this comment

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

I like to do such runtime null checks next to the compiletime annotation checks. Why should define this as best practice since I've seen several places in the code that does not do such checks

* Create a new instance.
*
* @param serviceName a non-null reference to the service name
* @param methodName a non-null reference to the method name
Copy link
Member

Choose a reason for hiding this comment

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

metrics param is missing

public void invoke(
@Nonnull ByteBuffer requestBuffer,
@Nonnull StreamObserver<ByteBuffer> responseObserver) {
try {
Copy link
Member

Choose a reason for hiding this comment

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

Nullcheck for responseObserver is missing

requires io.helidon.webserver.http2;
requires io.helidon.grpc.server;
requires io.helidon.grpc.core;
requires jsr305;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requires jsr305;
requires static jsr305;

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.

Update the grpc libs to a new version Implement generic gRPC handlers
5 participants