From b6443a2b1fd914906ef2f8abe34ab410ac5b03f5 Mon Sep 17 00:00:00 2001 From: Oscar Sandoval Date: Fri, 12 May 2023 08:23:18 +0100 Subject: [PATCH] increase log detail for limit checking, fix getDomainReservation() (#7506) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In troubleshooting ops issues we see logs like: Maximum domain resource limits of Type 'user_vm' for Domain Id = 763 is exceeded: Domain Resource Limit = (1 bytes) 1, Current Domain Resource Amount = (0 bytes) 0, Requested Resource Amount = (1 bytes) 1." However there is one missing value (currentResourceReservation) that is used in the calculation of limit check but it is not logged, which leads to confusion. Above we see we are using “0” and requested 1, with our limit being 1, but was rejected. Without logging all the values used in the calculation we don’t understand why it failed. Additionally, if we had this log above it would be clearer that a second bug is occurring. When we query for domain level resource reservations in “getDomainReservation” the actual SearchBuilder is the listAccountAndTypeSearch, not the listDomainAndTypeSearch. As a result, when we call getDomainReservation the query returns any outstanding domain reservation for any account, as domain ID is not a valid filter for the account search. This PR: Increases detailed information in log for checking resource limit to include reservations information for functions: checkDomainResourceLimit() and checkAccountResourceLimit Fixes getDomainReservation() to use listDomainAndTypeSearch instead of listAccountAndTypeSearch Co-authored-by: Oscar Sandoval --- .../reservation/dao/ReservationDaoImpl.java | 2 +- .../ResourceLimitManagerImpl.java | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java index 2b8b74224f3..6703de0b13c 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java @@ -63,7 +63,7 @@ public class ReservationDaoImpl extends GenericDaoBase impl @Override public long getDomainReservation(Long domainId, Resource.ResourceType resourceType) { long total = 0; - SearchCriteria sc = listAccountAndTypeSearch.create(); + SearchCriteria sc = listDomainAndTypeSearch.create(); sc.setParameters(DOMAIN_ID, domainId); sc.setParameters(RESOURCE_TYPE, resourceType); List reservations = listBy(sc); diff --git a/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java index 27c44f4df2f..9efeed39ac0 100644 --- a/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java +++ b/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java @@ -433,8 +433,25 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim long currentDomainResourceCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type); long currentResourceReservation = reservationDao.getDomainReservation(domainId, type); long requestedDomainResourceCount = currentDomainResourceCount + currentResourceReservation + numResources; - String messageSuffix = " domain resource limits of Type '" + type + "'" + " for Domain Id = " + domainId + " is exceeded: Domain Resource Limit = " + toHumanReadableSize(domainResourceLimit) - + ", Current Domain Resource Amount = " + toHumanReadableSize(currentDomainResourceCount) + ", Requested Resource Amount = " + toHumanReadableSize(numResources) + "."; + + String convDomainResourceLimit = String.valueOf(domainResourceLimit); + String convCurrentDomainResourceCount = String.valueOf(currentDomainResourceCount); + String convCurrentResourceReservation = String.valueOf(currentResourceReservation); + String convNumResources = String.valueOf(numResources); + + if (type == ResourceType.secondary_storage || type == ResourceType.primary_storage){ + convDomainResourceLimit = toHumanReadableSize(domainResourceLimit); + convCurrentDomainResourceCount = toHumanReadableSize(currentDomainResourceCount); + convCurrentResourceReservation = toHumanReadableSize(currentResourceReservation); + convNumResources = toHumanReadableSize(numResources); + } + + String messageSuffix = String.format( + " domain resource limits of Type '%s' for Domain Id = %s is exceeded: Domain Resource Limit = %s, " + + "Current Domain Resource Amount = %s, Current Resource Reservation = %s, Requested Resource Amount = %s.", + type, domainId, convDomainResourceLimit, + convCurrentDomainResourceCount, convCurrentResourceReservation, convNumResources + ); if (s_logger.isDebugEnabled()) { s_logger.debug("Checking if" + messageSuffix); @@ -460,17 +477,22 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim String convertedAccountResourceLimit = String.valueOf(accountResourceLimit); String convertedCurrentResourceCount = String.valueOf(currentResourceCount); + String convertedCurrentResourceReservation = String.valueOf(currentResourceReservation); String convertedNumResources = String.valueOf(numResources); if (type == ResourceType.secondary_storage || type == ResourceType.primary_storage){ convertedAccountResourceLimit = toHumanReadableSize(accountResourceLimit); convertedCurrentResourceCount = toHumanReadableSize(currentResourceCount); + convertedCurrentResourceReservation = toHumanReadableSize(currentResourceReservation); convertedNumResources = toHumanReadableSize(numResources); } - String messageSuffix = " amount of resources of Type = '" + type + "' for " + (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName()) - + " in Domain Id = " + account.getDomainId() + " is exceeded: Account Resource Limit = " + convertedAccountResourceLimit + ", Current Account Resource Amount = " + convertedCurrentResourceCount - + ", Requested Resource Amount = " + convertedNumResources + "."; + String messageSuffix = String.format( + " amount of resources of Type = '%s' for %s in Domain Id = %s is exceeded: " + + "Account Resource Limit = %s, Current Account Resource Amount = %s, Current Account Resource Reservation = %s, Requested Resource Amount = %s.", + type, (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName()), account.getDomainId(), + convertedAccountResourceLimit, convertedCurrentResourceCount, convertedCurrentResourceReservation, convertedNumResources + ); if (s_logger.isDebugEnabled()) { s_logger.debug("Checking if" + messageSuffix);