cbickel closed pull request #3756: Report metrics of kafka's queue time.
URL: https://github.com/apache/incubator-openwhisk/pull/3756
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/common/scala/src/main/scala/whisk/common/Logging.scala 
b/common/scala/src/main/scala/whisk/common/Logging.scala
index a82e56b4a7..e5fcfe2eb7 100644
--- a/common/scala/src/main/scala/whisk/common/Logging.scala
+++ b/common/scala/src/main/scala/whisk/common/Logging.scala
@@ -299,6 +299,7 @@ object LoggingMarkers {
 
   // Kafka related markers
   def KAFKA_QUEUE(topic: String) = LogMarkerToken(kafka, topic, count)
+  def KAFKA_MESSAGE_DELAY(topic: String) = LogMarkerToken(kafka, topic, start, 
Some("delay"))
 
   /*
    * General markers
diff --git 
a/common/scala/src/main/scala/whisk/connector/kafka/KafkaConsumerConnector.scala
 
b/common/scala/src/main/scala/whisk/connector/kafka/KafkaConsumerConnector.scala
index 16cbe35415..e551f5b2a3 100644
--- 
a/common/scala/src/main/scala/whisk/connector/kafka/KafkaConsumerConnector.scala
+++ 
b/common/scala/src/main/scala/whisk/connector/kafka/KafkaConsumerConnector.scala
@@ -52,6 +52,10 @@ class KafkaConsumerConnector(
   // It is updated from one thread in "peek", no concurrent data structure is 
necessary
   private var offset: Long = 0
 
+  // Markers for metrics, initialized only once
+  private val queueMetric = LoggingMarkers.KAFKA_QUEUE(topic)
+  private val delayMetric = LoggingMarkers.KAFKA_MESSAGE_DELAY(topic)
+
   /**
    * Long poll for messages. Method returns once message are available but no 
later than given
    * duration.
@@ -65,11 +69,15 @@ class KafkaConsumerConnector(
     val wakeUpTask = 
actorSystem.scheduler.scheduleOnce(cfg.sessionTimeoutMs.milliseconds + 
1.second)(consumer.wakeup())
 
     try {
-      val response = consumer.poll(duration.toMillis).asScala.map(r => 
(r.topic, r.partition, r.offset, r.value))
-      response.lastOption.foreach {
-        case (_, _, newOffset, _) => offset = newOffset + 1
+      val response = consumer.poll(duration.toMillis).asScala
+      val now = System.currentTimeMillis
+
+      response.lastOption.foreach(record => offset = record.offset + 1)
+      response.map { r =>
+        // record the time between producing the message and reading it
+        MetricEmitter.emitHistogramMetric(delayMetric, (now - 
r.timestamp).max(0))
+        (r.topic, r.partition, r.offset, r.value)
       }
-      response
     } catch {
       // Happens if the peek hangs.
       case _: WakeupException if retry > 0 =>
@@ -142,7 +150,7 @@ class KafkaConsumerConnector(
         
consumer.endOffsets(Set(topicAndPartition).asJava).asScala.get(topicAndPartition).foreach
 { endOffset =>
           // endOffset could lag behind the offset reported by the consumer 
internally resulting in negative numbers
           val queueSize = (endOffset - offset).max(0)
-          MetricEmitter.emitHistogramMetric(LoggingMarkers.KAFKA_QUEUE(topic), 
queueSize)
+          MetricEmitter.emitHistogramMetric(queueMetric, queueSize)
         }
       }
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to