From 3b98838be61fa58d86805879a5fc4b13511ed69e Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 16 Apr 2018 09:03:26 -0700 Subject: This CL adds log entry protos and logging handlers for bytestream Read and Write so that they are logged. I'm open to suggestions for the logging format for these calls, since we don't want to log the actual contents of reads/writes because of their size. PiperOrigin-RevId: 193047886 --- .../google/devtools/build/lib/remote/logging/BUILD | 2 + .../lib/remote/logging/LoggingInterceptor.java | 5 +++ .../build/lib/remote/logging/ReadHandler.java | 45 +++++++++++++++++++ .../build/lib/remote/logging/WriteHandler.java | 51 ++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/lib/remote/logging/ReadHandler.java create mode 100644 src/main/java/com/google/devtools/build/lib/remote/logging/WriteHandler.java (limited to 'src/main/java/com/google/devtools') diff --git a/src/main/java/com/google/devtools/build/lib/remote/logging/BUILD b/src/main/java/com/google/devtools/build/lib/remote/logging/BUILD index d2998ae152..dc1caa6266 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/logging/BUILD +++ b/src/main/java/com/google/devtools/build/lib/remote/logging/BUILD @@ -16,6 +16,8 @@ java_library( "//src/main/protobuf:remote_execution_log_java_proto", "//third_party:guava", "//third_party/grpc:grpc-jar", + "@googleapis//:google_bytestream_bytestream_java_grpc", + "@googleapis//:google_bytestream_bytestream_java_proto", "@googleapis//:google_devtools_remoteexecution_v1test_remote_execution_java_grpc", "@googleapis//:google_devtools_remoteexecution_v1test_remote_execution_java_proto", "@googleapis//:google_longrunning_operations_java_proto", diff --git a/src/main/java/com/google/devtools/build/lib/remote/logging/LoggingInterceptor.java b/src/main/java/com/google/devtools/build/lib/remote/logging/LoggingInterceptor.java index fa657ba19a..a805eae83b 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/logging/LoggingInterceptor.java +++ b/src/main/java/com/google/devtools/build/lib/remote/logging/LoggingInterceptor.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.remote.logging; +import com.google.bytestream.ByteStreamGrpc; import com.google.devtools.build.lib.remote.logging.RemoteExecutionLog.LogEntry; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; import com.google.devtools.build.lib.util.io.AsynchronousFileOutputStream; @@ -59,6 +60,10 @@ public class LoggingInterceptor implements ClientInterceptor { return new GetActionResultHandler(); } else if (method == ContentAddressableStorageGrpc.getFindMissingBlobsMethod()) { return new FindMissingBlobsHandler(); + } else if (method == ByteStreamGrpc.getReadMethod()) { + return new ReadHandler(); + } else if (method == ByteStreamGrpc.getWriteMethod()) { + return new WriteHandler(); } return null; } diff --git a/src/main/java/com/google/devtools/build/lib/remote/logging/ReadHandler.java b/src/main/java/com/google/devtools/build/lib/remote/logging/ReadHandler.java new file mode 100644 index 0000000000..8c43f40e5c --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/remote/logging/ReadHandler.java @@ -0,0 +1,45 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.remote.logging; + +import com.google.bytestream.ByteStreamProto.ReadRequest; +import com.google.bytestream.ByteStreamProto.ReadResponse; +import com.google.devtools.build.lib.remote.logging.RemoteExecutionLog.ReadDetails; +import com.google.devtools.build.lib.remote.logging.RemoteExecutionLog.RpcCallDetails; + +/** LoggingHandler for {@link google.bytestream.Read} gRPC call. */ +public class ReadHandler implements LoggingHandler { + private final ReadDetails.Builder builder = ReadDetails.newBuilder(); + private long numReads = 0; + private long bytesRead = 0; + + @Override + public void handleReq(ReadRequest message) { + builder.setRequest(message); + } + + @Override + public void handleResp(ReadResponse message) { + numReads++; + bytesRead += message.getData().size(); + } + + @Override + public RpcCallDetails getDetails() { + builder.setNumReads(numReads); + builder.setBytesRead(bytesRead); + return RpcCallDetails.newBuilder().setRead(builder).build(); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/remote/logging/WriteHandler.java b/src/main/java/com/google/devtools/build/lib/remote/logging/WriteHandler.java new file mode 100644 index 0000000000..67e9e378e2 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/remote/logging/WriteHandler.java @@ -0,0 +1,51 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.remote.logging; + +import com.google.bytestream.ByteStreamProto.WriteRequest; +import com.google.bytestream.ByteStreamProto.WriteResponse; +import com.google.devtools.build.lib.remote.logging.RemoteExecutionLog.RpcCallDetails; +import com.google.devtools.build.lib.remote.logging.RemoteExecutionLog.WriteDetails; +import java.util.LinkedHashSet; +import java.util.Set; + +/** LoggingHandler for {@link google.bytestream.Write} gRPC call. */ +public class WriteHandler implements LoggingHandler { + private final WriteDetails.Builder builder = WriteDetails.newBuilder(); + private final Set resources = new LinkedHashSet<>(); + private long numWrites = 0; + private long bytesSent = 0; + + @Override + public void handleReq(WriteRequest message) { + resources.add(message.getResourceName()); + + numWrites++; + bytesSent += message.getData().size(); + } + + @Override + public void handleResp(WriteResponse message) { + builder.setResponse(message); + } + + @Override + public RpcCallDetails getDetails() { + builder.addAllResourceNames(resources); + builder.setNumWrites(numWrites); + builder.setBytesSent(bytesSent); + return RpcCallDetails.newBuilder().setWrite(builder).build(); + } +} -- cgit v1.2.3