This repository was archived by the owner on Feb 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Spark schema main summary to view #67
Merged
vitillo
merged 4 commits into
mozilla:master
from
mreid-moz:spark_schema_main_summary_to_view
May 23, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ metastore_db/ | |
.idea/ | ||
derby.log | ||
*.iml | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-J-Xss4m | ||
-J-Xss16M | ||
-J-Xmx2048M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package telemetry.utils | ||
|
||
import scala.io.Source | ||
import scala.collection.JavaConversions._ | ||
import scala.collection.JavaConverters._ | ||
import telemetry.heka.{HekaFrame, Message} | ||
import org.json4s._ | ||
import org.json4s.jackson.JsonMethods.parse | ||
import org.joda.time.DateTime | ||
import org.apache.spark.rdd.RDD | ||
import awscala.s3.{Bucket, S3} | ||
import org.apache.spark.SparkContext | ||
import telemetry.{DerivedStream, ObjectSummary} | ||
|
||
object Telemetry { | ||
implicit lazy val s3: S3 = S3() | ||
|
||
private def listS3Keys(bucket: Bucket, prefix: String, delimiter: String = "/"): Stream[String] = { | ||
import com.amazonaws.services.s3.model.{ ListObjectsRequest, ObjectListing } | ||
|
||
val request = new ListObjectsRequest().withBucketName(bucket.getName).withPrefix(prefix).withDelimiter(delimiter) | ||
val firstListing = s3.listObjects(request) | ||
|
||
def completeStream(listing: ObjectListing): Stream[String] = { | ||
val prefixes = listing.getCommonPrefixes.asScala.toStream | ||
prefixes #::: (if (listing.isTruncated) completeStream(s3.listNextBatchOfObjects(listing)) else Stream.empty) | ||
} | ||
|
||
completeStream(firstListing) | ||
} | ||
|
||
private def matchingPrefixes(bucket: Bucket, seenPrefixes: Stream[String], pattern: List[String]): Stream[String] = { | ||
if (pattern.isEmpty) { | ||
seenPrefixes | ||
} else { | ||
val matching = seenPrefixes | ||
.flatMap(prefix => listS3Keys(bucket, prefix)) | ||
.filter(prefix => (pattern.head == "*" || prefix.endsWith(pattern.head + "/"))) | ||
matchingPrefixes(bucket, matching, pattern.tail) | ||
} | ||
} | ||
|
||
def appendToFile(p: String, s: String): Unit = { | ||
val pw = new java.io.PrintWriter(new java.io.FileOutputStream(new java.io.File(p),true)) | ||
try pw.write(s) finally pw.close() | ||
} | ||
|
||
def getRecords(sc: SparkContext, submissionDate: DateTime, pingPath: List[String]): RDD[Map[String, Any]] = { | ||
getMessages(sc, submissionDate, pingPath).map(HekaFrame.fields) | ||
} | ||
|
||
def getMessages(sc: SparkContext, submissionDate: DateTime, pingPath: List[String]): RDD[Message] = { | ||
// obtain the prefix of the telemetry data source | ||
val metadataBucket = Bucket("net-mozaws-prod-us-west-2-pipeline-metadata") | ||
val Some(sourcesObj) = metadataBucket.get("sources.json") | ||
val metaSources = parse(Source.fromInputStream(sourcesObj.getObjectContent()).getLines().mkString("\n")) | ||
val JString(telemetryPrefix) = metaSources \\ "telemetry" \\ "prefix" | ||
val JString(dataBucket) = metaSources \\ "telemetry" \\ "bucket" | ||
|
||
// get a stream of object summaries that match the desired criteria | ||
val bucket = Bucket(dataBucket) | ||
|
||
val summaries = matchingPrefixes( | ||
bucket, | ||
List("").toStream, | ||
List(telemetryPrefix, submissionDate.toString("yyyyMMdd")) ++ pingPath | ||
).flatMap(prefix => s3.objectSummaries(bucket, prefix)).map(summary => ObjectSummary(summary.getKey, summary.getSize)) | ||
|
||
// Partition the files into groups of approximately-equal size | ||
val groups = DerivedStream.groupBySize(summaries.toIterator) | ||
sc.parallelize(groups, groups.size).flatMap(x => x).flatMap(o => { | ||
val hekaFile = bucket.getObject(o.key).getOrElse(throw new Exception(s"File missing on S3: ${o.key}")) | ||
for (message <- HekaFrame.parse(hekaFile.getObjectContent, o.key)) yield message | ||
}) | ||
} | ||
|
||
def listOptions(submissionDate: DateTime, pingPath: List[String]): Stream[String] = { | ||
// obtain the prefix of the telemetry data source | ||
val metadataBucket = Bucket("net-mozaws-prod-us-west-2-pipeline-metadata") | ||
val Some(sourcesObj) = metadataBucket.get("sources.json") | ||
val metaSources = parse(Source.fromInputStream(sourcesObj.getObjectContent).getLines().mkString("\n")) | ||
val JString(telemetryPrefix) = metaSources \\ "telemetry" \\ "prefix" | ||
val JString(dataBucket) = metaSources \\ "telemetry" \\ "bucket" | ||
|
||
// get a stream of object summaries that match the desired criteria | ||
val bucket = Bucket(dataBucket) | ||
matchingPrefixes( | ||
bucket, | ||
List("").toStream, | ||
List(telemetryPrefix, submissionDate.toString("yyyyMMdd")) ++ pingPath ++ List("*") | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this function defined here but never used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this whole file from Anthony's PR, which only had the
getRecords
function - I addedgetMessages
because I needed to access the main Heka fields (Timestamp specifically).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a debugging function that I left in accidentally. It's pretty useful when debugging locally, but we probably don't need to keep it around.