metrics: fixed celery task names, fixed hiistogram type metrics, client small fixes

This commit is contained in:
RhodeCode Admin 2022-10-25 21:35:08 +02:00
parent 059911817e
commit 275f31e397
3 changed files with 13 additions and 13 deletions

View file

@ -15,12 +15,11 @@ TAG_INVALID_CHARS_RE = re.compile(
TAG_INVALID_CHARS_SUBS = "_"
# we save and expose methods called by statsd for discovery
stat_dict = {
buckets_dict = {
}
@lru_cache(maxsize=500)
def _normalize_tags_with_cache(tag_list):
return [TAG_INVALID_CHARS_RE.sub(TAG_INVALID_CHARS_SUBS, tag) for tag in tag_list]
@ -96,8 +95,8 @@ class StatsClientBase(object):
self._after(self._prepare(stat, value, rate, tags))
def _prepare(self, stat, value, rate, tags=None):
global stat_dict
stat_dict[stat] = 1
global buckets_dict
buckets_dict[stat] = 1
if rate < 1:
if random.random() > rate:

View file

@ -47,17 +47,14 @@ def run_task(task, *args, **kwargs):
if task is None:
raise ValueError('Got non-existing task for execution')
statsd = StatsdClient.statsd
exec_mode = 'sync'
if rhodecode.CELERY_ENABLED:
t = None
try:
t = task.apply_async(args=args, kwargs=kwargs)
log.debug('executing task %s:%s in async mode', t.task_id, task)
exec_mode = 'async'
return t
except socket.error as e:
if isinstance(e, IOError) and e.errno == 111:
log.error('Unable to connect to celeryd `%s`. Sync execution', e)
@ -73,9 +70,15 @@ def run_task(task, *args, **kwargs):
else:
log.debug('executing task %s:%s in sync mode', 'TASK', task)
statsd = StatsdClient.statsd
if statsd:
task_repr = getattr(task, 'name', task)
statsd.incr('rhodecode_celery_task_total', tags=[
'task:{}'.format(task),
'task:{}'.format(task_repr),
'mode:{}'.format(exec_mode)
])
# we got async task, return it after statsd call
if t:
return t
return ResultWrapper(task(*args, **kwargs))

View file

@ -53,7 +53,7 @@ class RequestWrapperTween(object):
_ver_ = rhodecode.__version__
_path = safe_str(get_access_path(request.environ))
_auth_user = self._get_user_info(request)
user_id = getattr(_auth_user, 'user_id', _auth_user)
total = time.time() - start
log.info(
'Req[%4s] %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
@ -67,10 +67,9 @@ class RequestWrapperTween(object):
resp_code = response.status_code
elapsed_time_ms = round(1000.0 * total) # use ms only
statsd.timing(
'rhodecode_req_timing', elapsed_time_ms,
"rhodecode_req_timing.histogram", elapsed_time_ms,
tags=[
"view_name:{}".format(match_route),
#"user:{}".format(user_id),
"code:{}".format(resp_code)
],
use_decimals=False
@ -78,7 +77,6 @@ class RequestWrapperTween(object):
statsd.incr(
'rhodecode_req_total', tags=[
"view_name:{}".format(match_route),
#"user:{}".format(user_id),
"code:{}".format(resp_code)
])