Skip to content

Commit a78ad61

Browse files
Furistoroboquat
authored andcommitted
[loadgen] Add authentication & fix checkoutLocation
1 parent 6b14c1e commit a78ad61

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

dev/loadgen/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ In order to configure the benchmark, you can use the configuration file
4141
| successRate | Percentage of started workspaces that should enter running state to count as a successful run |
4242
| environment | Global environment variables that will be set for all repositories |
4343
| workspaceClass | The workspace class to use for workspaces. This setting can be overriden for individual repositories |
44+
| repoAuth | The authentication for a repository. This setting can be overriden for individual repositories |
45+
| repoAuth.authUser | The user that should be used for authentication |
46+
| repoAuth.authPassword | The password that should be used for authentication |
4447
| featureFlags | The feature flag passed when creating the workspace |
4548
| repos | The repositories that will be used to create workspaces |
4649
| repo.cloneURL | The url of the repository |
@@ -49,6 +52,9 @@ In order to configure the benchmark, you can use the configuration file
4952
| repo.workspaceImage | The docker image that will be used for the workspace |
5053
| repo.environment | Environment variables that will only be set for this repository |
5154
| repo.workspaceClass | The workspace class to use for the workspace that will be created for this repository |
55+
| repo.auth | The authentication for the repository |
56+
| repo.auth.authUser | The user that should be used for authentication |
57+
| repo.auth.authPassword | The password that should be used for authentication |
5258

5359
After the benchmark has completed, you will find a benchmark-result.json file in your working directory, that contains information about every started workspace.
5460

dev/loadgen/cmd/benchmark.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ var benchmarkCommand = &cobra.Command{
7474
7575
Username: "foobar",
7676
},
77-
FeatureFlags: scenario.FeatureFlags,
78-
Timeout: "5m",
79-
WorkspaceImage: "will-be-overriden",
80-
WorkspaceLocation: "workspace-stress",
81-
Envvars: scenario.Environment,
82-
Class: scenario.WorkspaceClass,
77+
FeatureFlags: scenario.FeatureFlags,
78+
Timeout: "5m",
79+
WorkspaceImage: "will-be-overriden",
80+
Envvars: scenario.Environment,
81+
Class: scenario.WorkspaceClass,
8382
},
8483
Type: api.WorkspaceType_REGULAR,
8584
}
@@ -125,7 +124,10 @@ var benchmarkCommand = &cobra.Command{
125124
Load: load,
126125
Specs: &loadgen.MultiWorkspaceGenerator{
127126
Template: template,
128-
Repos: scenario.Repos,
127+
Config: loadgen.MultiGeneratorConfig{
128+
Repos: scenario.Repos,
129+
Auth: scenario.RepositoryAuth,
130+
},
129131
},
130132
Worker: 5,
131133
Observer: []chan<- *loadgen.SessionEvent{
@@ -198,6 +200,7 @@ type BenchmarkScenario struct {
198200
SuccessRate float32 `json:"successRate"`
199201
WorkspaceClass string `json:"workspaceClass"`
200202
FeatureFlags []api.WorkspaceFeatureFlag `json:"featureFlags"`
203+
RepositoryAuth *loadgen.RepositoryAuth `json:"repoAuth,omitempty"`
201204
}
202205

203206
func handleWorkspaceDeletion(timeout string, executor loadgen.Executor, canceled bool) error {

dev/loadgen/configs/prod-benchmark-pvc.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ featureFlags:
1414
# https://github.com/gitpod-io/gitpod/blob/e437e1868072dfad1d195031a4709a254bd60dc8/components/ws-manager-api/core.proto#L596
1515
# from core.proto: PERSISTENT_VOLUME_CLAIM = 7;
1616
- 7
17+
# repoAuth:
18+
# authUser: ""
19+
# authPassword: ""
1720
repos:
1821
- cloneURL: https://github.com/Furisto/workspace-stress
1922
cloneTarget: main
@@ -79,7 +82,7 @@ repos:
7982
workspaceClass: "g1-large-pvc"
8083
- cloneURL: https://github.com/gitpod-io/template-python-django
8184
cloneTarget: main
82-
score: 20
85+
score: 0
8386
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:e764b1a602dc4123d9a027358367b5c4a35b62043e3c630731702144b7d37f77
8487
- cloneURL: https://github.com/gitpod-io/template-python-flask
8588
score: 20

dev/loadgen/pkg/loadgen/generator.go

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package loadgen
66

77
import (
88
"math/rand"
9+
"net/url"
10+
"path"
11+
"strings"
912
"sync/atomic"
1013
"time"
1114

@@ -161,11 +164,22 @@ type WorkspaceCfg struct {
161164
Score int `json:"score"`
162165
Environment []*api.EnvironmentVariable `json:"environment"`
163166
WorkspaceClass string `json:"workspaceClass"`
167+
RepositoryAuth *RepositoryAuth `json:"auth,omitempty"`
168+
}
169+
170+
type RepositoryAuth struct {
171+
AuthUser string `json:"authUser"`
172+
AuthPassword string `json:"authPassword"`
164173
}
165174

166175
type MultiWorkspaceGenerator struct {
167176
Template *api.StartWorkspaceRequest
168-
Repos []WorkspaceCfg
177+
Config MultiGeneratorConfig
178+
}
179+
180+
type MultiGeneratorConfig struct {
181+
Repos []WorkspaceCfg
182+
Auth *RepositoryAuth
169183
}
170184

171185
func (f *MultiWorkspaceGenerator) Generate() (*StartWorkspaceSpec, error) {
@@ -178,7 +192,7 @@ func (f *MultiWorkspaceGenerator) Generate() (*StartWorkspaceSpec, error) {
178192
return nil, err
179193
}
180194

181-
repo := selectRepo(f.Repos)
195+
repo := selectRepo(f.Config.Repos)
182196
log.Infof("selecting repo %s", repo.CloneURL)
183197

184198
out := proto.Clone(f.Template).(*api.StartWorkspaceRequest)
@@ -187,21 +201,29 @@ func (f *MultiWorkspaceGenerator) Generate() (*StartWorkspaceSpec, error) {
187201
if out.Metadata.Annotations == nil {
188202
out.Metadata.Annotations = make(map[string]string)
189203
}
204+
205+
cloneUrl, err := url.Parse(repo.CloneURL)
206+
if err != nil {
207+
return nil, err
208+
}
209+
repositoryName := strings.TrimRight(path.Base(cloneUrl.Path), ".git")
210+
gitConfig := f.prepareGitConfig(repo)
211+
190212
out.Metadata.Annotations["context-url"] = repo.CloneURL
191213
out.ServicePrefix = workspaceID
214+
out.Spec.WorkspaceLocation = repositoryName
192215
out.Spec.Initializer = &csapi.WorkspaceInitializer{
193216
Spec: &csapi.WorkspaceInitializer_Git{
194217
Git: &csapi.GitInitializer{
195-
CheckoutLocation: "",
218+
CheckoutLocation: repositoryName,
196219
CloneTaget: repo.CloneTarget,
197220
RemoteUri: repo.CloneURL,
198221
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,
199-
Config: &csapi.GitConfig{
200-
Authentication: csapi.GitAuthMethod_NO_AUTH,
201-
},
222+
Config: gitConfig,
202223
},
203224
},
204225
}
226+
205227
out.Spec.WorkspaceImage = repo.WorkspaceImage
206228
if len(repo.WorkspaceClass) > 0 {
207229
out.Spec.Class = repo.WorkspaceClass
@@ -229,3 +251,22 @@ func selectRepo(repos []WorkspaceCfg) WorkspaceCfg {
229251

230252
return repos[len(repos)-1]
231253
}
254+
255+
func (f *MultiWorkspaceGenerator) prepareGitConfig(repo WorkspaceCfg) *csapi.GitConfig {
256+
gitConfig := &csapi.GitConfig{
257+
Authentication: csapi.GitAuthMethod_NO_AUTH,
258+
}
259+
if f.Config.Auth != nil {
260+
gitConfig.Authentication = csapi.GitAuthMethod_BASIC_AUTH
261+
gitConfig.AuthUser = f.Config.Auth.AuthUser
262+
gitConfig.AuthPassword = f.Config.Auth.AuthPassword
263+
}
264+
265+
if repo.RepositoryAuth != nil {
266+
gitConfig.Authentication = csapi.GitAuthMethod_BASIC_AUTH
267+
gitConfig.AuthUser = repo.RepositoryAuth.AuthUser
268+
gitConfig.AuthPassword = repo.RepositoryAuth.AuthPassword
269+
}
270+
271+
return gitConfig
272+
}

0 commit comments

Comments
 (0)