Skip to content

Commit

Permalink
Add scaling factor flag to scale client-side requests
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <[email protected]>
  • Loading branch information
sambhav committed Jul 15, 2024
1 parent 93a7c2c commit 80d752a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import (
)

const (
routinesPerController = 2
component = "controller"
defaultRoutinesPerController = 2
component = "controller"
)

var (
Expand All @@ -91,6 +91,7 @@ func main() {
flag.BoolVar(&cfg.EnablePriorityClasses, "enable-priority-classes", flaghelpers.GetEnvBool("ENABLE_PRIORITY_CLASSES", false), "if set to true, enables different pod priority classes for normal builds and automated builds")
flag.StringVar(&cfg.MaximumPlatformApiVersion, "maximum-platform-api-version", os.Getenv("MAXIMUM_PLATFORM_API_VERSION"), "The maximum allowed platform api version a build can utilize")
flag.BoolVar(&cfg.SshTrustUnknownHosts, "insecure-ssh-trust-unknown-hosts", flaghelpers.GetEnvBool("INSECURE_SSH_TRUST_UNKNOWN_HOSTS", true), "if set to true, automatically trust unknown hosts when using git ssh source")
flag.IntVar(&cfg.ScalingFactor, "scaling-factor", flaghelpers.GetEnvInt("SCALING_FACTOR", 1), "The scaling factor to scale client-side rate limits by")

flag.BoolVar(&featureFlags.InjectedSidecarSupport, "injected-sidecar-support", flaghelpers.GetEnvBool("INJECTED_SIDECAR_SUPPORT", false), "if set to true, all builds will execute in standard containers instead of init containers to support injected sidecars")
flag.BoolVar(&featureFlags.GenerateSlsaAttestation, "experimental-generate-slsa-attestation", flaghelpers.GetEnvBool("EXPERIMENTAL_GENERATE_SLSA_ATTESTATION", false), "if set to true, SLSA attestations will be generated for each build")
Expand Down Expand Up @@ -260,6 +261,7 @@ func main() {
clusterStackInformer.Informer(),
)

routinesPerController := defaultRoutinesPerController * cfg.ScalingFactor
err = runGroup(
ctx,
run(clusterStackController, routinesPerController),
Expand Down Expand Up @@ -311,13 +313,13 @@ func runGroup(ctx context.Context, fns ...func(ctx context.Context) error) error
const controllerCount = 7

// lifted from knative.dev/pkg/injection/sharedmain
func genericControllerSetup(ctx context.Context, cfg *rest.Config) (*zap.SugaredLogger, *informer.InformedWatcher, *http.Server) {
func genericControllerSetup(ctx context.Context, restCfg *rest.Config) (*zap.SugaredLogger, *informer.InformedWatcher, *http.Server) {
metrics.MemStatsOrDie(ctx)

// Adjust our client's rate limits based on the number of controllers we are running.
cfg.QPS = float32(controllerCount) * rest.DefaultQPS
cfg.Burst = controllerCount * rest.DefaultBurst
ctx, _ = injection.Default.SetupInformers(ctx, cfg)
restCfg.QPS = float32(controllerCount) * rest.DefaultQPS * float32(cfg.ScalingFactor)
restCfg.Burst = controllerCount * rest.DefaultBurst * cfg.ScalingFactor
ctx, _ = injection.Default.SetupInformers(ctx, restCfg)

logger, atomicLevel := sharedmain.SetupLoggerOrDie(ctx, component)
ctx = logging.WithLogger(ctx, logger)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Config struct {
EnablePriorityClasses bool `json:"enablePriorityClasses"`
MaximumPlatformApiVersion string `json:"maximumPlatformApiVersion"`
SshTrustUnknownHosts bool `json:"sshTrustUnknownHosts"`
ScalingFactor int `json:"scalingFactor"`
}

type FeatureFlags struct {
Expand Down
13 changes: 13 additions & 0 deletions pkg/flaghelpers/credential_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ func (i *CredentialsFlags) Set(value string) error {

func GetEnvBool(key string, defaultValue bool) bool {
s := os.Getenv(key)
if s == "" {
return defaultValue
}
v, err := strconv.ParseBool(s)
if err != nil {
return defaultValue
}
return v
}


func GetEnvInt(key string, defaultValue int) int {
s := os.Getenv(key)
v, err := strconv.Atoi(s)
if err != nil {
return defaultValue
}
return v
}
1 change: 1 addition & 0 deletions pkg/slsa/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func testAttester(t *testing.T, when spec.G, it spec.S) {
"enablePriorityClasses": false,
"maximumPlatformApiVersion": "",
"sshTrustUnknownHosts": true,
"scalingFactor": 0,
"buildInitImage": "build-init-image",
"buildInitWindowsImage": "build-init-windows-image",
"buildWaiterImage": "build-waiter-image",
Expand Down

0 comments on commit 80d752a

Please sign in to comment.