From d6fb5d680c010d572094a57bdefe3f4fe4f5492b Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 21 Feb 2022 13:45:47 +0100 Subject: [PATCH] Remove sentry integration It was introduced by #2159 because the various machines were hard to monitor. Since we moved to botmaster there is no longer a problem with that and if it ever served us is hard to say as the sentry project's password is lost for years. So simplify the exception handling by just throwing it --- ReviewBot.py | 19 +------- dist/package/openSUSE-release-tools.spec | 2 - obs_operator.py | 16 ------- osc-origin.py | 11 +---- osc-staging.py | 3 -- osclib/sentry.py | 60 ------------------------ 6 files changed, 3 insertions(+), 108 deletions(-) delete mode 100644 osclib/sentry.py diff --git a/ReviewBot.py b/ReviewBot.py index 69a0ad89..88ee7f22 100644 --- a/ReviewBot.py +++ b/ReviewBot.py @@ -18,7 +18,6 @@ from osclib.core import request_action_key from osclib.core import request_age from osclib.memoize import memoize from osclib.memoize import memoize_session_reset -from osclib.sentry import sentry_init from osclib.stagingapi import StagingAPI import signal import datetime @@ -32,9 +31,6 @@ from urllib.error import HTTPError, URLError from itertools import count -# In-case not properly initialized via the CommandLineInterface. -sentry_sdk = sentry_init() - class PackageLookup(object): """ helper class to manage 00Meta/lookup.yml @@ -186,8 +182,6 @@ class ReviewBot(object): for req in self.requests: self.logger.info("checking %s" % req.reqid) self.request = req - with sentry_sdk.configure_scope() as scope: - scope.set_extra('request.id', self.request.reqid) # XXX: this is a hack. Annotating the request with staging_project. # OBS itself should provide an API for that but that's currently not the case @@ -202,15 +196,13 @@ class ReviewBot(object): try: good = self.check_one_request(req) - except Exception as e: + except Exception: good = None import traceback traceback.print_exc() return_value = 1 - sentry_sdk.capture_exception(e) - if self.review_mode == 'no': good = None elif self.review_mode == 'accept': @@ -439,8 +431,6 @@ class ReviewBot(object): # Store in-case sub-classes need direct access to original values. self.action = a key = request_action_key(a) - with sentry_sdk.configure_scope() as scope: - scope.set_extra('action.key', key) override = self.request_override_check() if override is not None: @@ -897,11 +887,6 @@ class CommandLineInterface(cmdln.Cmdln): if self.options.fallback_group: self.checker.fallback_group = self.options.fallback_group - sentry_init(conf.config['apiurl'], { - 'review_bot': self.clazz.__name__, - 'review_user': self.checker.review_user, - }) - def setup_checker(self): """ reimplement this """ apiurl = conf.config['apiurl'] @@ -991,8 +976,6 @@ class CommandLineInterface(cmdln.Cmdln): self.logger.info("sleeping %d minutes." % interval) time.sleep(interval * 60) - sentry_sdk.flush() - # Reset all memoize session caches which are designed for single # tool run and not extended usage. memoize_session_reset() diff --git a/dist/package/openSUSE-release-tools.spec b/dist/package/openSUSE-release-tools.spec index 7d1ca9db..c7d37602 100644 --- a/dist/package/openSUSE-release-tools.spec +++ b/dist/package/openSUSE-release-tools.spec @@ -238,8 +238,6 @@ Group: Development/Tools/Other Requires: %{name} = %{version} Requires: osc >= 0.165.1 Requires: python3-osc -# internal API change related to accessing DSN in osclib/sentry.py -Suggests: python3-sentry-sdk >= 0.11.0 BuildArch: noarch %description -n osclib diff --git a/obs_operator.py b/obs_operator.py index 63dc3dd5..98e2c128 100755 --- a/obs_operator.py +++ b/obs_operator.py @@ -11,10 +11,7 @@ from socketserver import ThreadingMixIn import json import tempfile import os -from osc import conf from osclib import common -from osclib.sentry import sentry_client -from osclib.sentry import sentry_init import subprocess import sys import time @@ -27,15 +24,10 @@ from urllib.parse import parse_qs # https://stackoverflow.com/a/47012250, workaround by making EVERYTHING LEGAL! http.cookies._is_legal_key = lambda _: True -sentry_sdk = sentry_init() - -# Available in python 3.7. - class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): def handle_error(self, request, client_address): super().handle_error(request, client_address) - sentry_sdk.capture_exception() class RequestHandler(BaseHTTPRequestHandler): @@ -179,14 +171,9 @@ class RequestHandler(BaseHTTPRequestHandler): return None def oscrc_create(self, oscrc_file, apiurl, cookiejar_file, user): - sentry_dsn = sentry_client().dsn - sentry_environment = sentry_client().options.get('environment') oscrc_file.write('\n'.join([ '[general]', - # Passthru sentry_sdk options to allow for reporting on subcommands. - 'sentry_sdk.dsn = {}'.format(sentry_dsn) if sentry_dsn else '', - 'sentry_sdk.environment = {}'.format(sentry_environment) if sentry_environment else '', 'apiurl = {}'.format(apiurl), 'cookiejar = {}'.format(cookiejar_file.name), 'staging.color = 0', @@ -371,9 +358,6 @@ class OSCRequestEnvironmentException(Exception): def main(args): - conf.get_config() # Allow sentry DSN to be available. - sentry_init() - RequestHandler.apiurl = args.apiurl RequestHandler.session = args.session RequestHandler.debug = args.debug diff --git a/osc-origin.py b/osc-origin.py index 4022846a..1fb5adaf 100644 --- a/osc-origin.py +++ b/osc-origin.py @@ -25,7 +25,6 @@ from osclib.origin import origin_revision_state from osclib.origin import origin_updatable from osclib.origin import origin_updatable_initial from osclib.origin import origin_update -from osclib.sentry import sentry_init from osclib.util import mail_send from shutil import copyfile import sys @@ -101,14 +100,8 @@ def do_origin(self, subcmd, opts, *args): if not config: raise oscerr.WrongArgs('OSRT:OriginConfig attribute missing from {}'.format(opts.project)) - sentry_sdk = sentry_init(apiurl, {'osc_plugin': subcmd}) - try: - function = 'osrt_origin_{}'.format(command) - globals()[function](apiurl, opts, *args[1:]) - except Exception as e: - # Capture exception as osc.babysitter will consume any plugin exception. - sentry_sdk.capture_exception(e) - raise e + function = 'osrt_origin_{}'.format(command) + globals()[function](apiurl, opts, *args[1:]) def osrt_origin_config(apiurl, opts, *args): diff --git a/osc-staging.py b/osc-staging.py index 420b9e3c..d6b820c4 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -32,7 +32,6 @@ from osclib.unselect_command import UnselectCommand from osclib.repair_command import RepairCommand from osclib.rebuild_command import RebuildCommand from osclib.request_splitter import RequestSplitter -from osclib.sentry import sentry_init from osclib.supersede_command import SupersedeCommand from osclib.prio_command import PrioCommand @@ -392,8 +391,6 @@ def do_staging(self, subcmd, opts, *args): if value: setattr(Fore, name, ansi.code_to_chars(value)) - sentry_init(opts.apiurl, {'osc_plugin': subcmd}) - if opts.wipe_cache: Cache.delete_all() diff --git a/osclib/sentry.py b/osclib/sentry.py deleted file mode 100644 index 299f746d..00000000 --- a/osclib/sentry.py +++ /dev/null @@ -1,60 +0,0 @@ -from osc import conf -from osc import core -from osclib.common import VERSION - - -def sentry_init(obs_apiurl=None, tags=None): - try: - import sentry_sdk - except ImportError: - sentry_init.client = sentry_client_dummy() - return sentry_sdk_dummy() - - sentry_init.client = sentry_sdk.init( - conf.config.get('sentry_sdk.dsn'), - environment=conf.config.get('sentry_sdk.environment'), - release=VERSION) - - with sentry_sdk.configure_scope() as scope: - scope.set_tag('osc', core.__version__) - - if obs_apiurl: - scope.set_tag('obs_apiurl', obs_apiurl) - scope.user = {'username': conf.get_apiurl_usr(obs_apiurl)} - - if tags: - for key, value in tags.items(): - scope.set_tag(key, value) - - return sentry_sdk - - -def sentry_client(): - return sentry_init.client._client - - -class sentry_sdk_dummy: - def configure_scope(*args, **kw): - return nop_class() - - def __getattr__(self, _): - return nop_func - - -class nop_class: - def __enter__(self): - return nop_class() - - def __exit__(self, exc_type, exc_val, exc_tb): - pass - - def __getattr__(self, _): - return nop_func - - -class sentry_client_dummy(nop_class): - options = {} - - -def nop_func(*args, **kw): - pass