Commit 1cc0fc7f by Calen Pennington

Clean up some linting violations

parent 75503a29
...@@ -31,17 +31,19 @@ class CallbackModule(object): ...@@ -31,17 +31,19 @@ class CallbackModule(object):
self.datadog_api_initialized = False self.datadog_api_initialized = False
if self.datadog_api_key: if self.datadog_api_key:
datadog.initialize(api_key=self.datadog_api_key, datadog.initialize(
app_key=None) api_key=self.datadog_api_key,
app_key=None
)
self.datadog_api_initialized = True self.datadog_api_initialized = True
def clean_tag_value(self, value): def clean_tag_value(self, value):
return value.replace(" | ", ".").replace(" ", "-").lower() return value.replace(" | ", ".").replace(" ", "-").lower()
def playbook_on_play_start(self, pattern): def playbook_on_play_start(self, pattern):
self.playbook_name, _ = os.path.splitext( self.playbook_name, _ = os.path.splitext(
os.path.basename(self.play.playbook.filename) os.path.basename(self.play.playbook.filename)
) )
def playbook_on_task_start(self, name, is_conditional): def playbook_on_task_start(self, name, is_conditional):
""" """
...@@ -60,14 +62,15 @@ class CallbackModule(object): ...@@ -60,14 +62,15 @@ class CallbackModule(object):
if self.datadog_api_initialized: if self.datadog_api_initialized:
datadog_tasks_metrics = [] datadog_tasks_metrics = []
for name, points in results: for name, points in results:
datadog_tasks_metrics.append({'metric': 'edx.ansible.task_duration', datadog_tasks_metrics.append({
'date_happened': points[0], 'metric': 'edx.ansible.task_duration',
'points': points[1], 'date_happened': points[0],
'tags': ['task:{0}'.format(self.clean_tag_value(name)), 'points': points[1],
'playbook:{0}'.format(self.clean_tag_value(playbook_name)) 'tags': [
] 'task:{0}'.format(self.clean_tag_value(name)),
} 'playbook:{0}'.format(self.clean_tag_value(playbook_name))
) ]
})
try: try:
datadog.api.Metric.send(datadog_tasks_metrics) datadog.api.Metric.send(datadog_tasks_metrics)
except Exception as ex: except Exception as ex:
...@@ -76,11 +79,12 @@ class CallbackModule(object): ...@@ -76,11 +79,12 @@ class CallbackModule(object):
def _datadog_log_play(self, playbook_name, duration): def _datadog_log_play(self, playbook_name, duration):
if self.datadog_api_initialized: if self.datadog_api_initialized:
try: try:
datadog.api.Metric.send(metric="edx.ansible.playbook_duration", datadog.api.Metric.send(
date_happened=time.time(), metric="edx.ansible.playbook_duration",
points=duration, date_happened=time.time(),
tags=["playbook:{0}".format(self.clean_tag_value(playbook_name))] points=duration,
) tags=["playbook:{0}".format(self.clean_tag_value(playbook_name))]
)
except Exception as ex: except Exception as ex:
logger.error(ex.message) logger.error(ex.message)
...@@ -95,12 +99,11 @@ class CallbackModule(object): ...@@ -95,12 +99,11 @@ class CallbackModule(object):
def _logger_log_play(self, playbook_name, duration, task_count): def _logger_log_play(self, playbook_name, duration, task_count):
logger.info("\nPlaybook {0} finished: {1}, {2} total tasks. {3} elapsed. \n".format( logger.info("\nPlaybook {0} finished: {1}, {2} total tasks. {3} elapsed. \n".format(
playbook_name, playbook_name,
time.asctime(), time.asctime(),
task_count, task_count,
datetime.timedelta(seconds=(int(duration))) datetime.timedelta(seconds=(int(duration)))
) ))
)
def playbook_on_stats(self, stats): def playbook_on_stats(self, stats):
""" """
...@@ -118,7 +121,7 @@ class CallbackModule(object): ...@@ -118,7 +121,7 @@ class CallbackModule(object):
# Total time to run the complete playbook # Total time to run the complete playbook
total_seconds = sum([x[1][1] for x in self.stats.items()]) total_seconds = sum([x[1][1] for x in self.stats.items()])
# send the metric to datadog # send the metric to datadog
self._datadog_log_tasks(self.playbook_name, results) self._datadog_log_tasks(self.playbook_name, results)
self._datadog_log_play(self.playbook_name, total_seconds) self._datadog_log_play(self.playbook_name, total_seconds)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment