Skip to content

Commit

Permalink
scrooge-adaptive: Add logging to adaptive scrooge
Browse files Browse the repository at this point in the history
Problem

Basically, users want to understand which fields were actually deserialized by
adaptive scrooge.

Solution

Use debug log with information about fields which adaptive srooge will
deserialize.

RB_ID=922648
  • Loading branch information
dieu authored and jenkins committed Sep 5, 2017
1 parent ab83604 commit cd7df22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ lazy val scroogeAdaptive = Project(
"asm" % "asm" % "3.3.1",
"asm" % "asm-commons" % "3.3.1",
"asm" % "asm-util" % "3.3.1",
"com.twitter" % "libthrift" % libthriftVersion % "provided"
"com.twitter" % "libthrift" % libthriftVersion % "provided",
util("logging")
)
).dependsOn(scroogeCore, scroogeGenerator % "test", scroogeSerializer)

Expand Down
1 change: 1 addition & 0 deletions scrooge-adaptive/src/main/scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ scala_library(
'scrooge/scrooge-core',
'scrooge/scrooge-serializer',
'util/util-codec/src/main/scala:scala',
'util/util-logging/src/main/scala:scala',
],
exports=[
'3rdparty/jvm/asm',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.twitter.scrooge.adapt

import com.twitter.logging.Logger
import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec}
import java.lang.reflect.InvocationTargetException
import java.util.concurrent.atomic.AtomicInteger

private[adapt] object AdaptTrackingDecoder {
val logger = Logger(this.getClass)

val AdaptSuffix = "$Adapt"
val AdaptDecoderSuffix = "$AdaptDecoder"
val DecodeMethodName = "decode"
Expand Down Expand Up @@ -65,8 +68,22 @@ private[adapt] class AdaptTrackingDecoder[T <: ThriftStruct](
val useMapById = useMapByField.map { case (f, v) => (f.id, v) }

if (allFieldsUsed(useMapById)) {
logger.ifDebug(s"Adaptive scrooge is using all fields for ${codec.metaData.structName} struct.")
fallbackDecoder
} else {
val namesToUse = useMapByName.collect {
case (name, true) => name
}

if (namesToUse.isEmpty) {
logger.ifDebug(
s"Adaptive scrooge isn't using fields for ${codec.metaData.structName} struct with settings: $settings"
)
} else {
logger.ifDebug(
s"Adaptive scrooge is using fields: ${namesToUse.mkString(",")} for ${codec.metaData.structName} struct with settings: $settings"
)
}
buildAdaptiveDecoder(useMapByName, useMapById)
}
}
Expand Down

0 comments on commit cd7df22

Please sign in to comment.