From 2987dcb0da54c5e8984e2bc36def490ae5c16f50 Mon Sep 17 00:00:00 2001 From: Andrea Falzetti Date: Thu, 8 Dec 2022 09:35:42 +0000 Subject: [PATCH] jetbrains: run warmup as last task Co-authored-by: Anton Kosyakov Co-authored-by: Victor Nogueira --- components/ide-service/BUILD.yaml | 2 +- .../testdata/ideconfig_happypath.golden | 2 +- .../ideconfig_happypath_resolve.golden | 2 +- .../ideconfig_idetype_not_correct.golden | 2 +- .../testdata/ideconfig_idetype_unknown.golden | 2 +- .../resolve_ws_config_referrer_invalid.golden | 2 +- .../resolve_ws_config_regular_code.golden | 2 +- components/ide/jetbrains/launcher/main.go | 64 +++++++++++++++++++ 8 files changed, 71 insertions(+), 7 deletions(-) diff --git a/components/ide-service/BUILD.yaml b/components/ide-service/BUILD.yaml index c76345c0556980..531c77ec51af24 100644 --- a/components/ide-service/BUILD.yaml +++ b/components/ide-service/BUILD.yaml @@ -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 diff --git a/components/ide-service/pkg/server/testdata/ideconfig_happypath.golden b/components/ide-service/pkg/server/testdata/ideconfig_happypath.golden index 3bc141b7eae493..fc635e05ea24bd 100644 --- a/components/ide-service/pkg/server/testdata/ideconfig_happypath.golden +++ b/components/ide-service/pkg/server/testdata/ideconfig_happypath.golden @@ -90,4 +90,4 @@ } }, "Err": "" -} \ No newline at end of file +} diff --git a/components/ide-service/pkg/server/testdata/ideconfig_happypath_resolve.golden b/components/ide-service/pkg/server/testdata/ideconfig_happypath_resolve.golden index 9b2cf2a9e12702..b5faffa17860ce 100644 --- a/components/ide-service/pkg/server/testdata/ideconfig_happypath_resolve.golden +++ b/components/ide-service/pkg/server/testdata/ideconfig_happypath_resolve.golden @@ -92,4 +92,4 @@ } }, "Err": "" -} \ No newline at end of file +} diff --git a/components/ide-service/pkg/server/testdata/ideconfig_idetype_not_correct.golden b/components/ide-service/pkg/server/testdata/ideconfig_idetype_not_correct.golden index c5cb0883db93a5..e1ffc73b66de87 100644 --- a/components/ide-service/pkg/server/testdata/ideconfig_idetype_not_correct.golden +++ b/components/ide-service/pkg/server/testdata/ideconfig_idetype_not_correct.golden @@ -9,4 +9,4 @@ } }, "Err": "invalid ide config: DefaultDesktopIde should be desktop but browser" -} \ No newline at end of file +} diff --git a/components/ide-service/pkg/server/testdata/ideconfig_idetype_unknown.golden b/components/ide-service/pkg/server/testdata/ideconfig_idetype_unknown.golden index 7893c5b89ecb39..24af6837e87e91 100644 --- a/components/ide-service/pkg/server/testdata/ideconfig_idetype_unknown.golden +++ b/components/ide-service/pkg/server/testdata/ideconfig_idetype_unknown.golden @@ -9,4 +9,4 @@ } }, "Err": "invalid ide config" -} \ No newline at end of file +} diff --git a/components/ide-service/pkg/server/testdata/resolve_ws_config_referrer_invalid.golden b/components/ide-service/pkg/server/testdata/resolve_ws_config_referrer_invalid.golden index ec088fcbca185b..d4ab298f485431 100644 --- a/components/ide-service/pkg/server/testdata/resolve_ws_config_referrer_invalid.golden +++ b/components/ide-service/pkg/server/testdata/resolve_ws_config_referrer_invalid.golden @@ -4,4 +4,4 @@ "web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9" }, "Err": "" -} \ No newline at end of file +} diff --git a/components/ide-service/pkg/server/testdata/resolve_ws_config_regular_code.golden b/components/ide-service/pkg/server/testdata/resolve_ws_config_regular_code.golden index 22e8d5a9e166fc..738ae1ed74d8ba 100644 --- a/components/ide-service/pkg/server/testdata/resolve_ws_config_regular_code.golden +++ b/components/ide-service/pkg/server/testdata/resolve_ws_config_regular_code.golden @@ -10,4 +10,4 @@ "web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9" }, "Err": "" -} \ No newline at end of file +} diff --git a/components/ide/jetbrains/launcher/main.go b/components/ide/jetbrains/launcher/main.go index f2d527088c5dce..373021b58a4f97 100644 --- a/components/ide/jetbrains/launcher/main.go +++ b/components/ide/jetbrains/launcher/main.go @@ -161,6 +161,7 @@ func main() { } if launchCtx.warmup { + waitForTasksToFinish() launch(launchCtx) return } @@ -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) + } + + 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 +}