From f07eb8de87db498fccf7bd6baa66f7613a925752 Mon Sep 17 00:00:00 2001 From: animuk Date: Mon, 11 Feb 2019 17:43:30 +0530 Subject: [PATCH] Sentry Integration in Release Monitor --- openshift/template.yaml | 11 +++++++++++ release_monitor/release_monitor.py | 17 ++++++++++++----- requirements.txt | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/openshift/template.yaml b/openshift/template.yaml index 2734e8e..f9f6cfd 100644 --- a/openshift/template.yaml +++ b/openshift/template.yaml @@ -51,6 +51,11 @@ objects: secretKeyRef: name: aws key: s3-secret-access-key + - name: SENTRY_DSN + valueFrom: + secretKeyRef: + name: worker + key: sentry_dsn # this won't get used if running with SQS - name: RABBITMQ_SERVICE_SERVICE_HOST value: bayesian-broker @@ -175,3 +180,9 @@ parameters: required: true name: DEBUG value: "False" + +- description: Sentry DSN + displayName: Sentry DSN + required: false + name: SENTRY_DSN + value: "" diff --git a/release_monitor/release_monitor.py b/release_monitor/release_monitor.py index 0f08201..58fd42f 100644 --- a/release_monitor/release_monitor.py +++ b/release_monitor/release_monitor.py @@ -21,6 +21,7 @@ from f8a_worker.setup_celery import init_celery, init_selinon from f8a_worker.utils import normalize_package_name from selinon import run_flow +import sentry_sdk # local imports: from release_monitor.defaults import NPM_URL, PYPI_URL, ENABLE_SCHEDULING, SLEEP_INTERVAL @@ -39,6 +40,7 @@ def set_up_logger(): logger = set_up_logger() +sentry_sdk.init(os.environ.get("SENTRY_DSN")) class Package: @@ -113,11 +115,13 @@ def create_package_from_pypi_dict(dict): list_of_pypi_updates = feedparser.parse(self.pypi_url + "rss/updates.xml").entries try: updated_packages = set(map(create_package_from_pypi_dict, list_of_pypi_updates)) - except KeyError: + except KeyError as e: # if the "title" does not exist, catch the error and return nothing + logger.error('Titles does not exist : {e}'.format(e=str(e))) return set() - except IndexError: + except IndexError as e: # if the "title" does not contain name and version, catch the error and return nothing + logger.error('name and version does not exist : {e}'.format(e=str(e))) return set() return updated_packages @@ -138,7 +142,8 @@ def fetch_pkg_names_from_feed(self): try: r = set(map(lambda x: x['title'], npm_feed.entries)) return r - except KeyError: + except KeyError as e: + logger.error('npm package key not found : {e}'.format(e=str(e))) return None @staticmethod @@ -151,11 +156,13 @@ def fetch_latest_package_version(package): if req.status_code == 200: body = req.json() return body['latest'] - except ValueError: + except ValueError as e: # The body was not a valid JSON + logger.error('valid JSON key not found : {e}'.format(e=str(e))) return None - except KeyError: + except KeyError as e: # The body was a valid JSON, but it did not contain version field + logger.error('version key not found : {e}'.format(e=str(e))) return None def fetch_feed(self): diff --git a/requirements.txt b/requirements.txt index 839d8c6..8f37f72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ psutil==5.4.8 requests==2.21.0 typing==3.6.6 urllib3==1.24.1 # via requests +sentry-sdk==0.7.2 \ No newline at end of file