Browse Source

Reduce excessive server logging. (#1011)

Motivation:

When running a unary server, sending the response can put the
HTTP1ToGRPCServerCodec into ignore state.  This happens before
the end of stream is processed.  The 2 end stream messages
(empty buffer of data and end) then trigger logging.

Modifications:

Ignore end and empty data without logging when codec is in
ignore state.

Result:

Less logging and hence faster performance.
Peter Adams 5 years ago
parent
commit
6f47178d9d
1 changed files with 10 additions and 2 deletions
  1. 10 2
      Sources/GRPC/HTTP1ToGRPCServerCodec.swift

+ 10 - 2
Sources/GRPC/HTTP1ToGRPCServerCodec.swift

@@ -129,13 +129,21 @@ extension HTTP1ToGRPCServerCodec: ChannelInboundHandler {
   public typealias InboundOut = _RawGRPCServerRequestPart
   public typealias InboundOut = _RawGRPCServerRequestPart
 
 
   public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
   public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
+    let unwrappedData = self.unwrapInboundIn(data)
     if case .ignore = self.inboundState {
     if case .ignore = self.inboundState {
-      self.logger.notice("ignoring read data", metadata: ["data": "\(data)"])
+      switch unwrappedData {
+      case let .body(body) where body.readableBytes == 0:
+        break // Ignoring a read of zero bytes is always fine.
+      case .end:
+        break // Ignoring an end stream is not an event worth reporting.
+      default:
+        self.logger.notice("ignoring read data", metadata: ["data": "\(unwrappedData)"])
+      }
       return
       return
     }
     }
 
 
     do {
     do {
-      switch self.unwrapInboundIn(data) {
+      switch unwrappedData {
       case let .head(requestHead):
       case let .head(requestHead):
         self.inboundState = try self.processHead(context: context, requestHead: requestHead)
         self.inboundState = try self.processHead(context: context, requestHead: requestHead)