Improve trace logging in RequestChannel.sendResponse
It now records the correct size for `Send` and does more appropriate
logging if the connection is being closed or if no response is being
sent.
Author: huxihx
Reviewers: Denis Bolshakov, Ismael Juma
Closes from huxihx/KAFKA-5976
@@ -23,8 +23,7 @@ import java.util.concurrent._
import com.yammer.metrics.core.Gauge
import kafka.metrics.KafkaMetricsGroup
-import kafka.network.RequestChannel.{ShutdownRequest, BaseRequest}
-import kafka.server.QuotaId
+import kafka.network.RequestChannel.{BaseRequest, SendAction, ShutdownRequest, NoOpAction, CloseConnectionAction}
import kafka.utils.{Logging, NotNothing}
import org.apache.kafka.common.memory.MemoryPool
import org.apache.kafka.common.metrics.Sanitizer
@@ -204,7 +203,7 @@ object RequestChannel extends Logging {
s"Response(request=$request, responseSend=$responseSend, responseAction=$responseAction), responseAsString=$responseAsString"
}
- trait ResponseAction
+ sealed trait ResponseAction
case object SendAction extends ResponseAction
case object NoOpAction extends ResponseAction
case object CloseConnectionAction extends ResponseAction
@@ -246,8 +245,15 @@ class RequestChannel(val numProcessors: Int, val queueSize: Int) extends KafkaMe
def sendResponse(response: RequestChannel.Response) {
if (isTraceEnabled) {
val requestHeader = response.request.header
- trace(s"Sending ${requestHeader.apiKey} response to client ${requestHeader.clientId} of " +
- s"${response.responseSend.size} bytes.")
+ val message = response.responseAction match {
+ case SendAction =>
+ s"Sending ${requestHeader.apiKey} response to client ${requestHeader.clientId} of ${response.responseSend.get.size} bytes."
+ case NoOpAction =>
+ s"Not sending ${requestHeader.apiKey} response to client ${requestHeader.clientId} as it's not required."
+ case CloseConnectionAction =>
+ s"Closing connection for client ${requestHeader.clientId} due to error during ${requestHeader.apiKey}."
+ }
+ trace(message)
}
responseQueues(response.processor).put(response)
