@@ -464,7 +464,7 @@ func (wsm *WorkspaceManagerServer) DescribeWorkspace(ctx context.Context, req *w
464
464
Status : wsm .extractWorkspaceStatus (& ws ),
465
465
}
466
466
467
- lastActivity := ws . Status . LastActivity
467
+ lastActivity := getLastActivity ( & ws )
468
468
if lastActivity != nil {
469
469
result .LastActivity = lastActivity .UTC ().Format (time .RFC3339Nano )
470
470
}
@@ -1483,7 +1483,7 @@ func (wav *workspaceActivityVec) getWorkspaceActivityCounts() (active, notActive
1483
1483
continue
1484
1484
}
1485
1485
1486
- hasActivity := ws . Status . LastActivity != nil
1486
+ hasActivity := getLastActivity ( & ws ) != nil
1487
1487
if hasActivity {
1488
1488
active ++
1489
1489
} else {
@@ -1493,3 +1493,21 @@ func (wav *workspaceActivityVec) getWorkspaceActivityCounts() (active, notActive
1493
1493
1494
1494
return
1495
1495
}
1496
+
1497
+ func getLastActivity (ws * workspacev1.Workspace ) * time.Time {
1498
+ lastActivity := ws .Status .LastActivity
1499
+ if lastActivity != nil {
1500
+ return & lastActivity .Time
1501
+ }
1502
+
1503
+ // In case we don't have a record of the workspace's last activity, check for the FirstUserActivity condition
1504
+ // to see if the lastActivity got lost on a manager restart.
1505
+ if ws .IsConditionTrue (workspacev1 .WorkspaceConditionFirstUserActivity ) {
1506
+ now := time .Now ().UTC ()
1507
+ lastActivityStatus := metav1 .NewTime (now )
1508
+ return & lastActivityStatus .Time
1509
+ }
1510
+
1511
+ // If the FirstUserActivity condition isn't present we know that the workspace has never had user activity.
1512
+ return nil
1513
+ }
0 commit comments