Skip to content

Commit 1d68d00

Browse files
authored
[ws-daemon] Fix workspace location for log backup (#18401)
* [ws-daemon] Fix workspace location for log backup * Update integration test to check for uploaded logs
1 parent 3d790a8 commit 1d68d00

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

components/ws-daemon/pkg/controller/workspace_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,9 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
293293
WorkspaceID: ws.Spec.Ownership.WorkspaceID,
294294
InstanceID: ws.Name,
295295
},
296-
WorkspaceLocation: ws.Spec.WorkspaceLocation,
297-
SnapshotName: snapshotName,
298-
BackupLogs: ws.Spec.Type == workspacev1.WorkspaceTypePrebuild,
299-
UpdateGitStatus: ws.Spec.Type == workspacev1.WorkspaceTypeRegular,
296+
SnapshotName: snapshotName,
297+
BackupLogs: ws.Spec.Type == workspacev1.WorkspaceTypePrebuild,
298+
UpdateGitStatus: ws.Spec.Type == workspacev1.WorkspaceTypeRegular,
300299
})
301300

302301
err = retry.RetryOnConflict(retryParams, func() error {

components/ws-daemon/pkg/controller/workspace_operations.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ type InitOptions struct {
9797
}
9898

9999
type BackupOptions struct {
100-
Meta WorkspaceMeta
101-
WorkspaceLocation string
102-
BackupLogs bool
103-
UpdateGitStatus bool
104-
SnapshotName string
100+
Meta WorkspaceMeta
101+
BackupLogs bool
102+
UpdateGitStatus bool
103+
SnapshotName string
105104
}
106105

107106
func NewWorkspaceOperations(config content.Config, provider *WorkspaceProvider, reg prometheus.Registerer) (WorkspaceOperations, error) {
@@ -231,7 +230,7 @@ func (wso *DefaultWorkspaceOperations) BackupWorkspace(ctx context.Context, opts
231230
}
232231

233232
if opts.BackupLogs {
234-
err := wso.uploadWorkspaceLogs(ctx, opts)
233+
err := wso.uploadWorkspaceLogs(ctx, opts, ws.Location)
235234
if err != nil {
236235
// we do not fail the workspace yet because we still might succeed with its content!
237236
glog.WithError(err).WithFields(ws.OWI()).Error("log backup failed")
@@ -345,9 +344,9 @@ func ensureCleanSlate(location string) error {
345344
return nil
346345
}
347346

348-
func (wso *DefaultWorkspaceOperations) uploadWorkspaceLogs(ctx context.Context, opts BackupOptions) (err error) {
347+
func (wso *DefaultWorkspaceOperations) uploadWorkspaceLogs(ctx context.Context, opts BackupOptions, location string) (err error) {
349348
// currently we're only uploading prebuild log files
350-
logFiles, err := logs.ListPrebuildLogFiles(ctx, opts.WorkspaceLocation)
349+
logFiles, err := logs.ListPrebuildLogFiles(ctx, location)
351350
if err != nil {
352351
return err
353352
}

test/pkg/integration/apis.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ func (c *ComponentAPI) ClearImageBuilderClientCache() {
11061106
type ContentService interface {
11071107
csapi.ContentServiceClient
11081108
csapi.WorkspaceServiceClient
1109+
csapi.HeadlessLogServiceClient
11091110
}
11101111

11111112
func (c *ComponentAPI) ContentService() (ContentService, error) {
@@ -1141,11 +1142,13 @@ func (c *ComponentAPI) ContentService() (ContentService, error) {
11411142
type cs struct {
11421143
csapi.ContentServiceClient
11431144
csapi.WorkspaceServiceClient
1145+
csapi.HeadlessLogServiceClient
11441146
}
11451147

11461148
c.contentServiceStatus.ContentService = cs{
1147-
ContentServiceClient: csapi.NewContentServiceClient(conn),
1148-
WorkspaceServiceClient: csapi.NewWorkspaceServiceClient(conn),
1149+
ContentServiceClient: csapi.NewContentServiceClient(conn),
1150+
WorkspaceServiceClient: csapi.NewWorkspaceServiceClient(conn),
1151+
HeadlessLogServiceClient: csapi.NewHeadlessLogServiceClient(conn),
11491152
}
11501153

11511154
return c.contentServiceStatus.ContentService, nil

test/tests/components/ws-manager/prebuild_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
264264
}
265265

266266
t.Logf("prebuild snapshot: %s", prebuildSnapshot)
267+
268+
// check the prebuild logs have been uploaded
269+
checkPrebuildLogUploaded(t, ctx, api, ws)
267270
}()
268271

269272
// launch the workspace from prebuild
@@ -692,6 +695,25 @@ func checkGitFolderPermission(t *testing.T, rsa *integration.RpcClient, workspac
692695
}
693696
}
694697

698+
func checkPrebuildLogUploaded(t *testing.T, ctx context.Context, api *integration.ComponentAPI, ws *integration.LaunchWorkspaceDirectlyResult) {
699+
cs, err := api.ContentService()
700+
if err != nil {
701+
t.Fatal(err)
702+
}
703+
resp, err := cs.ListLogs(ctx, &csapi.ListLogsRequest{
704+
WorkspaceId: ws.LastStatus.Metadata.MetaId,
705+
InstanceId: ws.Req.Id,
706+
OwnerId: ws.LastStatus.Metadata.Owner,
707+
})
708+
if err != nil {
709+
t.Fatal(err)
710+
}
711+
if len(resp.TaskId) == 0 {
712+
t.Fatal("no logs found")
713+
}
714+
t.Logf("found logs (task ids: %v)", resp.TaskId)
715+
}
716+
695717
func findSnapshotFromStoppedWs(t *testing.T, ctx context.Context, lastStatus *wsmanapi.WorkspaceStatus) (string, *wsmanapi.VolumeSnapshotInfo, error) {
696718
if lastStatus == nil {
697719
return "", nil, fmt.Errorf("did not get last workspace status")

0 commit comments

Comments
 (0)