From 940f23420544f76a67ae3ed32e726c9f9c9c4b3d Mon Sep 17 00:00:00 2001 From: Gero Posmyk-Leinemann Date: Thu, 20 Jun 2024 13:19:15 +0200 Subject: [PATCH] [server] Move ff google_cloud_profiler into env var/installer config (#19912) --- components/server/src/init.ts | 10 +++++----- dev/preview/workflow/preview/deploy-gitpod.sh | 5 +++++ install/installer/pkg/components/server/deployment.go | 10 ++++++++++ .../pkg/config/v1/experimental/experimental.go | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/server/src/init.ts b/components/server/src/init.ts index 713bc7075ba463..60d8882001d183 100644 --- a/components/server/src/init.ts +++ b/components/server/src/init.ts @@ -59,7 +59,6 @@ import { installLogCountMetric } from "@gitpod/gitpod-protocol/lib/util/logging- import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing"; import { TypeORM } from "@gitpod/gitpod-db/lib"; import { dbConnectionsEnqueued, dbConnectionsFree, dbConnectionsTotal } from "./prometheus-metrics"; -import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server"; import { installCtxLogAugmenter } from "./util/log-context"; if (process.env.NODE_ENV === "development") { require("longjohn"); @@ -71,11 +70,12 @@ installLogCountMetric(); // eslint-disable-next-line @typescript-eslint/no-floating-promises (async () => { - let isEnabled = await getExperimentsClientForBackend().getValueAsync("google_cloud_profiler", false, {}); - while (!isEnabled) { - await new Promise((resolve) => setTimeout(resolve, 3000)); - isEnabled = await getExperimentsClientForBackend().getValueAsync("google_cloud_profiler", false, {}); + if (process.env.GOOGLE_CLOUD_PROFILER?.toLocaleLowerCase() !== "true") { + console.log("skipping cloud profiler, not enabled"); + return; } + console.log("starting cloud profiler"); + try { const profiler = await import("@google-cloud/profiler"); // there is no way to stop it: https://github.com/googleapis/cloud-profiler-nodejs/issues/876 diff --git a/dev/preview/workflow/preview/deploy-gitpod.sh b/dev/preview/workflow/preview/deploy-gitpod.sh index eabe4e4a9dede7..7f18fac19aeed2 100755 --- a/dev/preview/workflow/preview/deploy-gitpod.sh +++ b/dev/preview/workflow/preview/deploy-gitpod.sh @@ -447,6 +447,11 @@ yq w -i "${INSTALLER_CONFIG_PATH}" experimental.workspace.networkLimits.enforce yq w -i "${INSTALLER_CONFIG_PATH}" experimental.workspace.networkLimits.connectionsPerMinute "3000" yq w -i "${INSTALLER_CONFIG_PATH}" experimental.workspace.networkLimits.bucketSize "3000" +# +# Enable GCP profiling in server +# +yq w -i "${INSTALLER_CONFIG_PATH}" experimental.webapp.server.gcpProfilerEnabled "true" + log_success "Generated config at $INSTALLER_CONFIG_PATH" # ======== diff --git a/install/installer/pkg/components/server/deployment.go b/install/installer/pkg/components/server/deployment.go index eceb8c5ef7b46a..40832b5cda3007 100644 --- a/install/installer/pkg/components/server/deployment.go +++ b/install/installer/pkg/components/server/deployment.go @@ -142,6 +142,16 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) { return nil }) + _ = ctx.WithExperimental(func(cfg *experimental.Config) error { + if cfg.WebApp != nil && cfg.WebApp.Server != nil && cfg.WebApp.Server.GoogleCloudProfilerEnabled { + env = append(env, corev1.EnvVar{ + Name: "GOOGLE_CLOUD_PROFILER", + Value: "true", + }) + } + return nil + }) + volumes := make([]corev1.Volume, 0) volumeMounts := make([]corev1.VolumeMount, 0) diff --git a/install/installer/pkg/config/v1/experimental/experimental.go b/install/installer/pkg/config/v1/experimental/experimental.go index a7cb75ab9a9df9..1826651b5934d1 100644 --- a/install/installer/pkg/config/v1/experimental/experimental.go +++ b/install/installer/pkg/config/v1/experimental/experimental.go @@ -274,6 +274,8 @@ type ServerConfig struct { // @deprecated use containerRegistry.privateBaseImageAllowList instead DefaultBaseImageRegistryWhiteList []string `json:"defaultBaseImageRegistryWhitelist"` + + GoogleCloudProfilerEnabled bool `json:"gcpProfilerEnabled,omitempty"` } type ProxyConfig struct {