Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
configuration
Commits
3298f311
Commit
3298f311
authored
Jul 25, 2016
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minimize time spent with an open file when logging json timing messages
parent
1d53f992
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
26 deletions
+26
-26
playbooks/callback_plugins/task_timing.py
+26
-26
No files found.
playbooks/callback_plugins/task_timing.py
View file @
3298f311
...
...
@@ -88,21 +88,34 @@ class JsonFormatter(Formatter):
# N.B. This is intended to provide a consistent interface and message format
# across all of Open edX tooling, so it deliberately eschews standard
# python logging infrastructure.
if
ANSIBLE_TIMER_LOG
is
not
None
:
log_path
=
playbook_timestamp
.
start
.
strftime
(
ANSIBLE_TIMER_LOG
)
if
ANSIBLE_TIMER_LOG
is
None
:
return
messages
=
[]
for
name
,
timestamp
in
results
.
items
():
messages
.
append
({
'task'
:
name
,
'playbook'
:
playbook_name
,
'started_at'
:
timestamp
.
start
.
isoformat
(),
'ended_at'
:
timestamp
.
end
.
isoformat
(),
'duration'
:
timestamp
.
duration
.
total_seconds
(),
})
messages
.
append
({
'playbook'
:
playbook_name
,
'started_at'
:
playbook_timestamp
.
start
.
isoformat
(),
'ended_at'
:
playbook_timestamp
.
end
.
isoformat
(),
'duration'
:
playbook_timestamp
.
duration
.
total_seconds
(),
})
log_path
=
playbook_timestamp
.
start
.
strftime
(
ANSIBLE_TIMER_LOG
)
try
:
if
not
exists
(
dirname
(
log_path
)):
os
.
makedirs
(
dirname
(
log_path
))
with
open
(
log_path
,
'a'
)
as
outfile
:
for
name
,
timestamp
in
results
.
items
():
log_message
=
{
'task'
:
name
,
'playbook'
:
playbook_name
,
'started_at'
:
timestamp
.
start
.
isoformat
(),
'ended_at'
:
timestamp
.
end
.
isoformat
(),
'duration'
:
timestamp
.
duration
.
total_seconds
(),
}
for
log_message
in
messages
:
json
.
dump
(
log_message
,
outfile
,
...
...
@@ -110,21 +123,8 @@ class JsonFormatter(Formatter):
sort_keys
=
True
,
)
outfile
.
write
(
'
\n
'
)
log_message
=
{
'playbook'
:
playbook_name
,
'started_at'
:
playbook_timestamp
.
start
.
isoformat
(),
'ended_at'
:
playbook_timestamp
.
end
.
isoformat
(),
'duration'
:
playbook_timestamp
.
duration
.
total_seconds
(),
}
json
.
dump
(
log_message
,
outfile
,
separators
=
(
','
,
':'
),
sort_keys
=
True
,
)
outfile
.
write
(
'
\n
'
)
except
Exception
:
LOGGER
.
exception
(
"Unable to write json timing log messages"
)
class
LoggingFormatter
(
Formatter
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment