Skip to content

Commit

Permalink
fix: fix buget bug
Browse files Browse the repository at this point in the history
  • Loading branch information
whdalsrnt committed Sep 11, 2023
1 parent 616b033 commit 21e65c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/spaceone/cost_analysis/manager/budget_usage_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def _update_monthly_budget_usage(self, budget_vo: Budget, cost_mgr: CostManager)
budget_usage_vos = self.budget_usage_model.filter(budget_id=budget_vo.budget_id)
for budget_usage_vo in budget_usage_vos:
if budget_usage_vo.date in update_data:
budget_usage_vo.update({'usd_cost': update_data[budget_usage_vo.date]})
budget_usage_vo.update({'cost': update_data[budget_usage_vo.date]})
else:
budget_usage_vo.update({'usd_cost': 0})
budget_usage_vo.update({'cost': 0})

def _make_cost_analyze_query(self, budget_vo: Budget):
query = {
Expand All @@ -125,6 +125,7 @@ def _make_cost_analyze_query(self, budget_vo: Budget):
},
'filter': [
{'k': 'domain_id', 'v': budget_vo.domain_id, 'o': 'eq'},
{'k': 'data_source_id', 'v': budget_vo.data_source_id, 'o': 'eq'},
]
}

Expand All @@ -142,7 +143,7 @@ def _make_cost_analyze_query(self, budget_vo: Budget):

query['filter'].append({'k': 'project_id', 'v': project_ids, 'o': 'in'})

if budget_vo.provider_filter.state == 'ENABLED':
if budget_vo.provider_filter and budget_vo.provider_filter.state == 'ENABLED':
query['filter'].append({'k': 'provider', 'v': budget_vo.provider_filter.providers, 'o': 'in'})

return query
7 changes: 5 additions & 2 deletions src/spaceone/cost_analysis/service/budget_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ def create(self, params):
if len(provider_filter.get('providers', [])) == 0:
raise ERROR_PROVIDER_FILTER_IS_EMPTY()
else:
params['provider_filter']['providers'] = []
params['provider_filter'] = {
'state': 'DISABLED',
'providers': []
}

data_source_mgr: DataSourceManager = self.locator.get_manager('DataSourceManager')
data_source_vo: DataSource = data_source_mgr.get_data_source(data_source_id, domain_id)
data_source_metadata = data_source_vo.plugin_info.get('metadata', {})
data_source_metadata = data_source_vo.plugin_info.metadata
params['currency'] = data_source_metadata['currency']

if time_unit == 'TOTAL':
Expand Down
3 changes: 2 additions & 1 deletion src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,13 @@ def _close_job(self, job_id, domain_id, data_source_id):
self.job_mgr.change_error_status(job_vo, e)
raise e

self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id)
self.cost_mgr.remove_stat_cache(domain_id, data_source_id)

if not no_preload_cache:
self.job_mgr.preload_cost_stat_queries(domain_id, data_source_id)

self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id)

self._update_last_sync_time(job_vo)
self.job_mgr.change_success_status(job_vo)

Expand Down

0 comments on commit 21e65c8

Please sign in to comment.