Allow to tag data

This commit is contained in:
Ilya Shakhat 2016-02-19 16:47:44 +03:00
parent 3bd574c45b
commit 66c0942c0e
4 changed files with 26 additions and 6 deletions

View File

@ -35,6 +35,7 @@ class Endpoint(types.String):
return "Endpoint host[:port]"
MAIN_OPTS = [
cfg.StrOpt('scenario',
default=utils.env('PERFORMA_SCENARIO'),
@ -60,6 +61,9 @@ MAIN_OPTS = [
default=utils.env('PERFORMA_BOOK'),
help='Generate report in ReST format and store it into the '
'specified folder, defaults to env[PERFORMA_BOOK]. '),
cfg.StrOpt('tag',
default=utils.env('PERFORMA_TAG'),
help='Tag the execution, defaults to env[PERFORMA_TAG].'),
]

View File

@ -37,12 +37,17 @@ def main():
scenario = utils.read_yaml_file(scenario_file_path)
base_dir = os.path.dirname(scenario_file_path)
records = player.play_scenario(scenario)
tag = cfg.CONF.tag
if not tag:
tag = utils.random_string()
LOG.info('Using auto-generated tag "%s"', tag)
records = player.play_scenario(scenario, tag)
storage.store_data(records, cfg.CONF.mongo_url, cfg.CONF.mongo_db)
report.generate_report(scenario, base_dir, cfg.CONF.mongo_url,
cfg.CONF.mongo_db, cfg.CONF.book)
cfg.CONF.mongo_db, cfg.CONF.book, tag)
if __name__ == "__main__":

View File

@ -80,7 +80,12 @@ def play_execution(execution):
return records
def play_scenario(scenario):
def tag_records(records, tag):
for r in records:
r['tag'] = tag
def play_scenario(scenario, tag):
records = {}
if 'preparation' in scenario:
@ -90,5 +95,6 @@ def play_scenario(scenario):
execution = scenario['execution']
records = play_execution(execution)
tag_records(records, tag)
return records

View File

@ -32,12 +32,15 @@ from performa.engine import utils
LOG = logging.getLogger(__name__)
def generate_chart(chart_str, records_collection, doc_folder):
def generate_chart(chart_str, records_collection, doc_folder, tag):
chart = yaml.safe_load(chart_str)
pipeline = chart.get('pipeline')
title = chart.get('title')
axes = chart.get('axes') or dict(x='x', y='y')
if tag:
pipeline.insert(0, {'$match': {'tag': tag}})
chart_data = records_collection.aggregate(pipeline)
line = []
@ -81,7 +84,8 @@ def _make_dir(name):
raise
def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder):
def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder,
tag=None):
LOG.info('Generate report')
doc_folder = doc_folder or tempfile.mkdtemp(prefix='performa')
@ -101,7 +105,8 @@ def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder):
jinja_env.filters['chart'] = functools.partial(
generate_chart,
records_collection=records_collection,
doc_folder=doc_folder)
doc_folder=doc_folder,
tag=tag)
template = utils.read_file(report_template, base_dir=base_dir)
compiled_template = jinja_env.from_string(template)