Skip to content

Commit

Permalink
Issue #19: Add additional exception handling to Analyzer
Browse files Browse the repository at this point in the history
Wrapped the surfacing of the self.anomalous_metrics list and the writing of the
anomalies.json in some excepts

Modified:
skyline/analyzer/analyzer.py
  • Loading branch information
earthgecko committed Aug 18, 2016
1 parent 13575b0 commit 1100362
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions skyline/analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,13 +834,27 @@ def smtp_trigger_alert(alert, metric):
logger.info('debug :: Memory usage in run after alerts: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)

# Write anomalous_metrics to static webapp directory
if len(self.anomalous_metrics) > 0:
filename = path.abspath(path.join(path.dirname(__file__), '..', settings.ANOMALY_DUMP))
with open(filename, 'w') as fh:
# Make it JSONP with a handle_data() function
anomalous_metrics = list(self.anomalous_metrics)
anomalous_metrics.sort(key=operator.itemgetter(1))
fh.write('handle_data(%s)' % anomalous_metrics)
# @modified 20160818 - Issue #19: Add additional exception handling to Analyzer
anomalous_metrics_list_len = False
try:
len(self.anomalous_metrics)
anomalous_metrics_list_len = True
except:
logger.error('error :: failed to determine length of anomalous_metrics list')

if anomalous_metrics_list_len:
if len(self.anomalous_metrics) > 0:
filename = path.abspath(path.join(path.dirname(__file__), '..', settings.ANOMALY_DUMP))
try:
with open(filename, 'w') as fh:
# Make it JSONP with a handle_data() function
anomalous_metrics = list(self.anomalous_metrics)
anomalous_metrics.sort(key=operator.itemgetter(1))
fh.write('handle_data(%s)' % anomalous_metrics)
except:
logger.error(
'error :: failed to write anomalies to %s' %
str(filename))

# Using count files rather that multiprocessing.Value to enable metrics for
# metrics for algorithm run times, etc
Expand Down

0 comments on commit 1100362

Please sign in to comment.