Skip to content

Commit d4b2497

Browse files
committed
when a boggus metrics data is received, return -1 so it's not retried to death
1 parent b2b1461 commit d4b2497

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/aleph/web/controllers/metrics.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass, asdict
88
from typing import Dict, Optional
99
from urllib.parse import urljoin
10+
from requests import HTTPError
1011

1112
import aiohttp
1213
from aiocache import cached
@@ -118,13 +119,16 @@ async def fetch_eth_height() -> Optional[int]:
118119
"""Obtain the height of the Ethereum blockchain."""
119120
LOGGER.debug("Fetching ETH height")
120121
config = app['config']
121-
122-
if config.ethereum.enabled.value:
123-
w3 = Web3(Web3.HTTPProvider(config.ethereum.api_url.value))
124-
return await asyncio.get_event_loop().run_in_executor(
125-
None, getattr, w3.eth, 'block_number')
126-
else:
127-
return None
122+
123+
try:
124+
if config.ethereum.enabled.value:
125+
w3 = Web3(Web3.HTTPProvider(config.ethereum.api_url.value))
126+
return await asyncio.get_event_loop().run_in_executor(
127+
None, getattr, w3.eth, 'block_number')
128+
else:
129+
return None
130+
except HTTPError:
131+
return -1 # We got a boggus value!
128132

129133

130134
async def get_metrics(shared_stats:dict) -> Metrics:

0 commit comments

Comments
 (0)