Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/plugin/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def get_data(

date_ranges = self._get_date_range(start)

include_credit = options.get("include_credit", True)

for date in date_ranges:
year, month = date.split("-")
path = f"SPACE_ONE/billing/database={database}/account_id={account_id}/year={year}/month={month}"
Expand All @@ -85,7 +87,7 @@ def get_data(
for content in contents:
response_stream = self.aws_s3_connector.get_cost_data(content["Key"])
for results in response_stream:
yield self._make_cost_data(results, account_id)
yield self._make_cost_data(results, account_id, include_credit)

yield {"results": []}

Expand All @@ -98,7 +100,7 @@ def _update_sync_state(self, options, secret_data, schema, service_account_id):
tags["is_sync"] = "true"
self.space_connector.update_service_account(service_account_id, tags)

def _make_cost_data(self, results, account_id):
def _make_cost_data(self, results, account_id, include_credit):
costs_data = []

""" Source Data Model
Expand All @@ -123,6 +125,10 @@ class CostSummaryItem(BaseModel):
region = result["region"] or "USE1"
service_code = result["service_code"]
usage_type = result["usage_type"]

if not include_credit and service_code == "Credit":
continue

data = {
"cost": result.get("usage_cost", 0.0) or 0.0,
"usage_quantity": result["usage_quantity"],
Expand Down
Loading