Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spark.app.name tag to InfluxDBSink metrics #58

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/scala/ch/cern/sparkmeasure/InfluxDBSink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {
}

var appId = "noAppId"
var appName = "noAppName"

appId = SparkSession.getActiveSession match {
case Some(sparkSession) => sparkSession.sparkContext.applicationId
Expand All @@ -87,6 +88,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {
val startTime = executorAdded.time
val point = Point.measurement("executors_started")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.addField("executorId", executorId)
.addField("executorHost", executorInfo.executorHost)
.addField("totalCores", executorInfo.totalCores)
Expand All @@ -101,6 +103,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {
val stageId = stageSubmitted.stageInfo.stageId
val point = Point.measurement("stages_started")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.addField("stageId", stageId)
.addField("attemptNUmber", attemptNumber)
.time(submissionTime, TimeUnit.MILLISECONDS)
Expand All @@ -116,6 +119,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {

val point1 = Point.measurement("stages_ended")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(completionTime, TimeUnit.MILLISECONDS)
.addField("stageId", stageId)
.addField("attemptNumber", attemptNumber)
Expand All @@ -127,6 +131,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {
val taskmetrics = stageCompleted.stageInfo.taskMetrics
val point2 = Point.measurement("stage_metrics")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(completionTime, TimeUnit.MILLISECONDS)
.addField("stageId", stageId)
.addField("attemptNumber", attemptNumber)
Expand Down Expand Up @@ -173,6 +178,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {

val point = Point.measurement("queries_started")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(startTime, TimeUnit.MILLISECONDS)
.addField("description", description)
.addField("queryId", queryId)
Expand All @@ -185,6 +191,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {

val point = Point.measurement("queries_ended")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(endTime, TimeUnit.MILLISECONDS)
.addField("queryId", queryId)
.build()
Expand All @@ -200,6 +207,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {

val point = Point.measurement("jobs_started")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(startTime, TimeUnit.MILLISECONDS)
.addField("jobID", jobId)
.build()
Expand All @@ -212,6 +220,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {

val point = Point.measurement("jobs_ended")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(completionTime, TimeUnit.MILLISECONDS)
.addField("jobID", jobId)
.build()
Expand All @@ -220,7 +229,7 @@ class InfluxDBSink(conf: SparkConf) extends SparkListener {

override def onApplicationStart(applicationStart: SparkListenerApplicationStart): Unit = {
appId = applicationStart.appId.getOrElse("noAppId")
// val appName = applicationStart.appName
appName = applicationStart.appName
}

override def onApplicationEnd(applicationEnd: SparkListenerApplicationEnd): Unit = {
Expand All @@ -242,6 +251,7 @@ class InfluxDBSinkExtended(conf: SparkConf) extends InfluxDBSink(conf: SparkConf
val taskInfo = taskStart.taskInfo
val point = Point.measurement("tasks_started")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(taskInfo.launchTime, TimeUnit.MICROSECONDS)
.addField("taskId", taskInfo.taskId)
.addField("attemptNumber", taskInfo.attemptNumber)
Expand All @@ -256,6 +266,7 @@ class InfluxDBSinkExtended(conf: SparkConf) extends InfluxDBSink(conf: SparkConf

val point1 = Point.measurement("tasks_ended")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(taskInfo.finishTime, TimeUnit.MILLISECONDS)
.addField("taskId", taskInfo.taskId)
.addField("attemptNumber", taskInfo.attemptNumber)
Expand All @@ -266,6 +277,7 @@ class InfluxDBSinkExtended(conf: SparkConf) extends InfluxDBSink(conf: SparkConf

val point2 = Point.measurement("task_metrics")
.tag("applicationId", appId)
.tag("spark.app.name", appName)
.time(taskInfo.finishTime, TimeUnit.MILLISECONDS)
// task info
.addField("taskId", taskInfo.taskId)
Expand Down