I want to get the jobId of the Spark job which is running from within the Spark Context. Does Dataproc stores this info in Spark Context?
I want to get the jobId of the Spark job which is running from within the Spark Context. Does Dataproc stores this info in Spark Context?
Dataproc job ID is not available directly within SparkContext. You might need to call Dataproc Jobs API to list all jobs associated with the cluster and find it out.
With a bit of patience, I found this solution (I'm using Dataproc image 2.0-debian10, Spark 3.1.2, Scala 2.12.14).
In short, I noticed that you can get the Dataproc job ID by following these steps
I wrote this implicit class that extracts the ID as an optional value
implicit class RichSparkConf(protected val conf: SparkConf) {
def dataprocJobId: Option[String] = {
for {
yarnTags <- conf.getOption(RichSparkConf.SparkYarnTags)
dataProcJobIdTag <- yarnTags.split(",").find(_.startsWith(RichSparkConf.DataprocJobIdPrefix))
} yield dataProcJobIdTag.substring(RichSparkConf.DataprocJobIdPrefix.length)
}
}
object RichSparkConf {
val DataprocJobIdPrefix = "dataproc_job_"
val SparkYarnTags = "spark.yarn.tags"
}
As a rule of thumb, I usually try to take a look at all SparkConf key-value pairs and see if I can get something out of it that fits my requirement. Hope it helps ;)