forked from fabric8-analytics/fabric8-analytics-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.py
38 lines (31 loc) · 1022 Bytes
/
trace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Function to log report for selected event types."""
import json
import logging
from selinon.trace import Trace
_logger = logging.getLogger(__name__)
# We don't use caches now
_IGNORED_EVENTS = (
Trace.NODE_STATE_CACHE_GET,
Trace.NODE_STATE_CACHE_ADD,
Trace.NODE_STATE_CACHE_MISS,
Trace.NODE_STATE_CACHE_HIT,
Trace.TASK_RESULT_CACHE_GET,
Trace.TASK_RESULT_CACHE_ADD,
Trace.TASK_RESULT_CACHE_MISS,
Trace.TASK_RESULT_CACHE_HIT,
# These are not that relevant for prod
Trace.NODE_FAILURE,
Trace.NODE_SUCCESSFUL
)
def trace_func(event, report):
"""Log the report for selected event types."""
if event in _IGNORED_EVENTS:
return
event_str = Trace.event2str(event)
report.update({'event': event_str})
# It's OK to use 'extra' here as we are using a custom logging formatter,
# see celery_settings.py for more info
if event in Trace.WARN_EVENTS:
_logger.warning(json.dumps(report))
else:
_logger.info(json.dumps(report))