Skip to content

Commit b465d06

Browse files
authored
Uniformly use proxy to get the configuration of configcat (#16942)
* Uniformly use proxy to get the configuration of configcat * Add configcat enabled in workspace info api * enabled configcat in ide-service
1 parent 555ee27 commit b465d06

File tree

11 files changed

+104
-55
lines changed

11 files changed

+104
-55
lines changed

components/common-go/experiments/types.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,43 @@ type Attributes struct {
3232
VSCodeClientID string
3333
}
3434

35+
type ClientOpt func(o *options)
36+
37+
func WithGitpodProxy(gitpodHost string) ClientOpt {
38+
return func(o *options) {
39+
o.sdkKey = "gitpod"
40+
o.baseURL = fmt.Sprintf("https://%s/configcat", gitpodHost)
41+
o.pollInterval = 1 * time.Minute
42+
}
43+
}
44+
45+
type options struct {
46+
pollInterval time.Duration
47+
baseURL string
48+
sdkKey string
49+
}
50+
3551
// NewClient constructs a new experiments.Client. This is NOT A SINGLETON.
3652
// You should normally only call this once in the lifecycle of an application, clients are independent of each other will refresh flags on their own.
37-
// If the environment contains CONFIGCAT_SDK_KEY value, it vill be used to construct a ConfigCat client.
53+
// If the environment contains CONFIGCAT_SDK_KEY value, it will be used to construct a ConfigCat client.
3854
// Otherwise, it returns a client which always returns the default value. This client is used for Self-Hosted installations.
39-
func NewClient() Client {
40-
// TODO: get rid fo GITPOD_HOST is implementaion detail of supervisor, it is a subject to change
41-
// gitpodHost should be provided as an option instead
42-
gitpodHost := os.Getenv("GITPOD_HOST")
43-
if gitpodHost == "" {
44-
gitpodHost = os.Getenv("HOST_URL")
55+
func NewClient(opts ...ClientOpt) Client {
56+
opt := &options{
57+
sdkKey: os.Getenv("CONFIGCAT_SDK_KEY"),
58+
baseURL: os.Getenv("CONFIGCAT_BASE_URL"),
59+
pollInterval: 3 * time.Minute,
4560
}
46-
if gitpodHost != "" {
47-
return newConfigCatClient(configcat.Config{
48-
SDKKey: "gitpod",
49-
BaseURL: fmt.Sprintf("%s%s", gitpodHost, "/configcat"),
50-
PollInterval: 1 * time.Minute,
51-
HTTPTimeout: 3 * time.Second,
52-
})
61+
for _, o := range opts {
62+
o(opt)
5363
}
54-
sdkKey := os.Getenv("CONFIGCAT_SDK_KEY")
55-
if sdkKey == "" {
64+
65+
if opt.sdkKey == "" {
5666
return NewAlwaysReturningDefaultValueClient()
5767
}
5868
return newConfigCatClient(configcat.Config{
59-
SDKKey: sdkKey,
60-
PollInterval: 3 * time.Minute,
69+
SDKKey: opt.sdkKey,
70+
BaseURL: opt.baseURL,
71+
PollInterval: opt.pollInterval,
6172
HTTPTimeout: 3 * time.Second,
6273
Logger: &configCatLogger{log.Log},
6374
})

components/gitpod-protocol/src/experiments/configcat-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function getExperimentsClientForBackend(): Client {
3535
requestTimeoutMs: 2000,
3636
logger: configcat.createConsoleLogger(LogLevel.Error),
3737
maxInitWaitTimeSeconds: 0,
38+
baseUrl: process.env.CONFIGCAT_BASE_URL,
3839
});
3940

4041
client = new ConfigCatClient(configCatClient);

components/ide-service/pkg/server/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
254254
IdeImageLayers: defaultIde.ImageLayers,
255255
}
256256

257+
if os.Getenv("CONFIGCAT_SDK_KEY") != "" {
258+
resp.Envvars = append(resp.Envvars, &api.EnvironmentVariable{
259+
Name: "GITPOD_CONFIGCAT_ENABLED",
260+
Value: "true",
261+
})
262+
}
263+
257264
var wsConfig *gitpodapi.GitpodConfig
258265

259266
if req.WorkspaceConfig != "" {

components/supervisor-api/go/info.pb.go

Lines changed: 47 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/info.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ message WorkspaceInfoResponse {
9797

9898
// debug_workspace_type indicates whether it is a regular or prebuild debug workspace
9999
DebugWorkspaceType debug_workspace_type = 17;
100+
101+
// configcat_enabled controls whether configcat is enabled
102+
bool configcat_enabled = 18;
100103
}
101104

102105
enum DebugWorkspaceType {

components/supervisor/pkg/serverapi/publicapi.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type ServiceConfig struct {
5252
WorkspaceID string
5353
OwnerID string
5454
SupervisorVersion string
55+
ConfigcatEnabled bool
5556
}
5657

5758
type Service struct {
@@ -109,11 +110,15 @@ func NewServerApiService(ctx context.Context, cfg *ServiceConfig, tknsrv api.Tok
109110
return nil
110111
}
111112

113+
opts := []experiments.ClientOpt{}
114+
if cfg.ConfigcatEnabled {
115+
opts = append(opts, experiments.WithGitpodProxy(cfg.Host))
116+
}
112117
service := &Service{
113118
token: tknres.Token,
114119
gitpodService: gitpodService,
115120
cfg: cfg,
116-
experiments: experiments.NewClient(),
121+
experiments: experiments.NewClient(opts...),
117122
apiMetrics: NewClientMetrics(),
118123
onUsingPublicAPI: make(chan struct{}),
119124
subs: make(map[chan *gitpod.WorkspaceInstance]struct{}),

components/supervisor/pkg/supervisor/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ type WorkspaceConfig struct {
298298

299299
// DebugWorkspaceContenSource indicates where the debug workspace content came from
300300
DebugWorkspaceContenSource api.ContentSource `env:"SUPERVISOR_DEBUG_WORKSPACE_CONTENT_SOURCE"`
301+
302+
// ConfigcatEnabled controls whether configcat is enabled
303+
ConfigcatEnabled bool `env:"GITPOD_CONFIGCAT_ENABLED"`
301304
}
302305

303306
// WorkspaceGitpodToken is a list of tokens that should be added to supervisor's token service.

components/supervisor/pkg/supervisor/services.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ func (is *InfoService) WorkspaceInfo(context.Context, *api.WorkspaceInfoRequest)
670670
WorkspaceClass: &api.WorkspaceInfoResponse_WorkspaceClass{Id: is.cfg.WorkspaceClass},
671671
OwnerId: is.cfg.OwnerId,
672672
DebugWorkspaceType: is.cfg.DebugWorkspaceType,
673+
ConfigcatEnabled: is.cfg.ConfigcatEnabled,
673674
}
674675
if is.cfg.WorkspaceClassInfo != nil {
675676
resp.WorkspaceClass.DisplayName = is.cfg.WorkspaceClassInfo.DisplayName

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func Run(options ...RunOption) {
262262
WorkspaceID: cfg.WorkspaceID,
263263
OwnerID: cfg.OwnerId,
264264
SupervisorVersion: Version,
265+
ConfigcatEnabled: cfg.ConfigcatEnabled,
265266
}, tokenService)
266267
}
267268

install/installer/pkg/common/common.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ func ConfigcatEnv(ctx *RenderContext) []corev1.EnvVar {
424424
return []corev1.EnvVar{
425425
{
426426
Name: "CONFIGCAT_SDK_KEY",
427-
Value: sdkKey,
427+
Value: "gitpod",
428+
},
429+
{
430+
Name: "CONFIGCAT_BASE_URL",
431+
Value: "https://" + ctx.Config.Domain + "/configcat",
428432
},
429433
}
430434
}

install/installer/pkg/components/ide-service/deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
7979
},
8080
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
8181
common.DefaultEnv(&ctx.Config),
82+
common.ConfigcatEnv(ctx),
8283
)),
8384
VolumeMounts: []corev1.VolumeMount{
8485
{

0 commit comments

Comments
 (0)