From f2a991d345be639f79cad8cd5aeacab4f1f65b7b Mon Sep 17 00:00:00 2001 From: luke-lombardi <33990301+luke-lombardi@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:31:48 -0400 Subject: [PATCH] make maxreplicas configurable --- pkg/abstractions/common/autoscaler.go | 5 ++--- pkg/abstractions/endpoint/autoscaler.go | 4 ++-- pkg/abstractions/taskqueue/autoscaler.go | 4 ++-- pkg/common/config.default.yaml | 1 + pkg/types/config.go | 3 ++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/abstractions/common/autoscaler.go b/pkg/abstractions/common/autoscaler.go index ded24a7cb..1b3c9e905 100644 --- a/pkg/abstractions/common/autoscaler.go +++ b/pkg/abstractions/common/autoscaler.go @@ -22,9 +22,8 @@ type IAutoscaler interface { } const ( - MaxReplicas uint = 10 // Maximum number of desired replicas that can be returned - windowSize int = 60 // Number of samples in the sampling window - sampleRate time.Duration = time.Duration(1000) * time.Millisecond // Time between samples + windowSize int = 60 // Number of samples in the sampling window + sampleRate time.Duration = time.Duration(1000) * time.Millisecond // Time between samples ) type AutoscalerSample interface{} diff --git a/pkg/abstractions/endpoint/autoscaler.go b/pkg/abstractions/endpoint/autoscaler.go index c1cd74bba..a466a8e40 100644 --- a/pkg/abstractions/endpoint/autoscaler.go +++ b/pkg/abstractions/endpoint/autoscaler.go @@ -50,8 +50,8 @@ func endpointDeploymentScaleFunc(i *endpointInstance, s *endpointAutoscalerSampl desiredContainers += 1 } - // Limit max replicas to either what was set in autoscaler config, or our default of MaxReplicas (whichever is lower) - maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(abstractions.MaxReplicas)) + // Limit max replicas to either what was set in autoscaler config, or the limit specified on the gateway config (whichever is lower) + maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(i.AppConfig.GatewayService.StubLimits.MaxReplicas)) desiredContainers = int(math.Min(maxReplicas, float64(desiredContainers))) } diff --git a/pkg/abstractions/taskqueue/autoscaler.go b/pkg/abstractions/taskqueue/autoscaler.go index d8b19dae0..4b8ae4d63 100644 --- a/pkg/abstractions/taskqueue/autoscaler.go +++ b/pkg/abstractions/taskqueue/autoscaler.go @@ -66,8 +66,8 @@ func taskQueueScaleFunc(i *taskQueueInstance, s *taskQueueAutoscalerSample) *abs desiredContainers += 1 } - // Limit max replicas to either what was set in autoscaler config, or our default of MaxReplicas (whichever is lower) - maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(abstractions.MaxReplicas)) + // Limit max replicas to either what was set in autoscaler config, or the limit specified on the gateway config (whichever is lower) + maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(i.AppConfig.GatewayService.StubLimits.MaxReplicas)) desiredContainers = int(math.Min(maxReplicas, float64(desiredContainers))) } diff --git a/pkg/common/config.default.yaml b/pkg/common/config.default.yaml index 94c965c15..4eac184e9 100644 --- a/pkg/common/config.default.yaml +++ b/pkg/common/config.default.yaml @@ -48,6 +48,7 @@ gateway: shutdownTimeout: 180s stubLimits: memory: 32768 + maxReplicas: 10 imageService: localCacheEnabled: true registryStore: local diff --git a/pkg/types/config.go b/pkg/types/config.go index 3b6e310d0..4c4628989 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -84,7 +84,8 @@ type CORSConfig struct { } type StubLimits struct { - Memory uint64 `key:"memory" json:"memory"` + Memory uint64 `key:"memory" json:"memory"` + MaxReplicas uint64 `key:"maxReplicas" json:"max_replicas"` } type GatewayServiceConfig struct {