8000 more paranoia · coder/coder@1f1ceb1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f1ceb1

Browse files
committed
more paranoia
1 parent e2a6e5e commit 1f1ceb1

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,13 +1741,15 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
17411741
JobID: jobID,
17421742
}
17431743
for _, t := range jobType.WorkspaceBuild.Timings {
1744-
if t.Start == nil || t.End == nil {
1745-
s.Logger.Warn(ctx, "timings entry has nil start or end time", slog.F("entry", t.String()))
1744+
start := t.GetStart()
1745+
if !start.IsValid() || start.AsTime().IsZero() {
1746+
s.Logger.Warn(ctx, "timings entry has nil or zero start time", slog.F("job_id", job.ID.String()), slog.F("workspace_id", workspace.ID), slog.F("workspace_build_id", workspaceBuild.ID), slog.F("user_id", workspace.OwnerID))
17461747
continue
17471748
}
17481749

1749-
if t.Start.AsTime().IsZero() || t.End.AsTime().IsZero() {
1750-
s.Logger.Warn(ctx, "timings entry has zero start or end time, skipping", slog.F("entry", t.String()))
1750+
end := t.GetEnd()
1751+
if !end.IsValid() || end.AsTime().IsZero() {
1752+
s.Logger.Warn(ctx, "timings entry has nil or zero end time, skipping", slog.F("job_id", job.ID.String()), slog.F("workspace_id", workspace.ID), slog.F("workspace_build_id", workspaceBuild.ID), slog.F("user_id", workspace.OwnerID))
17511753
continue
17521754
}
17531755

@@ -1776,7 +1778,7 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
17761778
// after being started.
17771779
//
17781780
// Agent timeouts could be minutes apart, resulting in an unresponsive
1779-
// experience, so we'll notify after every unique timeout seconds.
1781+
// experience, so we'll notify after every unique timeout seconds
17801782
if !input.DryRun && workspaceBuild.Transition == database.WorkspaceTransitionStart && len(agentTimeouts) > 0 {
17811783
timeouts := maps.Keys(agentTimeouts)
17821784
slices.Sort(timeouts)

coderd/provisionerdserver/provisionerdserver_test.go

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,14 +1301,57 @@ func TestCompleteJob(t *testing.T) {
13011301
Name: "test-workspace-resource",
13021302
Type: "aws_instance",
13031303
}},
1304-
Timings: []*sdkproto.Timing{{
1305-
Stage: "test",
1306-
Source: "test-source",
1307-
Resource: "test-resource",
1308-
Action: "test-action",
1309-
Start: timestamppb.Now(),
1310-
End: timestamppb.Now(),
1311-
}},
1304+
Timings: []*sdkproto.Timing{
1305+
{
1306+
Stage: "test",
1307+
Source: "test-source",
1308+
Resource: "test-resource",
1309+
Action: "test-action",
1310+
Start: timestamppb.Now(),
1311+
End: timestamppb.Now(),
1312+
},
1313+
{
1314+
Stage: "test2",
1315+
Source: "test-source2",
1316+
Resource: "test-resource2",
1317+
Action: "test-action2",
1318+
// Start: omitted
1319+
// End: omitted
1320+
},
1321+
{
1322+
Stage: "test3",
1323+
Source: "test-source3",
1324+
Resource: "test-resource3",
1325+
Action: "test-action3",
1326+
Start: timestamppb.Now(),
1327+
End: nil,
1328+
},
1329+
{
1330+
Stage: "test3",
1331+
Source: "test-source3",
1332+
Resource: "test-resource3",
1333+
Action: "test-action3",
1334+
Start: nil,
1335+
End: timestamppb.Now(),
1336+
},
1337+
{
1338+
Stage: "test4",
1339+
Source: "test-source4",
1340+
Resource: "test-resource4",
1341+
Action: "test-action4",
1342+
Start: timestamppb.New(time.Time{}),
1343+
End: timestamppb.Now(),
1344+
},
1345+
{
1346+
Stage: "test5",
1347+
Source: "test-source5",
1348+
Resource: "test-resource5",
1349+
Action: "test-action5",
1350+
Start: timestamppb.Now(),
1351+
End: timestamppb.New(time.Time{}),
1352+
},
1353+
nil, // nil timing should be ignored
1354+
},
13121355
},
13131356
},
13141357
})

0 commit comments

Comments
 (0)
0