Skip to content

Commit a32738c

Browse files
Prevent infinite autoscaling (#11244)
* Prevent infinite autoscaling * Update server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java Co-authored-by: Suresh Kumar Anaparti <[email protected]>
1 parent ca6d2dc commit a32738c

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ public interface AutoScaleVmGroupVmMapDao extends GenericDao<AutoScaleVmGroupVmM
3535
public boolean removeByVm(long vmId);
3636

3737
public boolean removeByGroup(long vmGroupId);
38+
39+
int getErroredInstanceCount(long vmGroupId);
3840
}

engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,13 @@ public boolean removeByGroup(long vmGroupId) {
115115
sc.setParameters("vmGroupId", vmGroupId);
116116
return remove(sc) >= 0;
117117
}
118+
119+
@Override
120+
public int getErroredInstanceCount(long vmGroupId) {
121+
SearchCriteria<Integer> sc = CountBy.create();
122+
sc.setParameters("vmGroupId", vmGroupId);
123+
sc.setJoinParameters("vmSearch", "states", State.Error);
124+
final List<Integer> results = customSearch(sc, null);
125+
return results.get(0);
126+
}
118127
}

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848

4949
import com.cloud.hypervisor.HypervisorGuru;
50+
import com.cloud.network.as.AutoScaleManager;
5051
import com.cloud.user.AccountManagerImpl;
5152
import com.cloud.utils.crypt.DBEncryptionUtil;
5253
import com.cloud.host.HostTagVO;
@@ -570,6 +571,7 @@ protected void populateConfigValuesForValidationSet() {
570571
configValuesForValidation.add(UserDataManager.VM_USERDATA_MAX_LENGTH_STRING);
571572
configValuesForValidation.add(UnmanagedVMsManager.RemoteKvmInstanceDisksCopyTimeout.key());
572573
configValuesForValidation.add(UnmanagedVMsManager.ConvertVmwareInstanceToKvmTimeout.key());
574+
configValuesForValidation.add(AutoScaleManager.AutoScaleErroredInstanceThreshold.key());
573575
}
574576

575577
private void weightBasedParametersForValidation() {

server/src/main/java/com/cloud/network/as/AutoScaleManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public interface AutoScaleManager extends AutoScaleService {
3838
"The Number of worker threads to scan the autoscale vm groups.",
3939
false);
4040

41+
ConfigKey<Integer> AutoScaleErroredInstanceThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class,
42+
"autoscale.errored.instance.threshold",
43+
"10",
44+
"The number of Error Instances allowed in autoscale vm groups for scale up.",
45+
true);
46+
4147
void checkAutoScaleUser(Long autoscaleUserId, long accountId);
4248

4349
boolean deleteAutoScaleVmGroupsByAccount(Long accountId);

server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,11 @@ private boolean checkConditionUp(AutoScaleVmGroupVO asGroup, Integer numVm) {
17161716
s_logger.warn("number of VM will greater than the maximum in this group if scaling up, so do nothing more");
17171717
return false;
17181718
}
1719+
int erroredInstanceCount = autoScaleVmGroupVmMapDao.getErroredInstanceCount(asGroup.getId());
1720+
if (erroredInstanceCount > AutoScaleManager.AutoScaleErroredInstanceThreshold.value()) {
1721+
s_logger.warn("Number of Errored Instances are greater than the threshold in this group for scaling up, so do nothing more");
1722+
return false;
1723+
}
17191724
return true;
17201725
}
17211726

@@ -2202,7 +2207,8 @@ public ConfigKey<?>[] getConfigKeys() {
22022207
return new ConfigKey<?>[] {
22032208
AutoScaleStatsInterval,
22042209
AutoScaleStatsCleanupDelay,
2205-
AutoScaleStatsWorker
2210+
AutoScaleStatsWorker,
2211+
AutoScaleErroredInstanceThreshold
22062212
};
22072213
}
22082214

0 commit comments

Comments
 (0)