statsd: use safe mode and disable statsd if we can't connect

This commit is contained in:
RhodeCode Admin 2023-02-02 10:01:32 +01:00
parent 159c758565
commit 7a2bd60f22

View file

@ -38,8 +38,14 @@ def client_from_config(configuration, prefix='statsd.', **kwargs):
ipv6 = asbool(_config.pop('statsd_ipv6', IPV6))
log.debug('configured statsd client %s:%s', host, port)
return StatsClient(
host=host, port=port, prefix=prefix, maxudpsize=maxudpsize, ipv6=ipv6)
try:
client = StatsClient(
host=host, port=port, prefix=prefix, maxudpsize=maxudpsize, ipv6=ipv6)
except Exception:
log.exception('StatsD is enabled, but failed to connect to statsd server, fallback: disable statsd')
client = None
return client
def get_statsd_client(request):