##// END OF EJS Templates
.hgignore: add .venv to ignore dirs
.hgignore: add .venv to ignore dirs

File last commit:

r1063:5823ab6c python3
r1093:6e658db3 python3
Show More
statsd_client.py
53 lines | 1.4 KiB | text/x-python | PythonLexer
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:
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
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:
return super(StatsdClientClass, self).__getattribute__(name)
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
return super(StatsdClientClass, self).__getattribute__(name)
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()