##// END OF EJS Templates
core: refactor of vendor lib to easier sync with vcsserver
super-admin -
r5431:2e534b16 default
parent child Browse files
Show More
@@ -11,9 +11,9 b' import importlib'
11 11 from inspect import istraceback
12 12
13 13 from collections import OrderedDict
14 from rhodecode.lib.logging_formatter import _inject_req_id, ExceptionAwareFormatter
15 from rhodecode.lib.ext_json import sjson as json
16 14
15 from ...logging_formatter import _inject_req_id, ExceptionAwareFormatter
16 from ...ext_json import sjson as json
17 17
18 18 ZERO = timedelta(0)
19 19 HOUR = timedelta(hours=1)
@@ -78,7 +78,7 b' class JsonEncoder(json.JSONEncoder):'
78 78 return str(obj)
79 79
80 80 try:
81 return super(JsonEncoder, self).default(obj)
81 return super().default(obj)
82 82
83 83 except TypeError:
84 84 try:
@@ -194,7 +194,7 b' class JsonFormatter(ExceptionAwareFormat'
194 194
195 195 def serialize_log_record(self, log_record):
196 196 """Returns the final representation of the log record."""
197 return "%s%s" % (self.prefix, self.jsonify_log_record(log_record))
197 return "{}{}".format(self.prefix, self.jsonify_log_record(log_record))
198 198
199 199 def format(self, record):
200 200 """Formats a log record and serializes to json"""
@@ -102,7 +102,7 b' class NotExpirable(RuntimeError):'
102 102 pass
103 103
104 104
105 class Lock(object):
105 class Lock:
106 106 """
107 107 A Lock context manager implemented via redis SETNX/BLPOP.
108 108 """
@@ -1,5 +1,3 b''
1
2
3 1 import logging
4 2
5 3 from .stream import TCPStatsClient, UnixSocketStatsClient # noqa
@@ -1,5 +1,3 b''
1
2
3 1 import re
4 2 import random
5 3 from collections import deque
@@ -31,7 +29,7 b' def normalize_tags(tag_list):'
31 29 return _normalize_tags_with_cache(tuple(tag_list))
32 30
33 31
34 class StatsClientBase(object):
32 class StatsClientBase:
35 33 """A Base class for various statsd clients."""
36 34
37 35 def close(self):
@@ -73,7 +71,7 b' class StatsClientBase(object):'
73 71
74 72 def incr(self, stat, count=1, rate=1, tags=None):
75 73 """Increment a stat by `count`."""
76 self._send_stat(stat, '%s|c' % count, rate, tags)
74 self._send_stat(stat, f'{count}|c', rate, tags)
77 75
78 76 def decr(self, stat, count=1, rate=1, tags=None):
79 77 """Decrement a stat by `count`."""
@@ -87,18 +85,18 b' class StatsClientBase(object):'
87 85 return
88 86 with self.pipeline() as pipe:
89 87 pipe._send_stat(stat, '0|g', 1)
90 pipe._send_stat(stat, '%s|g' % value, 1)
88 pipe._send_stat(stat, f'{value}|g', 1)
91 89 else:
92 90 prefix = '+' if delta and value >= 0 else ''
93 self._send_stat(stat, '%s%s|g' % (prefix, value), rate, tags)
91 self._send_stat(stat, f'{prefix}{value}|g', rate, tags)
94 92
95 93 def set(self, stat, value, rate=1):
96 94 """Set a set value."""
97 self._send_stat(stat, '%s|s' % value, rate)
95 self._send_stat(stat, f'{value}|s', rate)
98 96
99 97 def histogram(self, stat, value, rate=1, tags=None):
100 98 """Set a histogram"""
101 self._send_stat(stat, '%s|h' % value, rate, tags)
99 self._send_stat(stat, f'{value}|h', rate, tags)
102 100
103 101 def _send_stat(self, stat, value, rate, tags=None):
104 102 self._after(self._prepare(stat, value, rate, tags))
@@ -110,10 +108,10 b' class StatsClientBase(object):'
110 108 if rate < 1:
111 109 if random.random() > rate:
112 110 return
113 value = '%s|@%s' % (value, rate)
111 value = f'{value}|@{rate}'
114 112
115 113 if self._prefix:
116 stat = '%s.%s' % (self._prefix, stat)
114 stat = f'{self._prefix}.{stat}'
117 115
118 116 res = '%s:%s%s' % (
119 117 stat,
@@ -1,5 +1,3 b''
1
2
3 1 import socket
4 2
5 3 from .base import StatsClientBase, PipelineBase
@@ -1,5 +1,3 b''
1
2
3 1 import functools
4 2 from time import perf_counter as time_now
5 3
@@ -11,7 +9,7 b' def safe_wraps(wrapper, *args, **kwargs)'
11 9 return functools.wraps(wrapper, *args, **kwargs)
12 10
13 11
14 class Timer(object):
12 class Timer:
15 13 """A context manager/decorator for statsd.timing()."""
16 14
17 15 def __init__(self, client, stat, rate=1, tags=None, use_decimals=True, auto_send=True):
@@ -1,5 +1,3 b''
1
2
3 1 import socket
4 2
5 3 from .base import StatsClientBase, PipelineBase
@@ -8,7 +6,7 b' from .base import StatsClientBase, Pipel'
8 6 class Pipeline(PipelineBase):
9 7
10 8 def __init__(self, client):
11 super(Pipeline, self).__init__(client)
9 super().__init__(client)
12 10 self._maxudpsize = client._maxudpsize
13 11
14 12 def _send(self):
@@ -141,7 +141,7 b' class ColorFormatter(ExceptionAwareForma'
141 141 """
142 142 Changes record's levelname to use with COLORS enum
143 143 """
144 def_record = super(ColorFormatter, self).format(record)
144 def_record = super().format(record)
145 145
146 146 levelname = record.levelname
147 147 start = COLOR_SEQ % (COLORS[levelname])
General Comments 0
You need to be logged in to leave comments. Login now