Skip to content

Commit

Permalink
Merge pull request #36 from openinsight-proj/add_getGRPCStatus_to_ads…
Browse files Browse the repository at this point in the history
…ervicev2

add GetGRPCStatus API to adservice-v2
  • Loading branch information
Frapschen authored Aug 20, 2024
2 parents db80204 + 8251f65 commit 46301ed
Show file tree
Hide file tree
Showing 5 changed files with 1,049 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/adservice-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ to specific the matrix size
the `oteldemo.AdService/GetAds` API will return error randomly(50%), you can use `-Dspring.randomError=false`
to disable this feature.

## mock gRPC status code

the `oteldemo.AdService/getGRPCStatus` API will return the gRPC status code, which correspond to the request `status_code` param.
```shell
grpcurl -plaintext -d '{"status_code": 0}' localhost:8080 oteldemo.AdService/GetGRPCStatus
```

## Integrate to Nacos and Sentinel

Expand Down
74 changes: 74 additions & 0 deletions src/adservice-v2/src/main/java-grpc/oteldemo/AdServiceGrpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ oteldemo.Demo.AdResponse> getGetAdsMethod() {
return getGetAdsMethod;
}

private static volatile io.grpc.MethodDescriptor<oteldemo.Demo.StatusRequest,
oteldemo.Demo.Empty> getGetGRPCStatusMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "GetGRPCStatus",
requestType = oteldemo.Demo.StatusRequest.class,
responseType = oteldemo.Demo.Empty.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<oteldemo.Demo.StatusRequest,
oteldemo.Demo.Empty> getGetGRPCStatusMethod() {
io.grpc.MethodDescriptor<oteldemo.Demo.StatusRequest, oteldemo.Demo.Empty> getGetGRPCStatusMethod;
if ((getGetGRPCStatusMethod = AdServiceGrpc.getGetGRPCStatusMethod) == null) {
synchronized (AdServiceGrpc.class) {
if ((getGetGRPCStatusMethod = AdServiceGrpc.getGetGRPCStatusMethod) == null) {
AdServiceGrpc.getGetGRPCStatusMethod = getGetGRPCStatusMethod =
io.grpc.MethodDescriptor.<oteldemo.Demo.StatusRequest, oteldemo.Demo.Empty>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetGRPCStatus"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
oteldemo.Demo.StatusRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
oteldemo.Demo.Empty.getDefaultInstance()))
.setSchemaDescriptor(new AdServiceMethodDescriptorSupplier("GetGRPCStatus"))
.build();
}
}
}
return getGetGRPCStatusMethod;
}

/**
* Creates a new async stub that supports all call types for the service
*/
Expand Down Expand Up @@ -101,6 +132,13 @@ public void getAds(oteldemo.Demo.AdRequest request,
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetAdsMethod(), responseObserver);
}

/**
*/
public void getGRPCStatus(oteldemo.Demo.StatusRequest request,
io.grpc.stub.StreamObserver<oteldemo.Demo.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetGRPCStatusMethod(), responseObserver);
}

@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
Expand All @@ -110,6 +148,13 @@ public void getAds(oteldemo.Demo.AdRequest request,
oteldemo.Demo.AdRequest,
oteldemo.Demo.AdResponse>(
this, METHODID_GET_ADS)))
.addMethod(
getGetGRPCStatusMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
new MethodHandlers<
oteldemo.Demo.StatusRequest,
oteldemo.Demo.Empty>(
this, METHODID_GET_GRPCSTATUS)))
.build();
}
}
Expand All @@ -135,6 +180,14 @@ public void getAds(oteldemo.Demo.AdRequest request,
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getGetAdsMethod(), getCallOptions()), request, responseObserver);
}

/**
*/
public void getGRPCStatus(oteldemo.Demo.StatusRequest request,
io.grpc.stub.StreamObserver<oteldemo.Demo.Empty> responseObserver) {
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getGetGRPCStatusMethod(), getCallOptions()), request, responseObserver);
}
}

/**
Expand All @@ -157,6 +210,13 @@ public oteldemo.Demo.AdResponse getAds(oteldemo.Demo.AdRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getGetAdsMethod(), getCallOptions(), request);
}

/**
*/
public oteldemo.Demo.Empty getGRPCStatus(oteldemo.Demo.StatusRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getGetGRPCStatusMethod(), getCallOptions(), request);
}
}

/**
Expand All @@ -180,9 +240,18 @@ public com.google.common.util.concurrent.ListenableFuture<oteldemo.Demo.AdRespon
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getGetAdsMethod(), getCallOptions()), request);
}

/**
*/
public com.google.common.util.concurrent.ListenableFuture<oteldemo.Demo.Empty> getGRPCStatus(
oteldemo.Demo.StatusRequest request) {
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getGetGRPCStatusMethod(), getCallOptions()), request);
}
}

private static final int METHODID_GET_ADS = 0;
private static final int METHODID_GET_GRPCSTATUS = 1;

private static final class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
Expand All @@ -205,6 +274,10 @@ public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserv
serviceImpl.getAds((oteldemo.Demo.AdRequest) request,
(io.grpc.stub.StreamObserver<oteldemo.Demo.AdResponse>) responseObserver);
break;
case METHODID_GET_GRPCSTATUS:
serviceImpl.getGRPCStatus((oteldemo.Demo.StatusRequest) request,
(io.grpc.stub.StreamObserver<oteldemo.Demo.Empty>) responseObserver);
break;
default:
throw new AssertionError();
}
Expand Down Expand Up @@ -267,6 +340,7 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new AdServiceFileDescriptorSupplier())
.addMethod(getGetAdsMethod())
.addMethod(getGetGRPCStatusMethod())
.build();
}
}
Expand Down
Loading

0 comments on commit 46301ed

Please sign in to comment.