mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 06:28:23 +00:00
logging: Fix duplicate detection for email errors.
Our implementation of duplication detection in the Zulip email error reporting system was buggy in two important ways: * It did not look at the traceback, and thus considered all errors as the same. * It reset the 10-minute duplicate timer every time an error happened, thus concealing situations where the same error was occuring more often than 1/10 minutes.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
import traceback
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
# Adapted http://djangosnippets.org/snippets/2242/ by user s29 (October 25, 2010)
|
# Adapted http://djangosnippets.org/snippets/2242/ by user s29 (October 25, 2010)
|
||||||
@@ -26,8 +28,10 @@ class _RateLimitFilter(object):
|
|||||||
use_cache = False
|
use_cache = False
|
||||||
|
|
||||||
if use_cache:
|
if use_cache:
|
||||||
key = self.__class__.__name__.upper()
|
tb = '\n'.join(traceback.format_exception(*record.exc_info))
|
||||||
|
key = self.__class__.__name__.upper() + hashlib.sha1(tb).hexdigest()
|
||||||
duplicate = cache.get(key) == 1
|
duplicate = cache.get(key) == 1
|
||||||
|
if not duplicate:
|
||||||
cache.set(key, 1, rate)
|
cache.set(key, 1, rate)
|
||||||
else:
|
else:
|
||||||
min_date = datetime.now() - timedelta(seconds=rate)
|
min_date = datetime.now() - timedelta(seconds=rate)
|
||||||
|
|||||||
Reference in New Issue
Block a user