Skip to content

Commit 05cccd0

Browse files
authored
Merge pull request #49 from stat-kwon/master
Fix typo and add debug code for monitoring
2 parents 023faed + 201d742 commit 05cccd0

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ local-conf.yml
1212
.venv/
1313
.venv.nosync/
1414
.DS_Store
15+
tmp

src/cloudforet/cost_analysis/connector/google_storage_collector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __init__(self, *args, **kwargs):
3333
)
3434

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

3837
bucket = self.client.get_bucket(bucket_name)
3938
blob_names = [blob.name for blob in bucket.list_blobs()]

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23
from dateutil.parser import parse
34
from spaceone.core.manager import BaseManager
45
from cloudforet.cost_analysis.error import *
@@ -7,7 +8,7 @@
78
GoogleStorageConnector,
89
)
910

10-
_LOGGER = logging.getLogger(__name__)
11+
_LOGGER = logging.getLogger("spaceone")
1112

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

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

2223
def get_data(self, options, secret_data, schema, task_options):
24+
start_time = time.time()
25+
_LOGGER.debug(
26+
f"[get_data] Start Collecting Cost Data (task_options={task_options})"
27+
)
28+
2329
if "default_vars" in options:
2430
self.default_vars = options["default_vars"]
31+
_LOGGER.debug(f"[get_data] apply default vars: {self.default_vars}")
2532

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

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

4554
for results in response_stream:
4655
yield self._make_cost_data(results)
4756

57+
_LOGGER.debug(
58+
f"[collector_collect] Finished Collecting Cost Data"
59+
f"(duration: {time.time() - start_time:.2f}s)"
60+
)
61+
4862
def _make_cost_data(self, results):
4963
costs_data = []
5064
for result in results:
5165
result = self._apply_strip_to_dict_keys(result)
5266
result = self._apply_strip_to_dict_values(result)
5367

54-
if self.default_vars:
68+
if self.field_mapper:
5569
result = self._change_result_by_field_mapper(result)
5670

57-
if self.field_mapper:
71+
if self.default_vars:
5872
self._set_default_vars(result)
5973

6074
if self.type_mapper:

0 commit comments

Comments
 (0)