Skip to content

Commit 4e8ee82

Browse files
sudo87sureshanaparti
authored andcommitted
Prevent infinite autoscaling (apache#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 fc3c42b commit 4e8ee82

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-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
@@ -37,4 +37,6 @@ public interface AutoScaleVmGroupVmMapDao extends GenericDao<AutoScaleVmGroupVmM
3737
public boolean removeByGroup(long vmGroupId);
3838

3939
int expungeByVmList(List<Long> vmIds, Long batchSize);
40+
41+
int getErroredInstanceCount(long vmGroupId);
4042
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,12 @@ public int expungeByVmList(List<Long> vmIds, Long batchSize) {
127127
sc.setParameters("vmIds", vmIds.toArray());
128128
return batchExpunge(sc, batchSize);
129129
}
130+
131+
public int getErroredInstanceCount(long vmGroupId) {
132+
SearchCriteria<Integer> sc = CountBy.create();
133+
sc.setParameters("vmGroupId", vmGroupId);
134+
sc.setJoinParameters("vmSearch", "states", State.Error);
135+
final List<Integer> results = customSearch(sc, null);
136+
return results.get(0);
137+
}
130138
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import javax.naming.ConfigurationException;
5252

5353
import com.cloud.hypervisor.HypervisorGuru;
54+
import com.cloud.network.as.AutoScaleManager;
5455
import com.cloud.user.AccountManagerImpl;
5556
import com.cloud.utils.crypt.DBEncryptionUtil;
5657
import com.cloud.host.HostTagVO;
@@ -619,6 +620,7 @@ protected void populateConfigValuesForValidationSet() {
619620
configValuesForValidation.add(VMLeaseManager.InstanceLeaseSchedulerInterval.key());
620621
configValuesForValidation.add(VMLeaseManager.InstanceLeaseExpiryEventSchedulerInterval.key());
621622
configValuesForValidation.add(VMLeaseManager.InstanceLeaseExpiryEventDaysBefore.key());
623+
configValuesForValidation.add(AutoScaleManager.AutoScaleErroredInstanceThreshold.key());
622624
}
623625

624626
protected 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
@@ -39,6 +39,12 @@ public interface AutoScaleManager extends AutoScaleService {
3939
"The Number of worker threads to scan the autoscale vm groups.",
4040
false);
4141

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

4450
boolean deleteAutoScaleVmGroupsByAccount(Account account);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,11 @@ private boolean checkConditionUp(AutoScaleVmGroupVO asGroup, Integer numVm) {
17221722
logger.warn("number of VM will greater than the maximum in this group if scaling up, so do nothing more");
17231723
return false;
17241724
}
1725+
int erroredInstanceCount = autoScaleVmGroupVmMapDao.getErroredInstanceCount(asGroup.getId());
1726+
if (erroredInstanceCount > AutoScaleManager.AutoScaleErroredInstanceThreshold.value()) {
1727+
s_logger.warn("Number of Errored Instances are greater than the threshold in this group for scaling up, so do nothing more");
1728+
return false;
1729+
}
17251730
return true;
17261731
}
17271732

@@ -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)