Commit 1d53f992 by Calen Pennington

Fail-fast when logging without datadog api initialization

parent d021ea9a
...@@ -57,28 +57,30 @@ class DatadogFormatter(Formatter): ...@@ -57,28 +57,30 @@ class DatadogFormatter(Formatter):
return value.replace(" | ", ".").replace(" ", "-").lower() return value.replace(" | ", ".").replace(" ", "-").lower()
def log_play(self, playbook_name, playbook_timestamp, results): def log_play(self, playbook_name, playbook_timestamp, results):
if self.datadog_api_initialized: if not self.datadog_api_initialized:
datadog_tasks_metrics = [] return
for name, timestamp in results.items():
datadog_tasks_metrics.append({ datadog_tasks_metrics = []
'metric': 'edx.ansible.task_duration', for name, timestamp in results.items():
'date_happened': timestamp.start, datadog_tasks_metrics.append({
'points': timestamp.duration.total_seconds(), 'metric': 'edx.ansible.task_duration',
'tags': [ 'date_happened': timestamp.start,
'task:{0}'.format(self.clean_tag_value(name)), 'points': timestamp.duration.total_seconds(),
'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: ]
datadog.api.Metric.send(datadog_tasks_metrics) })
datadog.api.Metric.send( try:
metric="edx.ansible.playbook_duration", datadog.api.Metric.send(datadog_tasks_metrics)
date_happened=time.time(), datadog.api.Metric.send(
points=playbook_timestamp.duration.total_seconds(), metric="edx.ansible.playbook_duration",
tags=["playbook:{0}".format(self.clean_tag_value(playbook_name))] date_happened=time.time(),
) points=playbook_timestamp.duration.total_seconds(),
except Exception as ex: tags=["playbook:{0}".format(self.clean_tag_value(playbook_name))]
LOGGER.error(ex.message) )
except Exception as ex:
LOGGER.error(ex.message)
class JsonFormatter(Formatter): class JsonFormatter(Formatter):
......
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