Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions bumiworker/bumiworker/modules/abandoned_base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,28 +58,28 @@ 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'
}
}
}
]
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:
resource_meter_value[res_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][
Expand All @@ -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
Expand Down
Loading