From 44fb2bc8c70f3450cd870da291c0bd0202f7f17b Mon Sep 17 00:00:00 2001 From: kompotkot Date: Wed, 1 Sep 2021 13:41:31 +0000 Subject: [PATCH] Humbug reporter for moonstream python crawlers --- crawlers/mooncrawl/mooncrawl/__init__.py | 7 +++++++ crawlers/mooncrawl/mooncrawl/ethcrawler.py | 2 +- crawlers/mooncrawl/mooncrawl/reporter.py | 18 ++++++++++++++++++ crawlers/mooncrawl/mooncrawl/settings.py | 6 +++++- crawlers/mooncrawl/sample.env | 1 + crawlers/mooncrawl/setup.py | 1 + 6 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 crawlers/mooncrawl/mooncrawl/reporter.py diff --git a/crawlers/mooncrawl/mooncrawl/__init__.py b/crawlers/mooncrawl/mooncrawl/__init__.py index e69de29b..9548e297 100644 --- a/crawlers/mooncrawl/mooncrawl/__init__.py +++ b/crawlers/mooncrawl/mooncrawl/__init__.py @@ -0,0 +1,7 @@ +from .reporter import reporter +from .version import MOONCRAWL_VERSION + +# Reporting +reporter.tags.append(f"version:{MOONCRAWL_VERSION}") +reporter.system_report(publish=True) +reporter.setup_excepthook(publish=True) diff --git a/crawlers/mooncrawl/mooncrawl/ethcrawler.py b/crawlers/mooncrawl/mooncrawl/ethcrawler.py index 793ab3ea..5e9275c4 100644 --- a/crawlers/mooncrawl/mooncrawl/ethcrawler.py +++ b/crawlers/mooncrawl/mooncrawl/ethcrawler.py @@ -48,7 +48,7 @@ def yield_blocks_numbers_lists( print( "Wrong format provided, expected {bottom_block}-{top_block}, as ex. 105-340" ) - return + raise Exception starting_block = max(input_start_block, input_end_block) ending_block = min(input_start_block, input_end_block) diff --git a/crawlers/mooncrawl/mooncrawl/reporter.py b/crawlers/mooncrawl/mooncrawl/reporter.py new file mode 100644 index 00000000..96f3de4a --- /dev/null +++ b/crawlers/mooncrawl/mooncrawl/reporter.py @@ -0,0 +1,18 @@ +import uuid + +from humbug.consent import HumbugConsent +from humbug.report import HumbugReporter + +from .settings import HUMBUG_REPORTER_CRAWLERS_TOKEN + +session_id = str(uuid.uuid4()) +client_id = "moonstream-crawlers" + +reporter = HumbugReporter( + name="moonstream", + consent=HumbugConsent(True), + client_id=client_id, + session_id=session_id, + bugout_token=HUMBUG_REPORTER_CRAWLERS_TOKEN, + tags=[], +) diff --git a/crawlers/mooncrawl/mooncrawl/settings.py b/crawlers/mooncrawl/mooncrawl/settings.py index 82b13772..307f2e8a 100644 --- a/crawlers/mooncrawl/mooncrawl/settings.py +++ b/crawlers/mooncrawl/mooncrawl/settings.py @@ -1,5 +1,9 @@ import os +# Bugout +HUMBUG_REPORTER_CRAWLERS_TOKEN = os.environ.get("HUMBUG_REPORTER_CRAWLERS_TOKEN") + +# Geth MOONSTREAM_IPC_PATH = os.environ.get("MOONSTREAM_IPC_PATH", None) MOONSTREAM_CRAWL_WORKERS = 4 @@ -12,5 +16,5 @@ except: f"Could not parse MOONSTREAM_CRAWL_WORKERS as int: {MOONSTREAM_CRAWL_WORKERS_RAW}" ) - +# Etherscan MOONSTREAM_ETHERSCAN_TOKEN = os.environ.get("MOONSTREAM_ETHERSCAN_TOKEN") diff --git a/crawlers/mooncrawl/sample.env b/crawlers/mooncrawl/sample.env index 5ebad6e0..5d4ac548 100644 --- a/crawlers/mooncrawl/sample.env +++ b/crawlers/mooncrawl/sample.env @@ -6,3 +6,4 @@ export MOONSTREAM_ETHERSCAN_TOKEN="" export AWS_S3_SMARTCONTRACT_BUCKET="" export MOONSTREAM_HUMBUG_TOKEN="" export COINMARKETCAP_API_KEY="" +export HUMBUG_REPORTER_CRAWLERS_TOKEN="" diff --git a/crawlers/mooncrawl/setup.py b/crawlers/mooncrawl/setup.py index 1e893bd4..46b397a3 100644 --- a/crawlers/mooncrawl/setup.py +++ b/crawlers/mooncrawl/setup.py @@ -34,6 +34,7 @@ setup( zip_safe=False, install_requires=[ "moonstreamdb @ git+https://git@github.com/bugout-dev/moonstream.git@39d2b8e36a49958a9ae085ec2cc1be3fc732b9d0#egg=moonstreamdb&subdirectory=db", + "humbug", "python-dateutil", "requests", "tqdm",