mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd/database): improve task status in tasks_with_status view (#20683)
This change restructures the `tasks_with_status` view query to: - Improve debuggability by adding a `status_debug` column to better understand the outcome - Reduce clutter from `bool_or`, `bool_and` which are aggregate functions that did not actually have serve a purpose (each join is 0-1 rows) - Improve agent lifecycle state coverage, `start_timeout` and `start_error` were omitted - These states are easy to trigger even in a perfectly functioning workspace/task so we now rely on app health to report whether or not there was an issue - Mark canceling and canceled workspace build jobs as error state - Agent stop states were implicitly `unknown`, now there are explicit (I initially considered `error`, could go either way)
This commit is contained in:
@@ -6664,6 +6664,23 @@ func TestTasksWithStatusView(t *testing.T) {
|
||||
StartedAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
CompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
}
|
||||
case database.ProvisionerJobStatusCanceling:
|
||||
jobParams = database.ProvisionerJob{
|
||||
OrganizationID: org.ID,
|
||||
Type: database.ProvisionerJobTypeWorkspaceBuild,
|
||||
InitiatorID: user.ID,
|
||||
StartedAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
CanceledAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
}
|
||||
case database.ProvisionerJobStatusCanceled:
|
||||
jobParams = database.ProvisionerJob{
|
||||
OrganizationID: org.ID,
|
||||
Type: database.ProvisionerJobTypeWorkspaceBuild,
|
||||
InitiatorID: user.ID,
|
||||
StartedAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
CompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
CanceledAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
|
||||
}
|
||||
default:
|
||||
t.Errorf("invalid build status: %v", buildStatus)
|
||||
}
|
||||
@@ -6816,6 +6833,28 @@ func TestTasksWithStatusView(t *testing.T) {
|
||||
expectWorkspaceAgentValid: false,
|
||||
expectWorkspaceAppValid: false,
|
||||
},
|
||||
{
|
||||
name: "CancelingBuild",
|
||||
buildStatus: database.ProvisionerJobStatusCanceling,
|
||||
buildTransition: database.WorkspaceTransitionStart,
|
||||
expectedStatus: database.TaskStatusError,
|
||||
description: "Latest workspace build is canceling",
|
||||
expectBuildNumberValid: true,
|
||||
expectBuildNumber: 1,
|
||||
expectWorkspaceAgentValid: false,
|
||||
expectWorkspaceAppValid: false,
|
||||
},
|
||||
{
|
||||
name: "CanceledBuild",
|
||||
buildStatus: database.ProvisionerJobStatusCanceled,
|
||||
buildTransition: database.WorkspaceTransitionStart,
|
||||
expectedStatus: database.TaskStatusError,
|
||||
description: "Latest workspace build was canceled",
|
||||
expectBuildNumberValid: true,
|
||||
expectBuildNumber: 1,
|
||||
expectWorkspaceAgentValid: false,
|
||||
expectWorkspaceAppValid: false,
|
||||
},
|
||||
{
|
||||
name: "StoppedWorkspace",
|
||||
buildStatus: database.ProvisionerJobStatusSucceeded,
|
||||
@@ -6943,24 +6982,26 @@ func TestTasksWithStatusView(t *testing.T) {
|
||||
buildStatus: database.ProvisionerJobStatusSucceeded,
|
||||
buildTransition: database.WorkspaceTransitionStart,
|
||||
agentState: database.WorkspaceAgentLifecycleStateStartTimeout,
|
||||
expectedStatus: database.TaskStatusUnknown,
|
||||
description: "Agent start timed out",
|
||||
appHealths: []database.WorkspaceAppHealth{database.WorkspaceAppHealthHealthy},
|
||||
expectedStatus: database.TaskStatusActive,
|
||||
description: "Agent start timed out but app is healthy, defer to app",
|
||||
expectBuildNumberValid: true,
|
||||
expectBuildNumber: 1,
|
||||
expectWorkspaceAgentValid: true,
|
||||
expectWorkspaceAppValid: false,
|
||||
expectWorkspaceAppValid: true,
|
||||
},
|
||||
{
|
||||
name: "AgentStartError",
|
||||
buildStatus: database.ProvisionerJobStatusSucceeded,
|
||||
buildTransition: database.WorkspaceTransitionStart,
|
||||
agentState: database.WorkspaceAgentLifecycleStateStartError,
|
||||
expectedStatus: database.TaskStatusUnknown,
|
||||
description: "Agent failed to start",
|
||||
appHealths: []database.WorkspaceAppHealth{database.WorkspaceAppHealthHealthy},
|
||||
expectedStatus: database.TaskStatusActive,
|
||||
description: "Agent start failed but app is healthy, defer to app",
|
||||
expectBuildNumberValid: true,
|
||||
expectBuildNumber: 1,
|
||||
expectWorkspaceAgentValid: true,
|
||||
expectWorkspaceAppValid: false,
|
||||
expectWorkspaceAppValid: true,
|
||||
},
|
||||
{
|
||||
name: "AgentShuttingDown",
|
||||
@@ -7081,6 +7122,8 @@ func TestTasksWithStatusView(t *testing.T) {
|
||||
got, err := db.GetTaskByID(ctx, task.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("Task status debug: %s", got.StatusDebug)
|
||||
|
||||
require.Equal(t, tt.expectedStatus, got.Status)
|
||||
|
||||
require.Equal(t, tt.expectBuildNumberValid, got.WorkspaceBuildNumber.Valid)
|
||||
|
||||
Reference in New Issue
Block a user