Skip to content

Fix typo and add debug code for monitoring #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ local-conf.yml
.venv/
.venv.nosync/
.DS_Store
tmp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def __init__(self, *args, **kwargs):
)

def get_cost_data(self, bucket_name: str):
_LOGGER.debug(f"[get_cost_data] bucket name: {bucket_name}")

bucket = self.client.get_bucket(bucket_name)
blob_names = [blob.name for blob in bucket.list_blobs()]
Expand Down
20 changes: 17 additions & 3 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from dateutil.parser import parse
from spaceone.core.manager import BaseManager
from cloudforet.cost_analysis.error import *
Expand All @@ -7,7 +8,7 @@
GoogleStorageConnector,
)

_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger("spaceone")

_REQUIRED_FIELDS = ["cost", "currency", "billed_date"]

Expand All @@ -20,11 +21,18 @@ def __init__(self, *args, **kwargs):
self.type_mapper = None

def get_data(self, options, secret_data, schema, task_options):
start_time = time.time()
_LOGGER.debug(
f"[get_data] Start Collecting Cost Data (task_options={task_options})"
)

if "default_vars" in options:
self.default_vars = options["default_vars"]
_LOGGER.debug(f"[get_data] apply default vars: {self.default_vars}")

if "field_mapper" in options:
self.field_mapper = options["field_mapper"]
_LOGGER.debug(f"[get_data] apply field mapper: {self.field_mapper}")

if "type_mapper" in options:
self.type_mapper = options["type_mapper"]
Expand All @@ -41,20 +49,26 @@ def get_data(self, options, secret_data, schema, task_options):
GoogleStorageConnector, secret_data=secret_data
)
response_stream = storage_connector.get_cost_data(bucket_name)
_LOGGER.debug(f"[get_data] get cost data from {bucket_name} bucket")

for results in response_stream:
yield self._make_cost_data(results)

_LOGGER.debug(
f"[collector_collect] Finished Collecting Cost Data"
f"(duration: {time.time() - start_time:.2f}s)"
)

def _make_cost_data(self, results):
costs_data = []
for result in results:
result = self._apply_strip_to_dict_keys(result)
result = self._apply_strip_to_dict_values(result)

if self.default_vars:
if self.field_mapper:
result = self._change_result_by_field_mapper(result)

if self.field_mapper:
if self.default_vars:
self._set_default_vars(result)

if self.type_mapper:
Expand Down
Loading