Fix false positives in Usage sanity checks of templates and network offerings (#8136)

Co-authored-by: João Jandre <48719461+JoaoJandre@users.noreply.github.com>
This commit is contained in:
Fabricio Duarte 2024-02-26 17:14:24 -03:00 committed by GitHub
parent 3baa45bc2a
commit d171582163
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -118,10 +118,19 @@ public class UsageSanityChecker {
}
int aggregationHours = aggregationRange / 60;
addCheckCase("SELECT count(*) FROM `cloud_usage`.`cloud_usage` cu where usage_type not in (4,5) and raw_usage > "
+ aggregationHours,
addCheckCase("SELECT count(*) FROM `cloud_usage`.`cloud_usage` cu where usage_type not in (4,5,13) and raw_usage > " + aggregationHours,
"usage records with raw_usage > " + aggregationHours,
lastCheckId);
addCheckCase("SELECT count(*) " +
" FROM ( SELECT cu.id, max(cu.raw_usage)/count(n.id) as avg_usage " +
" FROM `cloud_usage`.`cloud_usage` AS cu " +
" INNER JOIN cloud.nics AS n ON (n.instance_id = cu.vm_instance_id) " +
" WHERE cu.usage_type = 13 AND ((n.created <= cu.end_date) AND (n.removed is null OR n.removed > cu.start_date)) " +
" GROUP BY cu.id) as cu " +
" WHERE cu.avg_usage > " + aggregationHours,
"network offering usage records with raw_usage > " + aggregationHours,
lastCheckId);
}
private static int getAggregationRange(int aggregationRange, PreparedStatement pstmt) {
@ -175,8 +184,17 @@ public class UsageSanityChecker {
}
protected void checkTemplateISOUsage() {
addCheckCase("select count(*) from cloud_usage.cloud_usage cu inner join cloud.template_zone_ref tzr where "
+ "cu.usage_id = tzr.template_id and cu.zone_id = tzr.zone_id and cu.usage_type in (7,8) and cu.start_date > tzr.removed ",
addCheckCase("SELECT count(*) " +
" FROM cloud_usage.cloud_usage AS cu " +
" INNER JOIN cloud.template_zone_ref AS c_tzr ON ( c_tzr.template_id = cu.usage_id " +
" AND c_tzr.zone_id = cu.zone_id) " +
" WHERE cu.usage_type in (7,8) " +
" AND cu.start_date > c_tzr.removed " +
" AND NOT EXISTS ( SELECT 1 " +
" FROM cloud.template_zone_ref c_tzr_internal " +
" WHERE c_tzr_internal.template_id = c_tzr.template_id " +
" AND c_tzr_internal.zone_id = c_tzr.zone_id " +
" AND c_tzr_internal.removed IS NULL) ",
"template/ISO usage records which are created after it is removed",
lastCheckId);
}
@ -196,6 +214,7 @@ public class UsageSanityChecker {
String lastIdText = null;
lastId = -1;
if ((lastIdText = reader.readLine()) != null) {
LOGGER.info("Read {} as lastId for Usage sanity checking.", lastIdText);
lastId = Integer.parseInt(lastIdText);
}
} catch (Exception e) {
@ -214,7 +233,9 @@ public class UsageSanityChecker {
maxId = -1;
if (rs.next() && (rs.getInt(1) > 0)) {
maxId = rs.getInt(1);
LOGGER.info("Read {} as maxId for Usage sanity checking.", maxId);
if (maxId > lastId) {
LOGGER.info("The max id {} is greater than the last id {}; adding id check to the query.", maxId, lastId);
lastCheckId += " and cu.id <= ?";
}
}