services: binlog method name should include leading / char (#4588)
The APIs of the other implementations all begin method names with `/`,
since the binlog is language agnostic we should be aligned.
diff --git a/services/src/main/java/io/grpc/services/BinlogHelper.java b/services/src/main/java/io/grpc/services/BinlogHelper.java
index f731ea3..2795f4f 100644
--- a/services/src/main/java/io/grpc/services/BinlogHelper.java
+++ b/services/src/main/java/io/grpc/services/BinlogHelper.java
@@ -119,6 +119,9 @@
CallId callId) {
Preconditions.checkArgument(methodName == null || !isServer);
Preconditions.checkArgument(timeout == null || !isServer);
+ // Java does not include the leading '/'. To be consistent with the rest of gRPC we must
+ // include the '/' in the fully qualified name for binlogs.
+ Preconditions.checkArgument(methodName == null || !methodName.startsWith("/"));
GrpcLogEntry.Builder entryBuilder = GrpcLogEntry.newBuilder()
.setSequenceIdWithinCall(seq)
.setType(Type.SEND_INITIAL_METADATA)
@@ -126,7 +129,7 @@
.setCallId(callIdToProto(callId));
addMetadataToProto(entryBuilder, metadata, maxHeaderBytes);
if (methodName != null) {
- entryBuilder.setMethodName(methodName);
+ entryBuilder.setMethodName("/" + methodName);
}
if (timeout != null) {
entryBuilder.setTimeout(timeout);
@@ -145,6 +148,9 @@
SocketAddress peerSocket) {
Preconditions.checkArgument(methodName == null || isServer);
Preconditions.checkArgument(timeout == null || isServer);
+ // Java does not include the leading '/'. To be consistent with the rest of gRPC we must
+ // include the '/' in the fully qualified name for binlogs.
+ Preconditions.checkArgument(methodName == null || !methodName.startsWith("/"));
GrpcLogEntry.Builder entryBuilder = GrpcLogEntry.newBuilder()
.setSequenceIdWithinCall(seq)
.setType(Type.RECV_INITIAL_METADATA)
@@ -153,7 +159,7 @@
.setPeer(socketToProto(peerSocket));
addMetadataToProto(entryBuilder, metadata, maxHeaderBytes);
if (methodName != null) {
- entryBuilder.setMethodName(methodName);
+ entryBuilder.setMethodName("/" + methodName);
}
if (timeout != null) {
entryBuilder.setTimeout(timeout);
diff --git a/services/src/test/java/io/grpc/services/BinlogHelperTest.java b/services/src/test/java/io/grpc/services/BinlogHelperTest.java
index d7b0d0c..4ad7f8b 100644
--- a/services/src/test/java/io/grpc/services/BinlogHelperTest.java
+++ b/services/src/test/java/io/grpc/services/BinlogHelperTest.java
@@ -575,7 +575,7 @@
verify(sink).write(
metadataToProtoTestHelper(nonEmptyMetadata, 10).toBuilder()
.setSequenceIdWithinCall(1)
- .setMethodName("service/method")
+ .setMethodName("/service/method")
.setTimeout(Durations.fromMillis(1234))
.setType(GrpcLogEntry.Type.SEND_INITIAL_METADATA)
.setLogger(GrpcLogEntry.Logger.CLIENT)
@@ -592,7 +592,7 @@
verify(sink).write(
metadataToProtoTestHelper(nonEmptyMetadata, 10).toBuilder()
.setSequenceIdWithinCall(1)
- .setMethodName("service/method")
+ .setMethodName("/service/method")
.setType(GrpcLogEntry.Type.SEND_INITIAL_METADATA)
.setLogger(GrpcLogEntry.Logger.CLIENT)
.setCallId(BinlogHelper.callIdToProto(CALL_ID))
@@ -615,7 +615,7 @@
verify(sink).write(
metadataToProtoTestHelper(nonEmptyMetadata, 10).toBuilder()
.setSequenceIdWithinCall(1)
- .setMethodName("service/method")
+ .setMethodName("/service/method")
.setTimeout(Durations.fromMillis(1234))
.setType(GrpcLogEntry.Type.RECV_INITIAL_METADATA)
.setLogger(GrpcLogEntry.Logger.SERVER)
@@ -634,7 +634,7 @@
verify(sink).write(
metadataToProtoTestHelper(nonEmptyMetadata, 10).toBuilder()
.setSequenceIdWithinCall(1)
- .setMethodName("service/method")
+ .setMethodName("/service/method")
.setType(GrpcLogEntry.Type.RECV_INITIAL_METADATA)
.setLogger(GrpcLogEntry.Logger.SERVER)
.setCallId(BinlogHelper.callIdToProto(CALL_ID))