Skip to content

Commit

Permalink
[ws-manager] Add custom closed timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
iQQBot committed Feb 9, 2023
1 parent a0ec207 commit f40a338
Show file tree
Hide file tree
Showing 8 changed files with 825 additions and 568 deletions.
13 changes: 13 additions & 0 deletions components/ws-manager-api/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ message MarkActiveRequest {
// MarkActiveResponse is the answer to a mark workspace active request
message MarkActiveResponse {}

enum TimeoutType {
WorkspaceTimeout = 0;
ClosedTimeout = 1;
}

// SetTimeoutRequest configures the timeout of a workspace
message SetTimeoutRequest {
// id is the ID of the workspace
string id = 1;

// duration is the new timeout duration. Must be a valid Go duration (see https://golang.org/pkg/time/#ParseDuration)
string duration = 2;

TimeoutType type = 3;
}

// SetTimeoutResponse is the answer to a set timeout request
Expand Down Expand Up @@ -361,6 +368,9 @@ message WorkspaceSpec {
// ide_image_layers are contains the images needed for the ide to run,
// including ide-desktop, desktop-plugin and so on
repeated string ide_image_layers = 10;

// The timeout for closed ide.
string closed_timeout = 11;
}

// PortSpec describes a networking port exposed on a workspace
Expand Down Expand Up @@ -584,6 +594,9 @@ message StartWorkspaceSpec {
// ide_image_layers are contains the images needed for the ide to run,
// including ide-desktop, desktop-plugin and so on
repeated string ide_image_layers = 17;

// timeout optionally sets a custom closed timeout
string closed_timeout = 18;
}

// WorkspaceFeatureFlag enable non-standard behaviour in workspaces
Expand Down
1,207 changes: 646 additions & 561 deletions components/ws-manager-api/go/core.pb.go

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions components/ws-manager-api/typescript/src/core_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 102 additions & 3 deletions components/ws-manager-api/typescript/src/core_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions components/ws-manager/pkg/manager/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const (
// This is handy if you want to prevent a workspace from timing out during lunch break.
customTimeoutAnnotation = "gitpod/customTimeout"

// customClosedTimeoutAnnotation configures the closed timeout of a workspace, i.e. close web ide, disconnect ssh connection
customClosedTimeoutAnnotation = "gitpod/customClosedTimeout"

// firstUserActivityAnnotation marks a workspace woth the timestamp of first user activity in it
firstUserActivityAnnotation = "gitpod/firstUserActivity"

Expand Down
7 changes: 7 additions & 0 deletions components/ws-manager/pkg/manager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ func (m *Manager) createDefiniteWorkspacePod(startContext *startWorkspaceContext
}
annotations[customTimeoutAnnotation] = req.Spec.Timeout
}
if req.Spec.ClosedTimeout != "" {
_, err := time.ParseDuration(req.Spec.ClosedTimeout)
if err != nil {
return nil, xerrors.Errorf("invalid closed timeout \"%s\": %w", req.Spec.ClosedTimeout, err)
}
annotations[customClosedTimeoutAnnotation] = req.Spec.ClosedTimeout
}

for k, v := range req.Metadata.Annotations {
annotations[workspaceAnnotationPrefix+k] = v
Expand Down
17 changes: 14 additions & 3 deletions components/ws-manager/pkg/manager/manager_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,20 @@ func (m *Manager) SetTimeout(ctx context.Context, req *api.SetTimeoutRequest) (r
return nil, xerrors.Errorf("invalid duration \"%s\": %w", req.Duration, err)
}

err = m.markWorkspace(ctx, req.Id, addMark(customTimeoutAnnotation, req.Duration))
if err != nil {
return nil, xerrors.Errorf("cannot set workspace timeout: %w", err)
if req.Type == api.TimeoutType_WorkspaceTimeout {
err = m.markWorkspace(ctx, req.Id, addMark(customTimeoutAnnotation, req.Duration))
if err != nil {
return nil, xerrors.Errorf("cannot set workspace timeout: %w", err)
}
err = m.markWorkspace(ctx, req.Id, addMark(customClosedTimeoutAnnotation, "0"))
if err != nil {
return nil, xerrors.Errorf("cannot set closed timeout: %w", err)
}
} else {
err = m.markWorkspace(ctx, req.Id, addMark(customTimeoutAnnotation, req.Duration))
if err != nil {
return nil, xerrors.Errorf("cannot set closed timeout: %w", err)
}
}

return &api.SetTimeoutResponse{}, nil
Expand Down
Loading

0 comments on commit f40a338

Please sign in to comment.