Skip to content

Commit cd5d410

Browse files
authored
Add grpc-gateway helper types (#102)
Signed-off-by: Yuri Shkuro <[email protected]>
1 parent f893926 commit cd5d410

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PROTOTOOL_VER=1.8.0
1111
PROTOTOOL_IMAGE=uber/prototool:$(PROTOTOOL_VER)
1212
PROTOTOOL=docker run --rm -u ${shell id -u} -v "${PWD}:/go/src/${PROJECT_ROOT}" -w /go/src/${PROJECT_ROOT} $(PROTOTOOL_IMAGE)
1313

14-
PROTOC_VER=0.4.0
14+
PROTOC_VER=0.5.0
1515
PROTOC_IMAGE=jaegertracing/protobuf:$(PROTOC_VER)
1616
PROTOC=docker run --rm -u ${shell id -u} -v "${PWD}:${PWD}" -w ${PWD} ${PROTOC_IMAGE} --proto_path=${PWD}
1717

proto/api_v3/query_service.proto

+27
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,30 @@ service QueryService {
130130
// GetOperations returns operation names.
131131
rpc GetOperations(GetOperationsRequest) returns (GetOperationsResponse) {}
132132
}
133+
134+
// Below are some helper types when using APIv3 via HTTP endpoints implemented via grpc-gateway.
135+
136+
// GRPCGatewayError is the type returned when GRPC server returns an error.
137+
// Note that for streaming responses it would be wrapped in GRPCGatewayWrapper below.
138+
// Example: {"error":{"grpcCode":2,"httpCode":500,"message":"...","httpStatus":"text..."}}.
139+
message GRPCGatewayError {
140+
message GRPCGatewayErrorDetails {
141+
int32 grpcCode = 1;
142+
int32 httpCode = 2;
143+
string message = 3;
144+
string httpStatus = 4;
145+
}
146+
147+
GRPCGatewayErrorDetails error = 1;
148+
}
149+
150+
// GRPCGatewayWrapper is a type returned when GRPC service returns a stream.
151+
// For some unknown reason grpc-gateway/v1 wraps chunk responses in {"result": {actual output}}.
152+
// See https://github.com/grpc-ecosystem/grpc-gateway/issues/2189
153+
// TODO: it's not clear what happens when the server returns more than one chunk.
154+
// The gateway will presumably combine then into a single HTTP response.
155+
// Currently this is not possible because even though APIv3 GRPC Service is using output stream,
156+
// its implementation reads all spans from QueryService at once and forms only a single chunk.
157+
message GRPCGatewayWrapper {
158+
SpansResponseChunk result = 1;
159+
}

0 commit comments

Comments
 (0)