Skip to content

Commit

Permalink
improved logs (#355)
Browse files Browse the repository at this point in the history
* improved logs

* improved logs

* Update error log with payload
  • Loading branch information
daminichopra committed Sep 18, 2020
1 parent 098e3e5 commit cafca9c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/geocoding/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GeoCodingEnvReader:
"""

def __init__(self):
self.env = EnvReader(log=logging.getLogger(__name__).info)
self.env = EnvReader(log=logging.getLogger(__name__).debug)

def use_geocoding(self) -> bool:
return self.env.read(BoolVar('USE_GEOCODING', False))
Expand Down Expand Up @@ -62,9 +62,9 @@ def get_geo_cache() -> MaybeGeoCache:
"""
env = GeoCodingEnvReader()
if is_geo_coding_available():
log().info("Geo Cache env variables set, building a cache.")
log().debug("Geo Cache env variables set, building a cache.")

return GeoCodingCache(env.redis_host(), env.redis_port())

log().info("Geo Cache env variables indicate cache should not be used.")
log().debug("Geo Cache env variables indicate cache should not be used.")
return None
6 changes: 3 additions & 3 deletions src/reporter/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ def notify():
e_new = _filter_no_type_no_value_entities(e)
res_entity.append(e_new)
payload = res_entity

entity_id = [i["id"] for i in payload]
# Send valid entities to translator
try:
with translator_for(fiware_s) as trans:
trans.insert(payload, fiware_s, fiware_sp)
except:
msg = "Notification not processed or not updated"
msg = "Notification not processed or not updated for payload: %s" % (payload)
log().error(msg)
return msg, 500
msg = 'Notification successfully processed'
msg = "Notification successfully processed for : 'tenant' %s, 'fiwareServicePath' %s, 'entity_id' %s" % (fiware_s, fiware_sp, entity_id)
log().info(msg)
return msg

Expand Down
4 changes: 2 additions & 2 deletions src/reporter/tests/test_Headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_for_valid_headers(notification):
headers=HEADERS_VALID)
time.sleep(1)
assert res_post.status_code == 200
assert res_post.json() == 'Notification successfully processed'
assert res_post.json().startswith('Notification successfully processed')

get_url = "{}/entities/Room0".format(QL_URL)
res_get = requests.get(get_url, headers=HEADERS_VALID)
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_for_invalid_headers(notification):
headers=HEADERS_VALID)

assert res_post.status_code == 200
assert res_post.json() == 'Notification successfully processed'
assert res_post.json().startswith('Notification successfully processed')

get_url = "{}/entities/Room0".format(QL_URL)
res_get = requests.get(get_url, headers=HEADERS_INVALID)
Expand Down
13 changes: 6 additions & 7 deletions src/reporter/tests/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ def test_valid_notification(notification, clean_mongo, clean_crate):
r = requests.post('{}'.format(notify_url),
data=json.dumps(notification),
headers=HEADERS_PUT)

assert r.status_code == 200
assert r.json() == 'Notification successfully processed'
assert r.json().startswith('Notification successfully processed')


def test_valid_no_modified(notification, clean_mongo, clean_crate):
Expand All @@ -87,7 +86,7 @@ def test_valid_no_modified(notification, clean_mongo, clean_crate):
data=json.dumps(notification),
headers=HEADERS_PUT)
assert r.status_code == 200
assert r.json() == 'Notification successfully processed'
assert r.json().startswith('Notification successfully processed')

def do_integration(entity, notify_url, orion_client, crate_translator):
entity_id = entity['id']
Expand Down Expand Up @@ -220,7 +219,7 @@ def test_multiple_data_elements(notification, sameEntityWithDifferentAttrs, clea
r = requests.post('{}'.format(notify_url), data=json.dumps(notification),
headers=HEADERS_PUT)
assert r.status_code == 200
assert r.json() == 'Notification successfully processed'
assert r.json().startswith('Notification successfully processed')


def test_time_index(notification, clean_mongo, crate_translator):
Expand All @@ -236,7 +235,7 @@ def test_time_index(notification, clean_mongo, crate_translator):
data=json.dumps(notification),
headers=HEADERS_PUT)
assert r.status_code == 200
assert r.json() == 'Notification successfully processed'
assert r.json().startswith('Notification successfully processed')

time.sleep(1)
entity_type = notification['data'][0]['type']
Expand All @@ -261,7 +260,7 @@ def test_time_index(notification, clean_mongo, crate_translator):
data=json.dumps(notification),
headers=HEADERS_PUT)
assert r.status_code == 200
assert r.json() == 'Notification successfully processed'
assert r.json().startswith('Notification successfully processed')

time.sleep(1)
crate_translator._refresh([entity_type])
Expand All @@ -278,7 +277,7 @@ def test_time_index(notification, clean_mongo, crate_translator):
data=json.dumps(notification),
headers=HEADERS_PUT)
assert r.status_code == 200
assert r.json() == 'Notification successfully processed'
assert r.json().startswith('Notification successfully processed')

time.sleep(1)
crate_translator._refresh([entity_type])
Expand Down
4 changes: 2 additions & 2 deletions src/translators/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def log():

def lookup_backend(fiware_service: str) -> MaybeString:
cfg_reader = YamlReader(log=log().debug)
env_reader = EnvReader(log=log().info)
env_reader = EnvReader(log=log().debug)

config = cfg_reader.from_env_file(QL_CONFIG_ENV_VAR, defaults={})
tenant_backend = maybe_string_match(config, 'tenants', fiware_service,
Expand All @@ -45,6 +45,6 @@ def translator_for(fiware_service: str):
translator = CrateTranslatorInstance()
selected = CRATE_BACKEND

log().info(
log().debug(
f"Backend selected for tenant '{fiware_service}' is: {selected}")
return translator
7 changes: 5 additions & 2 deletions src/translators/sql_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def _insert_entities_of_type(self,

col = self._ea2cn(attr)
original_attrs[col] = (attr, attr_t)
entity_id = e.get('id')

if attr_t not in self.NGSI_TO_SQL:
# if attribute is complex assume it as an NGSI StructuredValue
Expand All @@ -249,11 +250,13 @@ def _insert_entities_of_type(self,
else:
# TODO fallback type should be defined by actual JSON type
supported_types = ', '.join(self.NGSI_TO_SQL.keys())
msg = ("'{}' is not a supported NGSI type. "
msg = ("'{}' is not a supported NGSI type"
" for Attribute: '{}' "
" and id : '{}'. "
"Please use any of the following: {}. "
"Falling back to {}.")
self.logger.warning(msg.format(
attr_t, supported_types, NGSI_TEXT))
attr_t, attr, entity_id, supported_types, NGSI_TEXT))

table[col] = self.NGSI_TO_SQL[NGSI_TEXT]

Expand Down

0 comments on commit cafca9c

Please sign in to comment.