Skip to content

Commit

Permalink
chore: remove debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMin5 committed Jan 16, 2024
1 parent deb2c15 commit e187b0a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/spaceone/cost_analysis/manager/budget_usage_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.budget_mgr: BudgetManager = self.locator.get_manager("BudgetManager")
self.budget_usage_model: BudgetUsage = self.locator.get_model("BudgetUsage")
self.identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
self.notification_mgr: NotificationManager = self.locator.get_manager(
"NotificationManager"
)
Expand Down Expand Up @@ -218,10 +217,11 @@ def _notify_message(
data_source_name = self.data_source_mgr.get_data_source(
budget_vo.data_source_id, budget_vo.domain_id
).name
project_name = self.identity_mgr.get_project_name(
identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
project_name = identity_mgr.get_project_name(
budget_vo.project_id, budget_vo.workspace_id, budget_vo.domain_id
)
workspace_name = self.identity_mgr.get_workspace(
workspace_name = identity_mgr.get_workspace(
budget_vo.workspace_id, budget_vo.domain_id
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self, *args, **kwargs):
self.data_source_rule_model: DataSourceRule = self.locator.get_model(
"DataSourceRule"
)
self.identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
self._project_info = {}
self._service_account_info = {}
self._data_source_rule_info = {}
Expand Down Expand Up @@ -177,7 +176,8 @@ def _get_service_account(self, target_key, target_value, domain_id):
"only": ["service_account_id", "project_id", "workspace_id"],
}

response = self.identity_mgr.list_service_accounts(query, domain_id)
identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
response = identity_mgr.list_service_accounts(query, domain_id)
results = response.get("results", [])
total_count = response.get("total_count", 0)

Expand All @@ -201,7 +201,8 @@ def _get_project(self, target_key, target_value, domain_id):
"only": ["project_id"],
}

response = self.identity_mgr.list_projects({"query": query}, domain_id)
identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
response = identity_mgr.list_projects({"query": query}, domain_id)
results = response.get("results", [])
total_count = response.get("total_count", 0)

Expand Down
1 change: 0 additions & 1 deletion src/spaceone/cost_analysis/manager/identity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
token = self.transaction.get_meta("token")
self.token_type = JWTUtil.get_value_from_token(token, "typ")
_LOGGER.debug(f"[IdentityManager] token: {token}")
self.identity_conn: SpaceConnector = self.locator.get_connector(
SpaceConnector, service="identity"
)
Expand Down
7 changes: 2 additions & 5 deletions src/spaceone/cost_analysis/service/data_source_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __init__(self, *args, **kwargs):
self.cost_mgr = CostManager()
self.budget_usage_mgr = BudgetUsageManager()
self.job_mgr = JobManager()
self.identity_mgr = IdentityManager()

@transaction(
permission="cost-analysis:DataSource.write",
Expand Down Expand Up @@ -378,9 +377,7 @@ def deregister(self, params):

if cascade_delete_cost:
self.cost_mgr.delete_cost_with_datasource(domain_id, data_source_id)
self.budget_usage_mgr.update_budget_usage(
domain_id, data_source_id
)
self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id)
self.cost_mgr.remove_stat_cache(domain_id, data_source_id)
self.job_mgr.preload_cost_stat_queries(domain_id, data_source_id)

Expand Down Expand Up @@ -552,7 +549,7 @@ def validate_secret_filter(self, secret_filter, domain_id):
}
]
}
identity_mgr: IdentityManager = self.locator.get_manager(IdentityManager)
identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
response = identity_mgr.list_service_accounts(_query, domain_id)
if response.get("total_count", 0) != len(secret_filter["service_accounts"]):
raise ERROR_INVALID_PARAMETER(
Expand Down
71 changes: 26 additions & 45 deletions src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ def get_cost_data(self, params):
None
"""

print(self.transaction.meta)
print(self.transaction.get_meta("token"))
task_options = params["task_options"]
job_task_id = params["job_task_id"]
secret_id = params["secret_id"]
Expand Down Expand Up @@ -225,13 +223,7 @@ def get_cost_data(self, params):
secret_type = data_source_vo.secret_type
options.update({"secret_type": secret_type})

_LOGGER.debug(
f"[get_cost_data] token1: {self.transaction.get_meta('token')}"
)
secret_data = self._get_secret_data(secret_id, domain_id)
_LOGGER.debug(
f"[get_cost_data] token2: {self.transaction.get_meta('token')}"
)

if secret_type == "USE_SERVICE_ACCOUNT_SECRET":
(
Expand All @@ -253,32 +245,21 @@ def get_cost_data(self, params):
) = self.ds_plugin_mgr.get_data_source_plugin_endpoint(
plugin_info, domain_id
)
_LOGGER.debug(
f"[get_cost_data] token3: {self.transaction.get_meta('token')}"
)

self.ds_plugin_mgr.initialize(endpoint)
_LOGGER.debug(
f"[get_cost_data] token4: {self.transaction.get_meta('token')}"
)
start_dt = datetime.utcnow()

count = 0
is_canceled = False
_LOGGER.debug(f"[get_cost_data] start job ({job_task_id}): {start_dt}")

for costs_data in self.ds_plugin_mgr.get_cost_data(
options, secret_data, schema, task_options, domain_id
options, secret_data, schema, task_options, domain_id
):
_LOGGER.debug(
f"[get_cost_data] token5: {self.transaction.get_meta('token')}"
)
results = costs_data.get("results", [])
for cost_data in results:
count += 1

self._check_cost_data(cost_data)
_LOGGER.debug(
f"[get_cost_data] token6: {self.transaction.get_meta('token')}"
)
self._create_cost_data(
cost_data, job_task_vo, cost_data_options
)
Expand Down Expand Up @@ -427,11 +408,11 @@ def create_cost_job(self, data_source_vo: DataSource, job_options):
return job_vo

def _list_secret_ids_from_secret_type(
self,
data_source_vo: DataSource,
secret_type: str,
workspace_id: str,
domain_id: str,
self,
data_source_vo: DataSource,
secret_type: str,
workspace_id: str,
domain_id: str,
):
secret_ids = []

Expand All @@ -452,7 +433,7 @@ def _list_secret_ids_from_secret_type(
return secret_ids

def _list_secret_ids_from_secret_filter(
self, secret_filter, provider: str, workspace_id: str, domain_id: str
self, secret_filter, provider: str, workspace_id: str, domain_id: str
):
secret_manager: SecretManager = self.locator.get_manager(SecretManager)

Expand All @@ -467,7 +448,7 @@ def _list_secret_ids_from_secret_filter(

@staticmethod
def _set_secret_filter(
secret_filter, provider: str, workspace_id: str, domain_id: str
secret_filter, provider: str, workspace_id: str, domain_id: str
):
_filter = [{"k": "domain_id", "v": domain_id, "o": "eq"}]

Expand All @@ -482,8 +463,8 @@ def _set_secret_filter(
{"k": "secret_id", "v": secret_filter["secrets"], "o": "in"}
)
if (
"service_accounts" in secret_filter
and secret_filter["service_accounts"]
"service_accounts" in secret_filter
and secret_filter["service_accounts"]
):
_filter.append(
{
Expand Down Expand Up @@ -579,10 +560,10 @@ def _create_cost_data(self, cost_data, job_task_vo, cost_options):
self.cost_mgr.create_cost(cost_data, execute_rollback=False)

def _is_job_failed(
self,
job_id: str,
domain_id: str,
workspace_id: str,
self,
job_id: str,
domain_id: str,
workspace_id: str,
):
job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id)

Expand All @@ -592,7 +573,7 @@ def _is_job_failed(
return False

def _close_job(
self, job_id: str, data_source_id: str, domain_id: str, workspace_id: str = None
self, job_id: str, data_source_id: str, domain_id: str, workspace_id: str = None
) -> None:
job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id)
no_preload_cache = job_vo.options.get("no_preload_cache", False)
Expand Down Expand Up @@ -780,7 +761,7 @@ def _aggregate_cost_data(self, job_vo: Job):

for job_task_id in job_task_ids:
for billed_month in self._distinct_billed_month(
data_source_id, domain_id, job_id, job_task_id
data_source_id, domain_id, job_id, job_task_id
):
self._aggregate_monthly_cost_data(
data_source_id,
Expand Down Expand Up @@ -811,13 +792,13 @@ def _distinct_billed_month(self, data_source_id, domain_id, job_id, job_task_id)
return values

def _aggregate_monthly_cost_data(
self,
data_source_id,
domain_id,
job_id,
job_task_id,
billed_month,
workspace_id: str = None,
self,
data_source_id,
domain_id,
job_id,
job_task_id,
billed_month,
workspace_id: str = None,
):
query = {
"group_by": [
Expand Down Expand Up @@ -872,7 +853,7 @@ def _get_all_data_sources(self):
)

def _check_duplicate_job(
self, data_source_id: str, domain_id: str, this_job_vo: Job
self, data_source_id: str, domain_id: str, this_job_vo: Job
):
query = {
"filter": [
Expand Down

0 comments on commit e187b0a

Please sign in to comment.