##// END OF EJS Templates
deps: bumped idna==3.10
deps: bumped idna==3.10

File last commit:

r1327:278da2b3 default
r1336:b4c1c007 default
Show More
statsd_client.py
70 lines | 2.1 KiB | text/x-python | PythonLexer
ruff: code-cleanups
r1100 # RhodeCode VCSServer provides access to different vcs backends via network.
core: updated copyrights to 2024
r1327 # Copyright (C) 2014-2024 RhodeCode GmbH
ruff: code-cleanups
r1100 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
metrics: use new statsd client logic, and start gathering new metrics
r1005 from vcsserver.lib._vendor.statsd import client_from_config
class StatsdClientNotInitialised(Exception):
pass
class _Singleton(type):
"""A metaclass that creates a Singleton base class when called."""
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
python3: fixes and code optimization for python3.11
r1114 cls._instances[cls] = super().__call__(*args, **kwargs)
metrics: use new statsd client logic, and start gathering new metrics
r1005 return cls._instances[cls]
class Singleton(_Singleton("SingletonMeta", (object,), {})):
pass
class StatsdClientClass(Singleton):
setup_run = False
statsd_client = None
statsd = None
code: flake8 fixes
r1063 strict_mode_init = False
metrics: use new statsd client logic, and start gathering new metrics
r1005
def __getattribute__(self, name):
if name.startswith("statsd"):
if self.setup_run:
python3: fixes and code optimization for python3.11
r1114 return super().__getattribute__(name)
metrics: use new statsd client logic, and start gathering new metrics
r1005 else:
code: flake8 fixes
r1063 if self.strict_mode_init:
raise StatsdClientNotInitialised(f"requested key was {name}")
metrics: use new statsd client logic, and start gathering new metrics
r1005 return None
python3: fixes and code optimization for python3.11
r1114 return super().__getattribute__(name)
metrics: use new statsd client logic, and start gathering new metrics
r1005
def setup(self, settings):
"""
Initialize the client
"""
code: flake8 fixes
r1063 strict_init_mode = settings.pop('statsd_strict_init', False)
metrics: use new statsd client logic, and start gathering new metrics
r1005 statsd = client_from_config(settings)
self.statsd = statsd
self.statsd_client = statsd
self.setup_run = True
StatsdClient = StatsdClientClass()