diff --git a/bumiworker/bumiworker/modules/abandoned_base.py b/bumiworker/bumiworker/modules/abandoned_base.py index 8650540b4..48fa01616 100644 --- a/bumiworker/bumiworker/modules/abandoned_base.py +++ b/bumiworker/bumiworker/modules/abandoned_base.py @@ -1,7 +1,7 @@ from collections import defaultdict from datetime import datetime, timedelta, timezone from bumiworker.bumiworker.modules.base import ( - LOG, ArchiveBase, ArchiveReason, ModuleBase, DAYS_IN_MONTH + ArchiveBase, ArchiveReason, ModuleBase, DAYS_IN_MONTH ) from tools.optscale_data.clickhouse import ExternalDataConverter from tools.optscale_time import utcnow, startday @@ -81,7 +81,6 @@ def _are_below_thresholds(res_data_request_map, metric_threshold_map): if all(data_request_map.get(key, 0) <= threshold_value for key, threshold_value in metric_threshold_map.items()): resource_ids.append(res_id) - LOG.debug(f'AB - Resources below thresholds: {resource_ids}') return resource_ids @staticmethod @@ -107,8 +106,6 @@ def _get(self): now = utcnow() start_date = now - timedelta(days=self.days_threshold) - LOG.debug(f'AB - Start date for abandoned buckets: {start_date}') - cloud_accounts = self.get_cloud_accounts(self.SUPPORTED_CLOUD_TYPES, self.skip_cloud_accounts) buckets_by_account = self.get_active_resources( @@ -163,8 +160,6 @@ def _get(self): self.metrics_result(data_req_map)) result.append(base_result_dict) - LOG.debug(f'AB - Abandoned buckets result: {result}') - return result diff --git a/bumiworker/bumiworker/modules/recommendations/s3_abandoned_buckets.py b/bumiworker/bumiworker/modules/recommendations/s3_abandoned_buckets.py index cb0544b02..9ae3a112e 100644 --- a/bumiworker/bumiworker/modules/recommendations/s3_abandoned_buckets.py +++ b/bumiworker/bumiworker/modules/recommendations/s3_abandoned_buckets.py @@ -30,7 +30,6 @@ def __init__(self, organization_id, config_client, created_at): def get_metric_threshold_map(self): # Buckets are considered abandoned if both GetObject and PutObject # operations are zero (no read or write activity) - LOG.debug(f'AB - GET_OBJECT_KEY: {GET_OBJECT_KEY}, PUT_OBJECT_KEY: {PUT_OBJECT_KEY}') return { GET_OBJECT_KEY: False, PUT_OBJECT_KEY: False @@ -59,8 +58,8 @@ def _get_data_size_request_metrics(self, cloud_account_id, '_id': '$resource_id', 'operation': '$lineItem/Operation' }, - 'total_usage': { - '$sum': '$lineItem/UsageAmount' + 'usage_amount': { + '$push': '$lineItem/UsageAmount' } } } @@ -68,7 +67,6 @@ def _get_data_size_request_metrics(self, cloud_account_id, api_requests = self.mongo_client.restapi.raw_expenses.aggregate( api_request_pipeline) api_requests_list = list(api_requests) - LOG.debug(f'AB - API Requests aggregation result: {api_requests_list}') resource_meter_value = {} # Initialize all resources with no recorded activity for res_id in cloud_resource_ids: @@ -76,11 +74,12 @@ def _get_data_size_request_metrics(self, cloud_account_id, GET_OBJECT_KEY: False, PUT_OBJECT_KEY: False } - # Aggregate operation usage (already summed by MongoDB) + # Aggregate operation usage by summing the pushed amounts for api_request in api_requests_list: cloud_resource_id = api_request['_id']['_id'] operation = api_request['_id']['operation'] - total_sum = int(api_request['total_usage']) + usage_amounts = api_request['usage_amount'] + total_sum = sum(float(amount) for amount in usage_amounts) if usage_amounts else 0 has_usage = bool(total_sum) if operation == 'GetObject': resource_meter_value[cloud_resource_id][ @@ -89,7 +88,6 @@ def _get_data_size_request_metrics(self, cloud_account_id, resource_meter_value[cloud_resource_id][ PUT_OBJECT_KEY] = has_usage - LOG.debug(f'AB - Resource meter values: {resource_meter_value}') return resource_meter_value @staticmethod