[GitHub] [openwhisk] rabbah commented on a change in pull request #4584: OpenWhisk User Events

2019-09-12 Thread GitBox
rabbah commented on a change in pull request #4584: OpenWhisk User Events
URL: https://github.com/apache/openwhisk/pull/4584#discussion_r323662152
 
 

 ##
 File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala
 ##
 @@ -223,6 +256,15 @@ object Activation extends DefaultJsonProtocol {
   "memory",
   "causedBy")
 
+  /**
+   * Extract namespace and action from name
+   * ex. whisk.system/apimgmt/createApi -> (whisk.system, apimgmt/createApi)
+   */
+  def getNamespaceAndActionName(name: String): (String, String) = {
 
 Review comment:
   it may be helpful to use `EntityPath(name).toFullyQualifiedEntityName` 
instead as there could be an optional a leading slash... up to you.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [openwhisk] rabbah commented on a change in pull request #4584: OpenWhisk User Events

2019-09-12 Thread GitBox
rabbah commented on a change in pull request #4584: OpenWhisk User Events
URL: https://github.com/apache/openwhisk/pull/4584#discussion_r323660047
 
 

 ##
 File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala
 ##
 @@ -194,22 +196,53 @@ object EventMessageBody extends DefaultJsonProtocol {
 
 case class Activation(name: String,
   statusCode: Int,
-  duration: Long,
-  waitTime: Long,
-  initTime: Long,
+  duration: Duration,
+  waitTime: Duration,
+  initTime: Duration,
   kind: String,
   conductor: Boolean,
   memory: Int,
   causedBy: Option[String])
 extends EventMessageBody {
-  val typeName = "Activation"
+  val typeName = Activation.typeName
   override def serialize = toJson.compactPrint
 
   def toJson = Activation.activationFormat.write(this)
+
+  def status: String = statusCode match {
 
 Review comment:
   +1


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [openwhisk] rabbah commented on a change in pull request #4584: OpenWhisk User Events

2019-09-12 Thread GitBox
rabbah commented on a change in pull request #4584: OpenWhisk User Events
URL: https://github.com/apache/openwhisk/pull/4584#discussion_r323664296
 
 

 ##
 File path: 
core/monitoring/user-events/src/main/scala/org/apache/openwhisk/core/monitoring/metrics/KamonRecorder.scala
 ##
 @@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openwhisk.core.monitoring.metrics
+
+import akka.event.slf4j.SLF4JLogging
+import org.apache.openwhisk.core.connector.{Activation, Metric}
+import kamon.Kamon
+import kamon.metric.MeasurementUnit
+
+import scala.collection.concurrent.TrieMap
+
+trait KamonMetricNames extends MetricNames {
+  val activationMetric = "openwhisk.action.activations"
+  val coldStartMetric = "openwhisk.action.coldStarts"
+  val waitTimeMetric = "openwhisk.action.waitTime"
+  val initTimeMetric = "openwhisk.action.initTime"
+  val durationMetric = "openwhisk.action.duration"
+  val statusMetric = "openwhisk.action.status"
+
+  val concurrentLimitMetric = "openwhisk.action.limit.concurrent"
+  val timedLimitMetric = "openwhisk.action.limit.timed"
+}
+
+object KamonRecorder extends MetricRecorder with KamonMetricNames with 
SLF4JLogging {
+  private val activationMetrics = new TrieMap[String, ActivationKamonMetrics]
+  private val limitMetrics = new TrieMap[String, LimitKamonMetrics]
+
+  override def processActivation(activation: Activation, initiatorNamespace: 
String): Unit = {
 
 Review comment:
   perhaps this pr #4609 makes it easier.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [openwhisk] rabbah commented on a change in pull request #4584: OpenWhisk User Events

2019-09-12 Thread GitBox
rabbah commented on a change in pull request #4584: OpenWhisk User Events
URL: https://github.com/apache/openwhisk/pull/4584#discussion_r323660551
 
 

 ##
 File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala
 ##
 @@ -194,22 +196,53 @@ object EventMessageBody extends DefaultJsonProtocol {
 
 case class Activation(name: String,
   statusCode: Int,
-  duration: Long,
-  waitTime: Long,
-  initTime: Long,
+  duration: Duration,
+  waitTime: Duration,
+  initTime: Duration,
   kind: String,
   conductor: Boolean,
   memory: Int,
   causedBy: Option[String])
 extends EventMessageBody {
-  val typeName = "Activation"
+  val typeName = Activation.typeName
   override def serialize = toJson.compactPrint
 
   def toJson = Activation.activationFormat.write(this)
+
+  def status: String = statusCode match {
+// Defined in ActivationResponse
+case 0 => Activation.statusSuccess
+case 1 => Activation.statusApplicationError
+case 2 => Activation.statusDeveloperError
+case 3 => Activation.statusInternalError
+case x => x.toString
+  }
+
+  def isColdStart: Boolean = initTime != Duration.Zero
 }
 
 object Activation extends DefaultJsonProtocol {
+
+  val typeName = "Activation"
   def parse(msg: String) = Try(activationFormat.read(msg.parseJson))
+
+  val statusSuccess = "success"
+  val statusApplicationError = "application_error"
+  val statusDeveloperError = "developer_error"
+  val statusInternalError = "internal_error"
+
+  private implicit val durationFormat = new RootJsonFormat[Duration] {
+override def write(obj: Duration): JsValue = obj match {
+  case o if o.isFinite() => JsNumber(o.toMillis)
+  case _ => JsNumber.zero
+}
+
+override def read(json: JsValue): Duration = json match {
+  case JsNumber(n) if n <= 0 => Duration.Zero
+  case JsNumber(n)   => toDuration(n.longValue())
 
 Review comment:
   nit; drop `()` in `longValue()` and in `isFinite()` above.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [openwhisk] rabbah commented on a change in pull request #4584: OpenWhisk User Events

2019-09-12 Thread GitBox
rabbah commented on a change in pull request #4584: OpenWhisk User Events
URL: https://github.com/apache/openwhisk/pull/4584#discussion_r323660833
 
 

 ##
 File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala
 ##
 @@ -194,22 +196,53 @@ object EventMessageBody extends DefaultJsonProtocol {
 
 case class Activation(name: String,
   statusCode: Int,
-  duration: Long,
-  waitTime: Long,
-  initTime: Long,
+  duration: Duration,
+  waitTime: Duration,
+  initTime: Duration,
   kind: String,
   conductor: Boolean,
   memory: Int,
   causedBy: Option[String])
 extends EventMessageBody {
-  val typeName = "Activation"
+  val typeName = Activation.typeName
   override def serialize = toJson.compactPrint
 
   def toJson = Activation.activationFormat.write(this)
+
+  def status: String = statusCode match {
+// Defined in ActivationResponse
+case 0 => Activation.statusSuccess
+case 1 => Activation.statusApplicationError
+case 2 => Activation.statusDeveloperError
+case 3 => Activation.statusInternalError
+case x => x.toString
+  }
+
+  def isColdStart: Boolean = initTime != Duration.Zero
 }
 
 object Activation extends DefaultJsonProtocol {
+
+  val typeName = "Activation"
   def parse(msg: String) = Try(activationFormat.read(msg.parseJson))
+
+  val statusSuccess = "success"
 
 Review comment:
   these would get removed as well if you reuse existing code to map status 
code to a string.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services