Commit 79741dbd by Calen Pennington

Capture playbook timing in a single Timestamp object

parent 28a8b677
...@@ -45,8 +45,7 @@ class CallbackModule(object): ...@@ -45,8 +45,7 @@ class CallbackModule(object):
self.stats = {} self.stats = {}
self.current_task = None self.current_task = None
self.playbook_name = None self.playbook_name = None
self.playbook_start = None self.playbook_timestamp = None
self.playbook_end = None
self.datadog_api_key = os.getenv('DATADOG_API_KEY') self.datadog_api_key = os.getenv('DATADOG_API_KEY')
self.datadog_api_initialized = False self.datadog_api_initialized = False
...@@ -64,7 +63,7 @@ class CallbackModule(object): ...@@ -64,7 +63,7 @@ class CallbackModule(object):
self.playbook_name, _ = splitext( self.playbook_name, _ = splitext(
basename(self.play.playbook.filename) basename(self.play.playbook.filename)
) )
self.playbook_start = datetime.utcnow() self.playbook_timestamp = Timestamp()
def playbook_on_task_start(self, name, is_conditional): def playbook_on_task_start(self, name, is_conditional):
""" """
...@@ -128,7 +127,7 @@ class CallbackModule(object): ...@@ -128,7 +127,7 @@ class CallbackModule(object):
def _json_log_tasks(self, playbook_name, results): def _json_log_tasks(self, playbook_name, results):
if ANSIBLE_TIMER_LOG is not None: if ANSIBLE_TIMER_LOG is not None:
log_path = self.playbook_start.strftime(ANSIBLE_TIMER_LOG) log_path = self.playbook_timestamp.start.strftime(ANSIBLE_TIMER_LOG)
if not exists(dirname(log_path)): if not exists(dirname(log_path)):
os.makedirs(dirname(log_path)) os.makedirs(dirname(log_path))
...@@ -156,7 +155,7 @@ class CallbackModule(object): ...@@ -156,7 +155,7 @@ class CallbackModule(object):
# across all of Open edX tooling, so it deliberately eschews standard # across all of Open edX tooling, so it deliberately eschews standard
# python logging infrastructure. # python logging infrastructure.
if ANSIBLE_TIMER_LOG is not None: if ANSIBLE_TIMER_LOG is not None:
log_path = self.playbook_start.strftime(ANSIBLE_TIMER_LOG) log_path = self.playbook_timestamp.start.strftime(ANSIBLE_TIMER_LOG)
if not exists(dirname(log_path)): if not exists(dirname(log_path)):
os.makedirs(dirname(log_path)) os.makedirs(dirname(log_path))
...@@ -164,8 +163,8 @@ class CallbackModule(object): ...@@ -164,8 +163,8 @@ class CallbackModule(object):
with open(log_path, 'a') as outfile: with open(log_path, 'a') as outfile:
log_message = { log_message = {
'playbook': self.playbook_name, 'playbook': self.playbook_name,
'started_at': self.playbook_start.isoformat(), 'started_at': self.playbook_timestamp.start.isoformat(),
'ended_at': self.playbook_end.isoformat(), 'ended_at': self.playbook_timestamp.end.isoformat(),
'duration': duration, 'duration': duration,
} }
...@@ -187,7 +186,7 @@ class CallbackModule(object): ...@@ -187,7 +186,7 @@ class CallbackModule(object):
if self.current_task is not None: if self.current_task is not None:
self.stats[self.current_task].stop() self.stats[self.current_task].stop()
self.playbook_end = datetime.utcnow() self.playbook_timestamp.stop()
# Sort the tasks by their running time # Sort the tasks by their running time
results = sorted( results = sorted(
...@@ -198,8 +197,8 @@ class CallbackModule(object): ...@@ -198,8 +197,8 @@ class CallbackModule(object):
# log the stats # log the stats
total_seconds = (self.playbook_end - self.playbook_start).total_seconds() total_seconds = self.playbook_timestamp.duration.total_seconds()
i
self._json_log_tasks(self.playbook_name, results) self._json_log_tasks(self.playbook_name, results)
self._json_log_play(self.playbook_name, total_seconds) self._json_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