Refactor PrewarmingPoolAlert triggering
from route-based to Nomad-Event-Stream-based.
This commit is contained in:

committed by
Sebastian Serth

parent
7b82300ff7
commit
0f7e98f78e
@ -35,7 +35,7 @@ func checkPrewarmingPool(manager environment.Manager) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(depletingEnvironments) > 0 {
|
if len(depletingEnvironments) > 0 {
|
||||||
arrayToString := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(depletingEnvironments)), ","), "[]")
|
arrayToString := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(depletingEnvironments)), ", "), "[]")
|
||||||
return fmt.Errorf("%w: environments %s", ErrorPrewarmingPoolDepleting, arrayToString)
|
return fmt.Errorf("%w: environments %s", ErrorPrewarmingPoolDepleting, arrayToString)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -110,8 +110,8 @@ func (m *NomadRunnerManager) DeleteEnvironment(id dto.EnvironmentID) {
|
|||||||
m.reloadingEnvironment.Delete(id.ToString())
|
m.reloadingEnvironment.Delete(id.ToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkPrewarmingPoolAlert checks if the prewarming pool contains enough idle runners as specified by the PrewarmingPoolThreshold
|
// checkPrewarmingPoolAlert checks if the prewarming pool contains enough idle runners as specified by the PrewarmingPoolThreshold.
|
||||||
// if not it starts an environment reload mechanism according to the PrewarmingPoolReloadTimeout.
|
// If not, it starts an environment reload mechanism according to the PrewarmingPoolReloadTimeout.
|
||||||
func (m *NomadRunnerManager) checkPrewarmingPoolAlert(environment ExecutionEnvironment, runnerAdded bool) {
|
func (m *NomadRunnerManager) checkPrewarmingPoolAlert(environment ExecutionEnvironment, runnerAdded bool) {
|
||||||
data, ok := m.reloadingEnvironment.Get(environment.ID().ToString())
|
data, ok := m.reloadingEnvironment.Get(environment.ID().ToString())
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -126,8 +126,8 @@ func (m *NomadRunnerManager) checkPrewarmingPoolAlert(environment ExecutionEnvir
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// With this hard lock we collect/block goroutines waiting for one reload to be done.
|
// With this hard lock, we collect/block goroutines waiting for one reload to be done.
|
||||||
// However, in practice its likely that only up to PrewarmingPoolSize/2 goroutines are waiting.
|
// However, in practice, it's likely that only up to PrewarmingPoolSize/2 goroutines are waiting.
|
||||||
// We could avoid the waiting, but we use it to solve the race conditions of the recursive call above.
|
// We could avoid the waiting, but we use it to solve the race conditions of the recursive call above.
|
||||||
data.Lock()
|
data.Lock()
|
||||||
defer data.Unlock()
|
defer data.Unlock()
|
||||||
@ -142,7 +142,7 @@ func (m *NomadRunnerManager) checkPrewarmingPoolAlert(environment ExecutionEnvir
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
data.cancel = cancel
|
data.cancel = cancel
|
||||||
|
|
||||||
log.WithField(dto.KeyEnvironmentID, environment.ID()).Info("Prewarming Pool Alert. Checking again..")
|
log.WithField(dto.KeyEnvironmentID, environment.ID()).Info("Prewarming Pool Alert. Checking again...")
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user