From 5fadd1724531be83fe28cc4f59b0ce3d92d2fd4a Mon Sep 17 00:00:00 2001 From: Luis Helder Date: Sun, 18 Aug 2024 23:04:43 -0300 Subject: [PATCH 1/3] fix: hathor-core healthcheck --- gateways/clients/hathor_core_client.py | 8 ++++++-- gateways/healthcheck_gateway.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gateways/clients/hathor_core_client.py b/gateways/clients/hathor_core_client.py index 762ca56d..21f62c77 100644 --- a/gateways/clients/hathor_core_client.py +++ b/gateways/clients/hathor_core_client.py @@ -43,7 +43,11 @@ def __init__(self, url: Optional[str] = None) -> None: self.log = logger.new(client="async") async def get( - self, path: str, params: Optional[dict] = None, timeout: Optional[float] = None + self, + path: str, + params: Optional[dict] = None, + timeout: Optional[float] = None, + content_type: Optional[str] = "application/json", ) -> Dict[Any, Any]: """Make a get request async @@ -71,7 +75,7 @@ async def get( status=response.status, body=await response.text(), ) - return await response.json() + return await response.json(content_type=content_type) except Exception as e: self.log.error("hathor_core_error", path=path, error=repr(e)) return {"error": repr(e)} diff --git a/gateways/healthcheck_gateway.py b/gateways/healthcheck_gateway.py index 2d8703af..f5922df0 100644 --- a/gateways/healthcheck_gateway.py +++ b/gateways/healthcheck_gateway.py @@ -36,7 +36,11 @@ async def get_hathor_core_health(self) -> Optional[dict]: """Retrieve hathor-core health information""" return await self.hathor_core_async_client.get( - HEALTH_ENDPOINT, timeout=HEALTHCHECK_CLIENT_TIMEOUT_IN_SECONDS + # XXX: We set the expected content_type to None because hathor-core was returning 'text/html' instead of 'application/json' + # This will be fixed in the next release of hathor-core (v0.63.0) + HEALTH_ENDPOINT, + timeout=HEALTHCHECK_CLIENT_TIMEOUT_IN_SECONDS, + content_type="text/html", ) def ping_redis(self) -> bool: From d31c02983251601825703deb40381efe413a54a0 Mon Sep 17 00:00:00 2001 From: Luis Helder Date: Sun, 18 Aug 2024 23:07:25 -0300 Subject: [PATCH 2/3] fix: use None instead --- gateways/healthcheck_gateway.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gateways/healthcheck_gateway.py b/gateways/healthcheck_gateway.py index f5922df0..dcb983de 100644 --- a/gateways/healthcheck_gateway.py +++ b/gateways/healthcheck_gateway.py @@ -38,9 +38,10 @@ async def get_hathor_core_health(self) -> Optional[dict]: return await self.hathor_core_async_client.get( # XXX: We set the expected content_type to None because hathor-core was returning 'text/html' instead of 'application/json' # This will be fixed in the next release of hathor-core (v0.63.0) + # None is better here to avoid having to sync the releases of hathor-core and explorer-service HEALTH_ENDPOINT, timeout=HEALTHCHECK_CLIENT_TIMEOUT_IN_SECONDS, - content_type="text/html", + content_type=None, ) def ping_redis(self) -> bool: From be8d3f55b4a5db20ce0753efedf0d14c43881e44 Mon Sep 17 00:00:00 2001 From: Luis Helder Date: Tue, 20 Aug 2024 13:29:32 -0300 Subject: [PATCH 3/3] fix: test --- tests/unit/gateways/test_healthcheck_gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/gateways/test_healthcheck_gateway.py b/tests/unit/gateways/test_healthcheck_gateway.py index 3adb31f5..c6b587c3 100644 --- a/tests/unit/gateways/test_healthcheck_gateway.py +++ b/tests/unit/gateways/test_healthcheck_gateway.py @@ -26,7 +26,7 @@ async def mock_get_hathor_core_health(endpoint, **kwargs): result = await self.healthcheck_gateway.get_hathor_core_health() self.assertEqual(result, {"status": "pass"}) self.hathor_core_async_client.get.assert_called_once_with( - "/v1a/health", timeout=5 + "/v1a/health", timeout=5, content_type=None ) def test_ping_redis(self):