Skip to content

Spark job cancellation no longer marks application as failed #8701

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

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ public synchronized void onJobEnd(SparkListenerJobEnd jobEnd) {
return;
}

lastJobFailed = false;
if (jobEnd.jobResult() instanceof JobFailed) {
JobFailed jobFailed = (JobFailed) jobEnd.jobResult();
Exception exception = jobFailed.exception();
Expand All @@ -510,9 +509,15 @@ public synchronized void onJobEnd(SparkListenerJobEnd jobEnd) {
jobSpan.setErrorMessage(errorMessage);
jobSpan.setTag(DDTags.ERROR_STACK, errorStackTrace);
jobSpan.setTag(DDTags.ERROR_TYPE, "Spark Job Failed");
lastJobFailed = true;
lastJobFailedMessage = errorMessage;
lastJobFailedStackTrace = errorStackTrace;

// Only propagate the error to the application if it is not a cancellation
if (errorMessage != null && !errorMessage.toLowerCase().contains("cancelled")) {
lastJobFailed = true;
lastJobFailedMessage = errorMessage;
lastJobFailedStackTrace = errorStackTrace;
}
} else {
lastJobFailed = false;
}

SparkAggregatedTaskMetrics metrics = jobMetrics.remove(jobEnd.jobId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ abstract class AbstractSparkListenerTest extends AgentTestRunner {
return new SparkListenerJobEnd(jobId, time, JobSucceeded$.MODULE$)
}

protected jobFailedEvent(Integer jobId, Long time, String errorMessage) {
def exception = new RuntimeException(errorMessage)
def jobFailed = new org.apache.spark.scheduler.JobFailed(exception)
return new SparkListenerJobEnd(jobId, time, jobFailed)
}

protected stageSubmittedEvent(Integer stageId, Long time) {
def stageInfo = createStageInfo(stageId)
stageInfo.submissionTime = Option.apply(time)
Expand Down Expand Up @@ -457,6 +463,34 @@ abstract class AbstractSparkListenerTest extends AgentTestRunner {
}
}

def "test lastJobFailed is not set when job is cancelled"() {
setup:
def listener = getTestDatadogSparkListener()
listener.onApplicationStart(applicationStartEvent(1000L))
listener.onJobStart(jobStartEvent(1, 1900L, [1]))
listener.onJobEnd(jobFailedEvent(1, 2200L, "Job was cancelled by user"))
listener.onApplicationEnd(new SparkListenerApplicationEnd(2300L))

expect:
assertTraces(1) {
trace(2) {
span {
operationName "spark.application"
resourceName "spark.application"
spanType "spark"
errored false
parent()
}
span {
operationName "spark.job"
spanType "spark"
errored true
childOf(span(0))
}
}
}
}

protected validateRelativeError(double value, double expected, double relativeAccuracy) {
double relativeError = Math.abs(value - expected) / expected
assert relativeError < relativeAccuracy
Expand Down
Loading