Skip to content

Commit

Permalink
Write rendered track to a temporary file
Browse files Browse the repository at this point in the history
With this commit we write the full track to a temporary file instead of
dumping it directly into Rally's log file. This helps users to interpret
error messages later on that involve line numbers. It also avoids
bloating Rally's log file.

Closes elastic#554
Relates elastic#559
  • Loading branch information
danielmitterdorfer authored Aug 28, 2018
1 parent 785b80f commit b47309f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion esrally/track/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import glob
import urllib.error
import tempfile

import jinja2
import jinja2.exceptions
Expand Down Expand Up @@ -622,7 +623,12 @@ def read(self, track_name, track_spec_file, mapping_dir):
self.logger.info("Reading track specification file [%s].", track_spec_file)
try:
rendered = render_template_from_file(track_spec_file, self.track_params)
self.logger.info("Final rendered track for '%s': %s", track_spec_file, rendered)
# render the track to a temporary file instead of dumping it into the logs. It is easier to check for error messages
# involving lines numbers and it also does not bloat Rally's log file so much.
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".json")
with open(tmp.name, "wt", encoding="utf-8") as f:
f.write(rendered)
self.logger.info("Final rendered track for '%s' has been written to '%s'.", track_spec_file, tmp.name)
track_spec = json.loads(rendered)
except jinja2.exceptions.TemplateNotFound:
self.logger.exception("Could not load [%s]", track_spec_file)
Expand Down

0 comments on commit b47309f

Please sign in to comment.