Skip to content

Commit db5af89

Browse files
authored
Get java feature flags from server (#19984)
* Get java feature flags from server * fix build
1 parent ca69313 commit db5af89

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

components/common-go/experiments/flags.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
const (
1313
OIDCServiceEnabledFlag = "oidcServiceEnabled"
1414
IdPClaimKeysFlag = "idp_claim_keys"
15-
SetJavaXmxFlag = "supervisor_set_java_xmx"
16-
SetJavaProcessorCount = "supervisor_set_java_processor_count"
1715
)
1816

1917
func GetIdPClaimKeys(ctx context.Context, client Client, attributes Attributes) []string {
@@ -27,11 +25,3 @@ func GetIdPClaimKeys(ctx context.Context, client Client, attributes Attributes)
2725
func IsOIDCServiceEnabled(ctx context.Context, client Client, attributes Attributes) bool {
2826
return client.GetBoolValue(ctx, OIDCServiceEnabledFlag, false, attributes)
2927
}
30-
31-
func IsSetJavaXmx(ctx context.Context, client Client, attributes Attributes) bool {
32-
return client.GetBoolValue(ctx, SetJavaXmxFlag, false, attributes)
33-
}
34-
35-
func IsSetJavaProcessorCount(ctx context.Context, client Client, attributes Attributes) bool {
36-
return client.GetBoolValue(ctx, SetJavaProcessorCount, false, attributes)
37-
}

components/server/src/workspace/workspace-starter.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,17 @@ export class WorkspaceStarter {
14841484
orgIdEnv.setValue(await this.configProvider.getDefaultImage(workspace.organizationId));
14851485
sysEnvvars.push(orgIdEnv);
14861486

1487+
const client = getExperimentsClientForBackend();
1488+
const [isSetJavaXmx, isSetJavaProcessorCount] = await Promise.all([
1489+
client
1490+
.getValueAsync("supervisor_set_java_xmx", false, { user })
1491+
.then((v) => newEnvVar("GITPOD_IS_SET_JAVA_XMX", String(v))),
1492+
client
1493+
.getValueAsync("supervisor_set_java_processor_count", false, { user })
1494+
.then((v) => newEnvVar("GITPOD_IS_SET_JAVA_PROCESSOR_COUNT", String(v))),
1495+
]);
1496+
sysEnvvars.push(isSetJavaXmx);
1497+
sysEnvvars.push(isSetJavaProcessorCount);
14871498
const spec = new StartWorkspaceSpec();
14881499
await createGitpodTokenPromise;
14891500
spec.setEnvvarsList(envvars);
@@ -1937,3 +1948,10 @@ export class ScmStartError extends Error {
19371948
return !!o && o["host"];
19381949
}
19391950
}
1951+
1952+
function newEnvVar(key: string, value: string): EnvironmentVariable {
1953+
const env = new EnvironmentVariable();
1954+
env.setName(key);
1955+
env.setValue(value);
1956+
return env;
1957+
}

components/supervisor/pkg/supervisor/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ type WorkspaceConfig struct {
251251
// DefaultWorkspaceImage is the default image of current workspace
252252
DefaultWorkspaceImage string `env:"GITPOD_DEFAULT_WORKSPACE_IMAGE"`
253253

254+
// IsSetJavaXmx is a flag to indicate if the JAVA_XMX environment variable is set
255+
// value retrieved from server with FeatureFlag
256+
IsSetJavaXmx bool `env:"GITPOD_IS_SET_JAVA_XMX"`
257+
258+
// IsSetJavaProcessorCount is a flag to indicate if the JAVA_PROCESSOR_COUNT environment variable is set
259+
// value retrieved from server with FeatureFlag
260+
IsSetJavaProcessorCount bool `env:"GITPOD_IS_SET_JAVA_PROCESSOR_COUNT"`
261+
254262
// IDEPort is the port at which the IDE will need to run on. This is not an IDE config
255263
// because Gitpod determines this port, not the IDE.
256264
IDEPort int `env:"GITPOD_THEIA_PORT"`

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,9 @@ func Run(options ...RunOption) {
199199
}
200200
exps := experiments.NewClient(experimentsClientOpts...)
201201

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

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

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

components/supervisor/pkg/supervisor/supervisor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestBuildChildProcEnv(t *testing.T) {
133133
cfg.EnvvarOTS = srv.URL
134134
}
135135

136-
act := buildChildProcEnv(cfg, test.Input, false, false, false)
136+
act := buildChildProcEnv(cfg, test.Input, false)
137137
assert(t, act)
138138
})
139139
}

0 commit comments

Comments
 (0)