Skip to content
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
10 changes: 0 additions & 10 deletions components/common-go/experiments/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
const (
OIDCServiceEnabledFlag = "oidcServiceEnabled"
IdPClaimKeysFlag = "idp_claim_keys"
SetJavaXmxFlag = "supervisor_set_java_xmx"
SetJavaProcessorCount = "supervisor_set_java_processor_count"
)

func GetIdPClaimKeys(ctx context.Context, client Client, attributes Attributes) []string {
Expand All @@ -27,11 +25,3 @@ func GetIdPClaimKeys(ctx context.Context, client Client, attributes Attributes)
func IsOIDCServiceEnabled(ctx context.Context, client Client, attributes Attributes) bool {
return client.GetBoolValue(ctx, OIDCServiceEnabledFlag, false, attributes)
}

func IsSetJavaXmx(ctx context.Context, client Client, attributes Attributes) bool {
return client.GetBoolValue(ctx, SetJavaXmxFlag, false, attributes)
}

func IsSetJavaProcessorCount(ctx context.Context, client Client, attributes Attributes) bool {
return client.GetBoolValue(ctx, SetJavaProcessorCount, false, attributes)
}
18 changes: 18 additions & 0 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,17 @@ export class WorkspaceStarter {
orgIdEnv.setValue(await this.configProvider.getDefaultImage(workspace.organizationId));
sysEnvvars.push(orgIdEnv);

const client = getExperimentsClientForBackend();
const [isSetJavaXmx, isSetJavaProcessorCount] = await Promise.all([
client
.getValueAsync("supervisor_set_java_xmx", false, { user })
.then((v) => newEnvVar("GITPOD_IS_SET_JAVA_XMX", String(v))),
client
.getValueAsync("supervisor_set_java_processor_count", false, { user })
.then((v) => newEnvVar("GITPOD_IS_SET_JAVA_PROCESSOR_COUNT", String(v))),
]);
sysEnvvars.push(isSetJavaXmx);
sysEnvvars.push(isSetJavaProcessorCount);
const spec = new StartWorkspaceSpec();
await createGitpodTokenPromise;
spec.setEnvvarsList(envvars);
Expand Down Expand Up @@ -1937,3 +1948,10 @@ export class ScmStartError extends Error {
return !!o && o["host"];
}
}

function newEnvVar(key: string, value: string): EnvironmentVariable {
const env = new EnvironmentVariable();
env.setName(key);
env.setValue(value);
return env;
}
8 changes: 8 additions & 0 deletions components/supervisor/pkg/supervisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ type WorkspaceConfig struct {
// DefaultWorkspaceImage is the default image of current workspace
DefaultWorkspaceImage string `env:"GITPOD_DEFAULT_WORKSPACE_IMAGE"`

// IsSetJavaXmx is a flag to indicate if the JAVA_XMX environment variable is set
// value retrieved from server with FeatureFlag
IsSetJavaXmx bool `env:"GITPOD_IS_SET_JAVA_XMX"`

// IsSetJavaProcessorCount is a flag to indicate if the JAVA_PROCESSOR_COUNT environment variable is set
// value retrieved from server with FeatureFlag
IsSetJavaProcessorCount bool `env:"GITPOD_IS_SET_JAVA_PROCESSOR_COUNT"`

// IDEPort is the port at which the IDE will need to run on. This is not an IDE config
// because Gitpod determines this port, not the IDE.
IDEPort int `env:"GITPOD_THEIA_PORT"`
Expand Down
14 changes: 4 additions & 10 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,9 @@ func Run(options ...RunOption) {
}
exps := experiments.NewClient(experimentsClientOpts...)

isSetJavaXmx := experiments.IsSetJavaXmx(context.Background(), exps, experiments.Attributes{
UserID: cfg.OwnerId,
})
isSetJavaProcessorCount := experiments.IsSetJavaProcessorCount(context.Background(), exps, experiments.Attributes{
UserID: cfg.OwnerId,
})
// BEWARE: we can only call buildChildProcEnv once, because it might download env vars from a one-time-secret
// URL, which would fail if we tried another time.
childProcEnvvars = buildChildProcEnv(cfg, nil, opts.RunGP, isSetJavaXmx, isSetJavaProcessorCount)
childProcEnvvars = buildChildProcEnv(cfg, nil, opts.RunGP)

err = AddGitpodUserIfNotExists()
if err != nil {
Expand Down Expand Up @@ -1060,7 +1054,7 @@ func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig) *exec.Cmd {
// of envvars. If envvars is nil, os.Environ() is used.
//
// Beware: if config contains an OTS URL the results may differ on subsequent calls.
func buildChildProcEnv(cfg *Config, envvars []string, runGP bool, setJavaXmx bool, isSetJavaProcessorCount bool) []string {
func buildChildProcEnv(cfg *Config, envvars []string, runGP bool) []string {
if envvars == nil {
envvars = os.Environ()
}
Expand Down Expand Up @@ -1136,7 +1130,7 @@ func buildChildProcEnv(cfg *Config, envvars []string, runGP bool, setJavaXmx boo
envs["HOME"] = "/home/gitpod"
envs["USER"] = "gitpod"

if cpuCount, ok := envs["GITPOD_CPU_COUNT"]; ok && isSetJavaProcessorCount {
if cpuCount, ok := envs["GITPOD_CPU_COUNT"]; ok && cfg.IsSetJavaProcessorCount {
if _, exists := envs["JAVA_TOOL_OPTIONS"]; exists {
// check if the JAVA_TOOL_OPTIONS already contains the ActiveProcessorCount flag
if !strings.Contains(envs["JAVA_TOOL_OPTIONS"], "-XX:ActiveProcessorCount=") {
Expand All @@ -1147,7 +1141,7 @@ func buildChildProcEnv(cfg *Config, envvars []string, runGP bool, setJavaXmx boo
}
}
// Particular Java optimisation: Java pre v10 did not gauge it's available memory correctly, and needed explicitly setting "-Xmx" for all Hotspot/openJDK VMs
if mem, ok := envs["GITPOD_MEMORY"]; ok && setJavaXmx {
if mem, ok := envs["GITPOD_MEMORY"]; ok && cfg.IsSetJavaXmx {
envs["JAVA_TOOL_OPTIONS"] += fmt.Sprintf(" -Xmx%sm", mem)
}

Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/pkg/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestBuildChildProcEnv(t *testing.T) {
cfg.EnvvarOTS = srv.URL
}

act := buildChildProcEnv(cfg, test.Input, false, false, false)
act := buildChildProcEnv(cfg, test.Input, false)
assert(t, act)
})
}
Expand Down