markusthoemmes commented on a change in pull request #2990: Change log level
dynamically
URL:
https://github.com/apache/incubator-openwhisk/pull/2990#discussion_r155740720
##########
File path: common/scala/src/main/scala/whisk/common/TransactionId.scala
##########
@@ -216,21 +212,22 @@ object TransactionId {
val invokerHealth = TransactionId(-121) // Invoker supervision
val controller = TransactionId(-130) // Controller startup
- def apply(tid: BigDecimal): TransactionId = {
+ def apply(tid: BigDecimal, extraLogging: Boolean = false): TransactionId = {
Try {
val now = Instant.now(Clock.systemUTC())
- TransactionId(TransactionMetadata(tid.toLong, now))
+ TransactionId(TransactionMetadata(tid.toLong, now, extraLogging))
} getOrElse unknown
}
implicit val serdes = new RootJsonFormat[TransactionId] {
- def write(t: TransactionId) = JsArray(JsNumber(t.meta.id),
JsNumber(t.meta.start.toEpochMilli))
+ def write(t: TransactionId) =
+ JsArray(JsNumber(t.meta.id), JsNumber(t.meta.start.toEpochMilli),
JsBoolean(t.meta.extraLogging))
Review comment:
Shall we make this a bit more efficient in that, if `extraLogging` is false,
we don't write anything at all. That'd spare us writing the extra bytes to
Kafka.
Code would look like this:
```scala
def write(t: TransactionId) = if(t.meta.extraLogging) {
val meta = Seq(t.meta.id.toJson, t.meta.start.toEpochMilli.toJson)
val extra = if(t.meta.extraLogging) Seq(t.meta.extraLogging.toJson) else
Seq.empty
(meta ++ extra).toJson
}
def read(value: JsValue) = Try {
value match {
case JsArray(Vector(JsNumber(id), JsNumber(start)) =>
TransactionId(TransactionMetadata(id.longValue,
Instant.ofEpochMilli(start.longValue), false))
case JsArray(Vector(JsNumber(id), JsNumber(start),
JsBoolean(extraLogging)) =>
TransactionId(TransactionMetadata(id.longValue,
Instant.ofEpochMilli(start.longValue), extraLogging))
}
}.getOrElse(unknown)
```
WDYT?
----------------------------------------------------------------
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