Fix increased prewarming pool size

by checking the number of required runners before creating an additional runner.
This commit is contained in:
Maximilian Paß
2023-05-21 18:52:57 +01:00
parent 26ca7e4597
commit f7339570ae
2 changed files with 4 additions and 1 deletions

View File

@ -243,7 +243,7 @@ func (n *NomadEnvironment) ApplyPrewarmingPoolSize() error {
func (n *NomadEnvironment) Sample() (runner.Runner, bool) { func (n *NomadEnvironment) Sample() (runner.Runner, bool) {
r, ok := n.idleRunners.Sample() r, ok := n.idleRunners.Sample()
if ok { if ok && n.idleRunners.Length() < n.PrewarmingPoolSize() {
go func() { go func() {
err := util.RetryExponential(time.Second, func() error { err := util.RetryExponential(time.Second, func() error {
return n.createRunner(false) return n.createRunner(false)
@ -252,6 +252,8 @@ func (n *NomadEnvironment) Sample() (runner.Runner, bool) {
log.WithError(err).WithField("environmentID", n.ID()).Error("Couldn't create new runner for claimed one") log.WithError(err).WithField("environmentID", n.ID()).Error("Couldn't create new runner for claimed one")
} }
}() }()
} else if ok {
log.WithField("environment", n.ID().ToString()).Warn("Too many idle runner")
} }
return r, ok return r, ok
} }

View File

@ -178,6 +178,7 @@ func TestTwoSampleAddExactlyTwoRunners(t *testing.T) {
_, job := helpers.CreateTemplateJob() _, job := helpers.CreateTemplateJob()
environment := &NomadEnvironment{apiMock, templateEnvironmentJobHCL, job, environment := &NomadEnvironment{apiMock, templateEnvironmentJobHCL, job,
storage.NewLocalStorage[runner.Runner](), nil, nil} storage.NewLocalStorage[runner.Runner](), nil, nil}
environment.SetPrewarmingPoolSize(2)
runner1 := &runner.RunnerMock{} runner1 := &runner.RunnerMock{}
runner1.On("ID").Return(tests.DefaultRunnerID) runner1.On("ID").Return(tests.DefaultRunnerID)
runner2 := &runner.RunnerMock{} runner2 := &runner.RunnerMock{}