Skip to content
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

[IDE Service] Move warmup logic to JetBrains Launcher #15233

Merged
merged 1 commit into from
Dec 14, 2022
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
2 changes: 1 addition & 1 deletion components/ide-service/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ packages:
scripts:
- name: gen-golden-files
script: |
go test -timeout 30s -run ^TestResolveWorkspaceConfig$ github.com/gitpod-io/gitpod/ide-service/pkg/server --force --update
go test -timeout 30s -run ./... github.com/gitpod-io/gitpod/ide-service/pkg/server --force --update
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@
}
},
"Err": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@
}
},
"Err": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
},
"Err": "invalid ide config: DefaultDesktopIde should be desktop but browser"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
},
"Err": "invalid ide config"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
},
"Err": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
},
"Err": ""
}
}
64 changes: 64 additions & 0 deletions components/ide/jetbrains/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func main() {
}

if launchCtx.warmup {
waitForTasksToFinish()
launch(launchCtx)
return
}
Expand Down Expand Up @@ -853,3 +854,66 @@ func resolveProjectContextDir(launchCtx *LaunchContext) string {

return launchCtx.projectDir
}

func waitForTasksToFinish() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var conn *grpc.ClientConn
var err error

for {
conn, err = dial(ctx)
if err == nil {
err = checkTasks(ctx, conn)
}
andreafalzetti marked this conversation as resolved.
Show resolved Hide resolved

if err == nil {
return
}

log.WithError(err).Error("launcher: failed to check tasks status")

select {
case <-ctx.Done():
return
case <-time.After(1 * time.Second):
}
}
}

func checkTasks(ctx context.Context, conn *grpc.ClientConn) error {
client := supervisor.NewStatusServiceClient(conn)
tasksResponse, err := client.TasksStatus(ctx, &supervisor.TasksStatusRequest{Observe: true})
if err != nil {
return xerrors.Errorf("failed get tasks status client: %w", err)
}

for {
var runningTasksCounter int

resp, err := tasksResponse.Recv()
if err != nil {
return err
}

for _, task := range resp.Tasks {
if task.State != supervisor.TaskState_closed && task.Presentation.Name != "GITPOD_JB_WARMUP_TASK" {
runningTasksCounter++
}
}
if runningTasksCounter == 0 {
break
}
}

return nil
}

func dial(ctx context.Context) (*grpc.ClientConn, error) {
supervisorConn, err := grpc.DialContext(ctx, util.GetSupervisorAddress(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
err = xerrors.Errorf("failed connecting to supervisor: %w", err)
}
return supervisorConn, err
}