Handle timeout error in monitoring requests
@@ -38,7 +38,7 @@ class Monitor(object):
_logger = None
def __init__(self):
- self._logger = logger.setup(__name__)
+ self._logger = logger.setup(__name__, level=20)
self._monitor_loop_task = None # type: asyncio.Task
"""Task for :meth:`_monitor_loop`, to ensure it has finished"""
@@ -94,21 +94,19 @@ class Monitor(object):
text = await resp.text()
res = json.loads(text)
if res["uptime"] is None:
- raise ValueError('Improper Response')
- except ValueError:
+ raise ValueError('res.uptime is None')
+ except aiohttp.client_exceptions.ClientError as ex:
service_record._status = ServiceRecord.Status.Unresponsive
check_count[service_record._id] += 1
- self._logger.info("Marked as doubtful micro-service %s", service_record.__repr__())
- except Exception as ex: # TODO: Fix too broad exception clause
- # Fixme: Investigate as why no exception message can appear,
- # e.g. FogLAMP[423] INFO: monitor: foglamp.services.core.service_registry.monitor: Exception occurred
- # during monitoring:
-
- if "" != str(ex).strip(): # i.e. if a genuine exception occurred
- self._logger.info("Exception occurred during monitoring: %s", str(ex))
+ self._logger.info("ClientError: %s, %s", str(ex), service_record.__repr__())
+ except ValueError as ex:
service_record._status = ServiceRecord.Status.Unresponsive
check_count[service_record._id] += 1
- self._logger.info("Marked as unresponsive micro-service %s", service_record.__repr__())
+ self._logger.info("Invalid response: %s, %s", str(ex), service_record.__repr__())
+ except Exception as ex:
+ service_record._status = ServiceRecord.Status.Unresponsive
+ check_count[service_record._id] += 1
+ self._logger.info("Exception occurred: %s, %s", str(ex), service_record.__repr__())
else:
service_record._status = ServiceRecord.Status.Running
check_count[service_record._id] = 1
