Skip to content

Commit 94200d4

Browse files
markusthoemmescbickel
authored andcommitted
Add namespaceId to the activation record as well to enable correlation. (#3073)
1 parent caaf928 commit 94200d4

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ class DockerToActivationFileLogStore(system: ActorSystem, destinationDirectory:
9999

100100
val logs = container.logs(action.limits.logs.asMegaBytes, action.exec.sentinelledLogs)(transid)
101101

102+
// Adding the userId field to every written record, so any background process can properly correlate.
103+
val userIdField = Map("namespaceId" -> user.authkey.uuid.toJson)
104+
102105
val additionalMetadata = Map(
103106
"activationId" -> activation.activationId.asString.toJson,
104-
"action" -> action.fullyQualifiedName(false).asString.toJson,
105-
"userId" -> user.authkey.uuid.toJson)
107+
"action" -> action.fullyQualifiedName(false).asString.toJson) ++ userIdField
108+
109+
val augmentedActivation = JsObject(activation.toJson.fields ++ userIdField)
106110

107111
// Manually construct JSON fields to omit parsing the whole structure
108112
val metadata = ByteString("," + fieldsString(additionalMetadata))
@@ -113,7 +117,7 @@ class DockerToActivationFileLogStore(system: ActorSystem, destinationDirectory:
113117
// the closing "}", adding the fields and finally add "}\n" to the end again.
114118
.map(_.dropRight(1) ++ metadata ++ eventEnd)
115119
// As the last element of the stream, print the activation record.
116-
.concat(Source.single(ByteString(activation.toJson.compactPrint + "\n")))
120+
.concat(Source.single(ByteString(augmentedActivation.toJson.compactPrint + "\n")))
117121
.to(writeToFile)
118122

119123
val combined = OwSink.combine(toSeq, toFile)(Broadcast[ByteString](_))

tests/src/test/scala/whisk/core/containerpool/logging/test/DockerToActivationFileLogStoreTests.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import akka.util.ByteString
2525
import common.{StreamLogging, WskActorSystem}
2626
import org.scalatest.Matchers
2727
import spray.json._
28+
import spray.json.DefaultJsonProtocol._
2829
import whisk.common.TransactionId
2930
import whisk.core.containerpool.logging.{DockerToActivationFileLogStore, LogLine}
3031
import whisk.core.entity._
@@ -41,14 +42,21 @@ class DockerToActivationFileLogStoreTests
4142

4243
override def createStore() = new TestLogStoreTo(Sink.ignore)
4344

44-
def toLoggedEvent(line: LogLine, userId: UUID, activationId: ActivationId, actionName: FullyQualifiedEntityName) = {
45+
def toLoggedEvent(line: LogLine,
46+
userId: UUID,
47+
activationId: ActivationId,
48+
actionName: FullyQualifiedEntityName): String = {
4549
val event = line.toJson.compactPrint
4650
val concatenated =
47-
s""","activationId":"${activationId.asString}","action":"${actionName.asString}","userId":"${userId.asString}""""
51+
s""","activationId":"${activationId.asString}","action":"${actionName.asString}","namespaceId":"${userId.asString}""""
4852

4953
event.dropRight(1) ++ concatenated ++ "}\n"
5054
}
5155

56+
def toLoggedActivation(activation: WhiskActivation): String = {
57+
JsObject(activation.toJson.fields ++ Map("namespaceId" -> user.authkey.uuid.asString.toJson)).compactPrint + "\n"
58+
}
59+
5260
behavior of "DockerCouchDbFileLogStore"
5361

5462
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
7078
}
7179

7280
// Last message should be the full activation
73-
testActor.expectMsg(activation.toJson.compactPrint + "\n")
81+
testActor.expectMsg(toLoggedActivation(activation))
7482
}
7583

7684
class TestLogStoreTo(override val writeToFile: Sink[ByteString, _])

0 commit comments

Comments
 (0)