openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbic...@apache.org
Subject [incubator-openwhisk] branch master updated: Add namespaceId to the activation record as well to enable correlation. (#3073)
Date Thu, 07 Dec 2017 12:59:06 GMT
This is an automated email from the ASF dual-hosted git repository.

cbickel 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 94200d4  Add namespaceId to the activation record as well to enable correlation.
(#3073)
94200d4 is described below

commit 94200d4dc7a6aaae6b694fc7333690df13c2975c
Author: Markus Thömmes <markusthoemmes@me.com>
AuthorDate: Thu Dec 7 13:59:03 2017 +0100

    Add namespaceId to the activation record as well to enable correlation. (#3073)
---
 .../logging/DockerToActivationFileLogStore.scala           | 10 +++++++---
 .../logging/test/DockerToActivationFileLogStoreTests.scala | 14 +++++++++++---
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
b/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
index f31c320..f9ec413 100644
--- a/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
+++ b/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
@@ -99,10 +99,14 @@ class DockerToActivationFileLogStore(system: ActorSystem, destinationDirectory:
 
     val logs = container.logs(action.limits.logs.asMegaBytes, action.exec.sentinelledLogs)(transid)
 
+    // Adding the userId field to every written record, so any background process can properly
correlate.
+    val userIdField = Map("namespaceId" -> user.authkey.uuid.toJson)
+
     val additionalMetadata = Map(
       "activationId" -> activation.activationId.asString.toJson,
-      "action" -> action.fullyQualifiedName(false).asString.toJson,
-      "userId" -> user.authkey.uuid.toJson)
+      "action" -> action.fullyQualifiedName(false).asString.toJson) ++ userIdField
+
+    val augmentedActivation = JsObject(activation.toJson.fields ++ userIdField)
 
     // Manually construct JSON fields to omit parsing the whole structure
     val metadata = ByteString("," + fieldsString(additionalMetadata))
@@ -113,7 +117,7 @@ class DockerToActivationFileLogStore(system: ActorSystem, destinationDirectory:
     // the closing "}", adding the fields and finally add "}\n" to the end again.
       .map(_.dropRight(1) ++ metadata ++ eventEnd)
       // As the last element of the stream, print the activation record.
-      .concat(Source.single(ByteString(activation.toJson.compactPrint + "\n")))
+      .concat(Source.single(ByteString(augmentedActivation.toJson.compactPrint + "\n")))
       .to(writeToFile)
 
     val combined = OwSink.combine(toSeq, toFile)(Broadcast[ByteString](_))
diff --git a/tests/src/test/scala/whisk/core/containerpool/logging/test/DockerToActivationFileLogStoreTests.scala
b/tests/src/test/scala/whisk/core/containerpool/logging/test/DockerToActivationFileLogStoreTests.scala
index 1f5f22c..f142c1b 100644
--- a/tests/src/test/scala/whisk/core/containerpool/logging/test/DockerToActivationFileLogStoreTests.scala
+++ b/tests/src/test/scala/whisk/core/containerpool/logging/test/DockerToActivationFileLogStoreTests.scala
@@ -25,6 +25,7 @@ import akka.util.ByteString
 import common.{StreamLogging, WskActorSystem}
 import org.scalatest.Matchers
 import spray.json._
+import spray.json.DefaultJsonProtocol._
 import whisk.common.TransactionId
 import whisk.core.containerpool.logging.{DockerToActivationFileLogStore, LogLine}
 import whisk.core.entity._
@@ -41,14 +42,21 @@ class DockerToActivationFileLogStoreTests
 
   override def createStore() = new TestLogStoreTo(Sink.ignore)
 
-  def toLoggedEvent(line: LogLine, userId: UUID, activationId: ActivationId, actionName:
FullyQualifiedEntityName) = {
+  def toLoggedEvent(line: LogLine,
+                    userId: UUID,
+                    activationId: ActivationId,
+                    actionName: FullyQualifiedEntityName): String = {
     val event = line.toJson.compactPrint
     val concatenated =
-      s""","activationId":"${activationId.asString}","action":"${actionName.asString}","userId":"${userId.asString}""""
+      s""","activationId":"${activationId.asString}","action":"${actionName.asString}","namespaceId":"${userId.asString}""""
 
     event.dropRight(1) ++ concatenated ++ "}\n"
   }
 
+  def toLoggedActivation(activation: WhiskActivation): String = {
+    JsObject(activation.toJson.fields ++ Map("namespaceId" -> user.authkey.uuid.asString.toJson)).compactPrint
+ "\n"
+  }
+
   behavior of "DockerCouchDbFileLogStore"
 
   it should "read logs returned by the container,in mem and enrich + write them to the provided
sink" in {
@@ -70,7 +78,7 @@ class DockerToActivationFileLogStoreTests
     }
 
     // Last message should be the full activation
-    testActor.expectMsg(activation.toJson.compactPrint + "\n")
+    testActor.expectMsg(toLoggedActivation(activation))
   }
 
   class TestLogStoreTo(override val writeToFile: Sink[ByteString, _])

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Mime
View raw message