Skip to content

Commit 51a0bce

Browse files
custom patterns, more tolerant to empty values.
1 parent 0ea4d5c commit 51a0bce

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

rma/application.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@
1313
from collections import defaultdict
1414
from redis.exceptions import ResponseError
1515

16+
def ptransform(nm):
17+
if nm.startswith('celery-task-meta'):
18+
spl = nm.split('-')
19+
rt = '-'.join(spl[0:3])+':'+'-'.join(spl[3:])
20+
elif nm.startswith('qo_cli.aff_aggregations.aggregate_aff_aname_aname'):
21+
spl = nm.split('-')
22+
rt = '-'.join(spl[0:1])+':'+'-'.join(spl[1:])
23+
elif nm.endswith('_trigger_queue_user_job'):
24+
spl = nm.split('_')
25+
rt = '_'.join(spl[1:])+':'+'_'.join(spl[0:1])
26+
elif nm.endswith('.reply.celery.pidbox'):
27+
spl = nm.split('.')
28+
rt = '.'.join(spl[1:])+':'+spl[0]
29+
elif nm.endswith('_user_queue_user_job'):
30+
spl = nm.split('_')
31+
rt = '_'.join(spl[1:])+':'+spl[0]
32+
else:
33+
rt = nm
34+
return rt
35+
1636

1737
def connect_to_redis(host, port, db=0, password=None):
1838
"""
@@ -152,14 +172,15 @@ def do_ram(self, res):
152172
total_keys = sum(len(values) for key, values in aggregate_patterns.items())
153173
ret += (rule.analyze(keys=aggregate_patterns, total=total_keys))
154174

175+
155176
return ret
156177

157178
def get_pattern_aggregated_data(self, data):
158-
split_patterns = self.splitter.split((obj["name"] for obj in data))
179+
split_patterns = self.splitter.split((ptransform(obj["name"]) for obj in data))
159180
self.logger.debug(split_patterns)
160181

161182
aggregate_patterns = {item: [] for item in split_patterns}
162183
for pattern in split_patterns:
163-
aggregate_patterns[pattern] = list(filter(lambda obj: fnmatch.fnmatch(obj["name"], pattern), data))
184+
aggregate_patterns[pattern] = list(filter(lambda obj: fnmatch.fnmatch(ptransform(obj["name"]), pattern), data))
164185

165186
return aggregate_patterns

rma/rule/Hash.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,25 @@ def __init__(self, info, redis):
4040
raise Exception('Panic', 'Unknown encoding %s in %s' % (self.encoding, key_name))
4141

4242
self.valueUsedBytes = sum(m)
43-
self.fieldMin = min(args2)
44-
self.fieldMax = max(args3)
45-
self.valueMin = min(m2)
46-
self.valueMax = max(m3)
43+
44+
try:
45+
self.fieldMin = min(args2)
46+
except ValueError:
47+
self.fieldMin = None
48+
pass
49+
try:
50+
self.fieldMax = max(args3)
51+
except ValueError:
52+
self.fieldMax = None
53+
pass
54+
try:
55+
self.valueMin = min(m2)
56+
except ValueError:
57+
self.valueMin = None
58+
try:
59+
self.valueMax = max(m3)
60+
except ValueError:
61+
self.valueMax = None
4762

4863

4964
class HashAggregator(object):

0 commit comments

Comments
 (0)