Skip to content

[ws-manager] allow user custom closed timeout #16278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
WORKSPACE_TIMEOUT = 0;
CLOSED_TIMEOUT = 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
985 changes: 535 additions & 450 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_WORKSPACE_TIMEOUT {
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 if req.Type == api.TimeoutType_CLOSED_TIMEOUT {
err = m.markWorkspace(ctx, req.Id, addMark(customClosedTimeoutAnnotation, req.Duration))
if err != nil {
return nil, xerrors.Errorf("cannot set closed timeout: %w", err)
}
}

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