Skip to content

Commit 0b20a63

Browse files
Andrew Farriesroboquat
authored andcommitted
Make usage report bucket name configurable
The name of the object storage bucket to which usage reports are uploaded needs to be configurable for Gitpod SaaS. GCloud bucket names are globally unique, so the bucket name must vary between staging and production.
1 parent 74bf2aa commit 0b20a63

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

components/content-service-api/go/config/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ type PProf struct {
114114
Addr string `json:"address"`
115115
}
116116

117+
// UsageReportConfig configures the upload of workspace instance usage reports
118+
type UsageReportConfig struct {
119+
BucketName string `json:"bucketName"`
120+
}
121+
117122
type ServiceConfig struct {
118-
Service baseserver.ServerConfiguration `json:"service"`
119-
Storage StorageConfig `json:"storage"`
123+
Service baseserver.ServerConfiguration `json:"service"`
124+
Storage StorageConfig `json:"storage"`
125+
UsageReports UsageReportConfig `json:"usageReport"`
120126
}

install/installer/pkg/components/content-service/configmap.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ import (
1111

1212
"github.com/gitpod-io/gitpod/content-service/api/config"
1313
"github.com/gitpod-io/gitpod/installer/pkg/common"
14+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
1415

1516
corev1 "k8s.io/api/core/v1"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
"k8s.io/apimachinery/pkg/runtime"
1819
)
1920

2021
func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
22+
usageReportBucketName := "gitpod-usage-reports"
23+
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
24+
if cfg.Workspace != nil && cfg.Workspace.ContentService.UsageReportBucketName != "" {
25+
usageReportBucketName = cfg.Workspace.ContentService.UsageReportBucketName
26+
}
27+
return nil
28+
})
29+
2130
cscfg := config.ServiceConfig{
2231
Service: baseserver.ServerConfiguration{
2332
Address: fmt.Sprintf(":%d", RPCPort),
2433
},
2534
Storage: common.StorageConfig(ctx),
35+
UsageReports: config.UsageReportConfig{
36+
BucketName: usageReportBucketName,
37+
},
2638
}
2739

2840
fc, err := common.ToJSONString(cscfg)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the MIT License. See License-MIT.txt in the project root for license information.
3+
4+
package content_service
5+
6+
import (
7+
"encoding/json"
8+
"testing"
9+
10+
csconfig "github.com/gitpod-io/gitpod/content-service/api/config"
11+
"github.com/gitpod-io/gitpod/installer/pkg/common"
12+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
13+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
14+
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
15+
"github.com/stretchr/testify/require"
16+
corev1 "k8s.io/api/core/v1"
17+
"k8s.io/utils/pointer"
18+
)
19+
20+
func TestConfigMap_CanConfigureUsageReportBucketName(t *testing.T) {
21+
ctx := newRenderContext(t)
22+
objs, err := configmap(ctx)
23+
require.NoError(t, err)
24+
require.Len(t, objs, 1, "must only render one configmap")
25+
26+
expectedUsageReportConfig := csconfig.UsageReportConfig{BucketName: "some-bucket-name"}
27+
expectedJSON, err := common.ToJSONString(expectedUsageReportConfig)
28+
require.NoError(t, err)
29+
30+
cm, ok := objs[0].(*corev1.ConfigMap)
31+
require.True(t, ok)
32+
33+
var fullConfig csconfig.ServiceConfig
34+
err = json.Unmarshal([]byte(cm.Data["config.json"]), &fullConfig)
35+
require.NoError(t, err)
36+
37+
actualUsageReportConfig := fullConfig.UsageReports
38+
actualJSON, err := common.ToJSONString(actualUsageReportConfig)
39+
require.NoError(t, err)
40+
41+
require.JSONEq(t, string(expectedJSON), string(actualJSON))
42+
}
43+
44+
func newRenderContext(t *testing.T) *common.RenderContext {
45+
t.Helper()
46+
47+
ctx, err := common.NewRenderContext(config.Config{
48+
Domain: "test.domain.everything.awesome.is",
49+
ObjectStorage: config.ObjectStorage{InCluster: pointer.Bool(true)},
50+
Experimental: &experimental.Config{
51+
Workspace: &experimental.WorkspaceConfig{
52+
ContentService: struct {
53+
UsageReportBucketName string "json:\"usageReportBucketName\""
54+
}{UsageReportBucketName: "some-bucket-name"},
55+
},
56+
},
57+
}, versions.Manifest{}, "test-namespace")
58+
59+
require.NoError(t, err)
60+
61+
return ctx
62+
}

install/installer/pkg/config/v1/experimental/experimental.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ type WorkspaceConfig struct {
103103
GitpodInstallationWorkspaceHostSuffix string `json:"gitpodInstallationWorkspaceHostSuffix"`
104104
GitpodInstallationWorkspaceHostSuffixRegex string `json:"gitpodInstallationWorkspaceHostSuffixRegex"`
105105
} `json:"wsProxy"`
106+
107+
ContentService struct {
108+
UsageReportBucketName string `json:"usageReportBucketName"`
109+
} `json:"contentService"`
106110
}
107111

108112
type PersistentVolumeClaim struct {

0 commit comments

Comments
 (0)