This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 7633332  Use Gauge metric instead of Histogram where applicable (#4327)
7633332 is described below

commit 76333322e1e9bc77001ec398dd9f68feb85df460
Author: Chetan Mehrotra <[email protected]>
AuthorDate: Mon Mar 11 18:46:42 2019 +0530

    Use Gauge metric instead of Histogram where applicable (#4327)
    
    * Kamon Gauge abstraction
    
    * Switch to gauge metric
---
 .../org/apache/openwhisk/common/Logging.scala      | 26 +++++++++++++++++-
 .../connector/kafka/KafkaConsumerConnector.scala   |  2 +-
 .../core/loadBalancer/CommonLoadBalancer.scala     | 12 ++++----
 .../openwhisk/core/loadBalancer/LeanBalancer.scala |  4 +--
 .../ShardingContainerPoolBalancer.scala            | 32 ++++++++--------------
 5 files changed, 46 insertions(+), 30 deletions(-)

diff --git 
a/common/scala/src/main/scala/org/apache/openwhisk/common/Logging.scala 
b/common/scala/src/main/scala/org/apache/openwhisk/common/Logging.scala
index e5ff182..1a336fc 100644
--- a/common/scala/src/main/scala/org/apache/openwhisk/common/Logging.scala
+++ b/common/scala/src/main/scala/org/apache/openwhisk/common/Logging.scala
@@ -24,7 +24,7 @@ import java.time.format.DateTimeFormatter
 import akka.event.Logging._
 import akka.event.LoggingAdapter
 import kamon.Kamon
-import kamon.metric.{MeasurementUnit, Counter => KCounter, Histogram => 
KHistogram}
+import kamon.metric.{MeasurementUnit, Counter => KCounter, Histogram => 
KHistogram, Gauge => KGauge}
 import kamon.statsd.{MetricKeyGenerator, SimpleMetricKeyGenerator}
 import kamon.system.SystemMetrics
 import org.apache.openwhisk.core.entity.ControllerInstanceId
@@ -194,6 +194,7 @@ case class LogMarkerToken(
   // (given the same key) are always the same, so a missed update is not 
harmful
   private var _counter: KCounter = _
   private var _histogram: KHistogram = _
+  private var _gauge: KGauge = _
 
   override val toString = component + "_" + action + "_" + state
   val toStringWithSubAction: String =
@@ -227,6 +228,13 @@ case class LogMarkerToken(
     _histogram
   }
 
+  def gauge: KGauge = {
+    if (_gauge == null) {
+      _gauge = createGauge()
+    }
+    _gauge
+  }
+
   private def createCounter() = {
     if (TransactionId.metricsKamonTags) {
       Kamon
@@ -247,6 +255,16 @@ case class LogMarkerToken(
     }
   }
 
+  private def createGauge() = {
+    if (TransactionId.metricsKamonTags) {
+      Kamon
+        .gauge(createName(toString, "gauge"), measurementUnit)
+        .refine(tags)
+    } else {
+      Kamon.gauge(createName(toStringWithSubAction, "gauge"), measurementUnit)
+    }
+  }
+
   /**
    * Kamon 1.0 onwards does not include the metric type in the metric name 
which cause issue
    * for us as we use same metric name for counter and histogram. So to be 
backward compatible we
@@ -291,6 +309,12 @@ object MetricEmitter {
       token.histogram.record(value)
     }
   }
+
+  def emitGaugeMetric(token: LogMarkerToken, value: Long): Unit = {
+    if (TransactionId.metricsKamon) {
+      token.gauge.set(value)
+    }
+  }
 }
 
 /**
diff --git 
a/common/scala/src/main/scala/org/apache/openwhisk/connector/kafka/KafkaConsumerConnector.scala
 
b/common/scala/src/main/scala/org/apache/openwhisk/connector/kafka/KafkaConsumerConnector.scala
index 51ef83e..7e673d1 100644
--- 
a/common/scala/src/main/scala/org/apache/openwhisk/connector/kafka/KafkaConsumerConnector.scala
+++ 
b/common/scala/src/main/scala/org/apache/openwhisk/connector/kafka/KafkaConsumerConnector.scala
@@ -190,7 +190,7 @@ class KafkaConsumerConnector(
             endOffset =>
               // endOffset could lag behind the offset reported by the 
consumer internally resulting in negative numbers
               val queueSize = (endOffset - offset).max(0)
-              MetricEmitter.emitHistogramMetric(queueMetric, queueSize)
+              MetricEmitter.emitGaugeMetric(queueMetric, queueSize)
           }
         }
       }
diff --git 
a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/CommonLoadBalancer.scala
 
b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/CommonLoadBalancer.scala
index 969c087..724a5f7 100644
--- 
a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/CommonLoadBalancer.scala
+++ 
b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/CommonLoadBalancer.scala
@@ -64,20 +64,20 @@ abstract class CommonLoadBalancer(config: WhiskConfig,
   protected val totalBlackBoxActivationMemory = new LongAdder()
   protected val totalManagedActivationMemory = new LongAdder()
 
-  protected def emitHistogramMetric() = {
-    
MetricEmitter.emitHistogramMetric(LOADBALANCER_ACTIVATIONS_INFLIGHT(controllerInstance),
 totalActivations.longValue)
-    MetricEmitter.emitHistogramMetric(
+  protected def emitMetrics() = {
+    
MetricEmitter.emitGaugeMetric(LOADBALANCER_ACTIVATIONS_INFLIGHT(controllerInstance),
 totalActivations.longValue)
+    MetricEmitter.emitGaugeMetric(
       LOADBALANCER_MEMORY_INFLIGHT(controllerInstance, ""),
       totalBlackBoxActivationMemory.longValue + 
totalManagedActivationMemory.longValue)
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(
       LOADBALANCER_MEMORY_INFLIGHT(controllerInstance, "Blackbox"),
       totalBlackBoxActivationMemory.longValue)
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(
       LOADBALANCER_MEMORY_INFLIGHT(controllerInstance, "Managed"),
       totalManagedActivationMemory.longValue)
   }
 
-  actorSystem.scheduler.schedule(10.seconds, 10.seconds)(emitHistogramMetric())
+  actorSystem.scheduler.schedule(10.seconds, 10.seconds)(emitMetrics())
 
   override def activeActivationsFor(namespace: UUID): Future[Int] =
     
Future.successful(activationsPerNamespace.get(namespace).map(_.intValue()).getOrElse(0))
diff --git 
a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala
 
b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala
index 130203a..af84662 100644
--- 
a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala
+++ 
b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/LeanBalancer.scala
@@ -82,8 +82,8 @@ class LeanBalancer(config: WhiskConfig,
     // Currently do nothing
   }
 
-  override protected def emitHistogramMetric() = {
-    super.emitHistogramMetric()
+  override protected def emitMetrics() = {
+    super.emitMetrics()
   }
 }
 
diff --git 
a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
 
b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
index 0464393..174aeb1 100644
--- 
a/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
+++ 
b/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
@@ -163,9 +163,9 @@ class ShardingContainerPoolBalancer(
     None
   }
 
-  override protected def emitHistogramMetric() = {
-    super.emitHistogramMetric()
-    MetricEmitter.emitHistogramMetric(
+  override protected def emitMetrics() = {
+    super.emitMetrics()
+    MetricEmitter.emitGaugeMetric(
       INVOKER_TOTALMEM_BLACKBOX,
       schedulingState.blackboxInvokers.foldLeft(0L) { (total, curr) =>
         if (curr.status.isUsable) {
@@ -174,7 +174,7 @@ class ShardingContainerPoolBalancer(
           total
         }
       })
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(
       INVOKER_TOTALMEM_MANAGED,
       schedulingState.managedInvokers.foldLeft(0L) { (total, curr) =>
         if (curr.status.isUsable) {
@@ -183,30 +183,22 @@ class ShardingContainerPoolBalancer(
           total
         }
       })
-    MetricEmitter.emitHistogramMetric(
-      HEALTHY_INVOKER_MANAGED,
-      schedulingState.managedInvokers.count(_.status == Healthy))
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(HEALTHY_INVOKER_MANAGED, 
schedulingState.managedInvokers.count(_.status == Healthy))
+    MetricEmitter.emitGaugeMetric(
       UNHEALTHY_INVOKER_MANAGED,
       schedulingState.managedInvokers.count(_.status == Unhealthy))
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(
       UNRESPONSIVE_INVOKER_MANAGED,
       schedulingState.managedInvokers.count(_.status == Unresponsive))
-    MetricEmitter.emitHistogramMetric(
-      OFFLINE_INVOKER_MANAGED,
-      schedulingState.managedInvokers.count(_.status == Offline))
-    MetricEmitter.emitHistogramMetric(
-      HEALTHY_INVOKER_BLACKBOX,
-      schedulingState.blackboxInvokers.count(_.status == Healthy))
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(OFFLINE_INVOKER_MANAGED, 
schedulingState.managedInvokers.count(_.status == Offline))
+    MetricEmitter.emitGaugeMetric(HEALTHY_INVOKER_BLACKBOX, 
schedulingState.blackboxInvokers.count(_.status == Healthy))
+    MetricEmitter.emitGaugeMetric(
       UNHEALTHY_INVOKER_BLACKBOX,
       schedulingState.blackboxInvokers.count(_.status == Unhealthy))
-    MetricEmitter.emitHistogramMetric(
+    MetricEmitter.emitGaugeMetric(
       UNRESPONSIVE_INVOKER_BLACKBOX,
       schedulingState.blackboxInvokers.count(_.status == Unresponsive))
-    MetricEmitter.emitHistogramMetric(
-      OFFLINE_INVOKER_BLACKBOX,
-      schedulingState.blackboxInvokers.count(_.status == Offline))
+    MetricEmitter.emitGaugeMetric(OFFLINE_INVOKER_BLACKBOX, 
schedulingState.blackboxInvokers.count(_.status == Offline))
   }
 
   /** State needed for scheduling. */

Reply via email to