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