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
This commit is contained in:
Stephan Kulow 2022-02-21 13:45:47 +01:00
parent 3e14e55fde
commit d6fb5d680c
6 changed files with 3 additions and 108 deletions

View File

@ -18,7 +18,6 @@ from osclib.core import request_action_key
from osclib.core import request_age from osclib.core import request_age
from osclib.memoize import memoize from osclib.memoize import memoize
from osclib.memoize import memoize_session_reset from osclib.memoize import memoize_session_reset
from osclib.sentry import sentry_init
from osclib.stagingapi import StagingAPI from osclib.stagingapi import StagingAPI
import signal import signal
import datetime import datetime
@ -32,9 +31,6 @@ from urllib.error import HTTPError, URLError
from itertools import count from itertools import count
# In-case not properly initialized via the CommandLineInterface.
sentry_sdk = sentry_init()
class PackageLookup(object): class PackageLookup(object):
""" helper class to manage 00Meta/lookup.yml """ helper class to manage 00Meta/lookup.yml
@ -186,8 +182,6 @@ class ReviewBot(object):
for req in self.requests: for req in self.requests:
self.logger.info("checking %s" % req.reqid) self.logger.info("checking %s" % req.reqid)
self.request = req 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. # 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 # OBS itself should provide an API for that but that's currently not the case
@ -202,15 +196,13 @@ class ReviewBot(object):
try: try:
good = self.check_one_request(req) good = self.check_one_request(req)
except Exception as e: except Exception:
good = None good = None
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return_value = 1 return_value = 1
sentry_sdk.capture_exception(e)
if self.review_mode == 'no': if self.review_mode == 'no':
good = None good = None
elif self.review_mode == 'accept': elif self.review_mode == 'accept':
@ -439,8 +431,6 @@ class ReviewBot(object):
# Store in-case sub-classes need direct access to original values. # Store in-case sub-classes need direct access to original values.
self.action = a self.action = a
key = request_action_key(a) key = request_action_key(a)
with sentry_sdk.configure_scope() as scope:
scope.set_extra('action.key', key)
override = self.request_override_check() override = self.request_override_check()
if override is not None: if override is not None:
@ -897,11 +887,6 @@ class CommandLineInterface(cmdln.Cmdln):
if self.options.fallback_group: if self.options.fallback_group:
self.checker.fallback_group = 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): def setup_checker(self):
""" reimplement this """ """ reimplement this """
apiurl = conf.config['apiurl'] apiurl = conf.config['apiurl']
@ -991,8 +976,6 @@ class CommandLineInterface(cmdln.Cmdln):
self.logger.info("sleeping %d minutes." % interval) self.logger.info("sleeping %d minutes." % interval)
time.sleep(interval * 60) time.sleep(interval * 60)
sentry_sdk.flush()
# Reset all memoize session caches which are designed for single # Reset all memoize session caches which are designed for single
# tool run and not extended usage. # tool run and not extended usage.
memoize_session_reset() memoize_session_reset()

View File

@ -238,8 +238,6 @@ Group: Development/Tools/Other
Requires: %{name} = %{version} Requires: %{name} = %{version}
Requires: osc >= 0.165.1 Requires: osc >= 0.165.1
Requires: python3-osc Requires: python3-osc
# internal API change related to accessing DSN in osclib/sentry.py
Suggests: python3-sentry-sdk >= 0.11.0
BuildArch: noarch BuildArch: noarch
%description -n osclib %description -n osclib

View File

@ -11,10 +11,7 @@ from socketserver import ThreadingMixIn
import json import json
import tempfile import tempfile
import os import os
from osc import conf
from osclib import common from osclib import common
from osclib.sentry import sentry_client
from osclib.sentry import sentry_init
import subprocess import subprocess
import sys import sys
import time import time
@ -27,15 +24,10 @@ from urllib.parse import parse_qs
# https://stackoverflow.com/a/47012250, workaround by making EVERYTHING LEGAL! # https://stackoverflow.com/a/47012250, workaround by making EVERYTHING LEGAL!
http.cookies._is_legal_key = lambda _: True http.cookies._is_legal_key = lambda _: True
sentry_sdk = sentry_init()
# Available in python 3.7.
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
def handle_error(self, request, client_address): def handle_error(self, request, client_address):
super().handle_error(request, client_address) super().handle_error(request, client_address)
sentry_sdk.capture_exception()
class RequestHandler(BaseHTTPRequestHandler): class RequestHandler(BaseHTTPRequestHandler):
@ -179,14 +171,9 @@ class RequestHandler(BaseHTTPRequestHandler):
return None return None
def oscrc_create(self, oscrc_file, apiurl, cookiejar_file, user): 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([ oscrc_file.write('\n'.join([
'[general]', '[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), 'apiurl = {}'.format(apiurl),
'cookiejar = {}'.format(cookiejar_file.name), 'cookiejar = {}'.format(cookiejar_file.name),
'staging.color = 0', 'staging.color = 0',
@ -371,9 +358,6 @@ class OSCRequestEnvironmentException(Exception):
def main(args): def main(args):
conf.get_config() # Allow sentry DSN to be available.
sentry_init()
RequestHandler.apiurl = args.apiurl RequestHandler.apiurl = args.apiurl
RequestHandler.session = args.session RequestHandler.session = args.session
RequestHandler.debug = args.debug RequestHandler.debug = args.debug

View File

@ -25,7 +25,6 @@ from osclib.origin import origin_revision_state
from osclib.origin import origin_updatable from osclib.origin import origin_updatable
from osclib.origin import origin_updatable_initial from osclib.origin import origin_updatable_initial
from osclib.origin import origin_update from osclib.origin import origin_update
from osclib.sentry import sentry_init
from osclib.util import mail_send from osclib.util import mail_send
from shutil import copyfile from shutil import copyfile
import sys import sys
@ -101,14 +100,8 @@ def do_origin(self, subcmd, opts, *args):
if not config: if not config:
raise oscerr.WrongArgs('OSRT:OriginConfig attribute missing from {}'.format(opts.project)) raise oscerr.WrongArgs('OSRT:OriginConfig attribute missing from {}'.format(opts.project))
sentry_sdk = sentry_init(apiurl, {'osc_plugin': subcmd}) function = 'osrt_origin_{}'.format(command)
try: globals()[function](apiurl, opts, *args[1:])
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
def osrt_origin_config(apiurl, opts, *args): def osrt_origin_config(apiurl, opts, *args):

View File

@ -32,7 +32,6 @@ from osclib.unselect_command import UnselectCommand
from osclib.repair_command import RepairCommand from osclib.repair_command import RepairCommand
from osclib.rebuild_command import RebuildCommand from osclib.rebuild_command import RebuildCommand
from osclib.request_splitter import RequestSplitter from osclib.request_splitter import RequestSplitter
from osclib.sentry import sentry_init
from osclib.supersede_command import SupersedeCommand from osclib.supersede_command import SupersedeCommand
from osclib.prio_command import PrioCommand from osclib.prio_command import PrioCommand
@ -392,8 +391,6 @@ def do_staging(self, subcmd, opts, *args):
if value: if value:
setattr(Fore, name, ansi.code_to_chars(value)) setattr(Fore, name, ansi.code_to_chars(value))
sentry_init(opts.apiurl, {'osc_plugin': subcmd})
if opts.wipe_cache: if opts.wipe_cache:
Cache.delete_all() Cache.delete_all()

View File

@ -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