Skip to content

Commit

Permalink
Scala Common Enrich: ensured that all timestamp fields are nonnegative (
Browse files Browse the repository at this point in the history
closes #1938)
  • Loading branch information
fblundun committed Aug 19, 2015
1 parent 3fea143 commit 6638b44
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ object EventEnrichments {
}
}

/**
* Validate that the collector timestamp is set and valid
*
* @param collectorTstamp
* @return Validated collector timestamp
*/
def validateCollectorTstamp(collectorTstamp: Option[DateTime]): Validation[String, String] = {
collectorTstamp match {
case None => "No collector_tstamp set".fail
case Some(t) => extractTimestamp("collector_tstamp", t.getMillis.toString)
}
}

/**
* Extracts the timestamp from the
* format as laid out in the Tracker
Expand All @@ -95,7 +108,12 @@ object EventEnrichments {
val extractTimestamp: (String, String) => ValidatedString = (field, tstamp) =>
try {
val dt = new DateTime(tstamp.toLong)
toTimestamp(dt).success
val timestampString = toTimestamp(dt)
if (timestampString.startsWith("-")) {
s"Field [$field]: [$tstamp] is formatted as [$timestampString] which isn't Redshift-compatible".fail
} else {
timestampString.success
}
} catch {
case nfe: NumberFormatException =>
"Field [%s]: [%s] is not in the expected format (ms since epoch)".format(field, tstamp).fail
Expand Down

0 comments on commit 6638b44

Please sign in to comment.