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 failure context to recordExecutorEvent #1280

Merged
merged 1 commit into from
Jun 30, 2021
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
19 changes: 12 additions & 7 deletions pkg/controller/sparkapplication/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ func (c *Controller) getAndUpdateExecutorState(app *v1beta2.SparkApplication) er
oldState, exists := app.Status.ExecutorState[pod.Name]
// Only record an executor event if the executor state is new or it has changed.
if !exists || newState != oldState {
c.recordExecutorEvent(app, newState, pod.Name)
if newState == v1beta2.ExecutorFailedState {
execContainerState := getExecutorContainerTerminatedState(pod.Status)
c.recordExecutorEvent(app, newState, pod.Name, execContainerState.ExitCode, execContainerState.Reason)
} else {
c.recordExecutorEvent(app, newState, pod.Name)
}
}
executorStateMap[pod.Name] = newState

Expand Down Expand Up @@ -972,18 +977,18 @@ func (c *Controller) recordDriverEvent(app *v1beta2.SparkApplication, phase v1be
}
}

func (c *Controller) recordExecutorEvent(app *v1beta2.SparkApplication, state v1beta2.ExecutorState, name string) {
func (c *Controller) recordExecutorEvent(app *v1beta2.SparkApplication, state v1beta2.ExecutorState, args ...interface{}) {
switch state {
case v1beta2.ExecutorCompletedState:
c.recorder.Eventf(app, apiv1.EventTypeNormal, "SparkExecutorCompleted", "Executor %s completed", name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the output look like for args?

Copy link
Contributor Author

@ImpSy ImpSy Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before we use c.recorder.Eventf which already accept variadics parameters

per doc:

Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})

We already use something similar in recordSparkApplicationEvent for v1beta2.FailedState

c.recorder.Eventf(app, apiv1.EventTypeNormal, "SparkExecutorCompleted", "Executor %s completed", args)
case v1beta2.ExecutorPendingState:
c.recorder.Eventf(app, apiv1.EventTypeNormal, "SparkExecutorPending", "Executor %s is pending", name)
c.recorder.Eventf(app, apiv1.EventTypeNormal, "SparkExecutorPending", "Executor %s is pending", args)
case v1beta2.ExecutorRunningState:
c.recorder.Eventf(app, apiv1.EventTypeNormal, "SparkExecutorRunning", "Executor %s is running", name)
c.recorder.Eventf(app, apiv1.EventTypeNormal, "SparkExecutorRunning", "Executor %s is running", args)
case v1beta2.ExecutorFailedState:
c.recorder.Eventf(app, apiv1.EventTypeWarning, "SparkExecutorFailed", "Executor %s failed", name)
c.recorder.Eventf(app, apiv1.EventTypeWarning, "SparkExecutorFailed", "Executor %s failed with ExitCode: %d, Reason: %s", args)
case v1beta2.ExecutorUnknownState:
c.recorder.Eventf(app, apiv1.EventTypeWarning, "SparkExecutorUnknownState", "Executor %s in unknown state", name)
c.recorder.Eventf(app, apiv1.EventTypeWarning, "SparkExecutorUnknownState", "Executor %s in unknown state", args)
}
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/sparkapplication/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,17 @@ func TestSyncSparkApplication_ExecutingState(t *testing.T) {
},
Status: apiv1.PodStatus{
Phase: apiv1.PodFailed,
ContainerStatuses: []apiv1.ContainerStatus{
{
Name: config.SparkExecutorContainerName,
State: apiv1.ContainerState{
Terminated: &apiv1.ContainerStateTerminated{
ExitCode: 137,
Reason: "OOMKilled",
},
},
},
},
},
},
expectedAppState: v1beta2.FailingState,
Expand Down
10 changes: 9 additions & 1 deletion pkg/controller/sparkapplication/sparkapp_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ func isDriverRunning(app *v1beta2.SparkApplication) bool {
}

func getDriverContainerTerminatedState(podStatus apiv1.PodStatus) *apiv1.ContainerStateTerminated {
return getContainerTerminatedState(config.SparkDriverContainerName, podStatus)
}

func getExecutorContainerTerminatedState(podStatus apiv1.PodStatus) *apiv1.ContainerStateTerminated {
return getContainerTerminatedState(config.SparkExecutorContainerName, podStatus)
}

func getContainerTerminatedState(name string, podStatus apiv1.PodStatus) *apiv1.ContainerStateTerminated {
for _, c := range podStatus.ContainerStatuses {
if c.Name == config.SparkDriverContainerName {
if c.Name == name {
if c.State.Terminated != nil {
return c.State.Terminated
}
Expand Down