Browse Source

Allow to tag data

Ilya Shakhat 3 years ago
parent
commit
66c0942c0e
4 changed files with 26 additions and 6 deletions
  1. 4
    0
      performa/engine/config.py
  2. 7
    2
      performa/engine/main.py
  3. 7
    1
      performa/engine/player.py
  4. 8
    3
      performa/engine/report.py

+ 4
- 0
performa/engine/config.py View File

@@ -35,6 +35,7 @@ class Endpoint(types.String):
35 35
         return "Endpoint host[:port]"
36 36
 
37 37
 
38
+
38 39
 MAIN_OPTS = [
39 40
     cfg.StrOpt('scenario',
40 41
                default=utils.env('PERFORMA_SCENARIO'),
@@ -60,6 +61,9 @@ MAIN_OPTS = [
60 61
                default=utils.env('PERFORMA_BOOK'),
61 62
                help='Generate report in ReST format and store it into the '
62 63
                     'specified folder, defaults to env[PERFORMA_BOOK]. '),
64
+    cfg.StrOpt('tag',
65
+               default=utils.env('PERFORMA_TAG'),
66
+               help='Tag the execution, defaults to env[PERFORMA_TAG].'),
63 67
 ]
64 68
 
65 69
 

+ 7
- 2
performa/engine/main.py View File

@@ -37,12 +37,17 @@ def main():
37 37
     scenario = utils.read_yaml_file(scenario_file_path)
38 38
     base_dir = os.path.dirname(scenario_file_path)
39 39
 
40
-    records = player.play_scenario(scenario)
40
+    tag = cfg.CONF.tag
41
+    if not tag:
42
+        tag = utils.random_string()
43
+        LOG.info('Using auto-generated tag "%s"', tag)
44
+
45
+    records = player.play_scenario(scenario, tag)
41 46
 
42 47
     storage.store_data(records, cfg.CONF.mongo_url, cfg.CONF.mongo_db)
43 48
 
44 49
     report.generate_report(scenario, base_dir, cfg.CONF.mongo_url,
45
-                           cfg.CONF.mongo_db, cfg.CONF.book)
50
+                           cfg.CONF.mongo_db, cfg.CONF.book, tag)
46 51
 
47 52
 
48 53
 if __name__ == "__main__":

+ 7
- 1
performa/engine/player.py View File

@@ -80,7 +80,12 @@ def play_execution(execution):
80 80
     return records
81 81
 
82 82
 
83
-def play_scenario(scenario):
83
+def tag_records(records, tag):
84
+    for r in records:
85
+        r['tag'] = tag
86
+
87
+
88
+def play_scenario(scenario, tag):
84 89
     records = {}
85 90
 
86 91
     if 'preparation' in scenario:
@@ -90,5 +95,6 @@ def play_scenario(scenario):
90 95
         execution = scenario['execution']
91 96
 
92 97
         records = play_execution(execution)
98
+        tag_records(records, tag)
93 99
 
94 100
     return records

+ 8
- 3
performa/engine/report.py View File

@@ -32,12 +32,15 @@ from performa.engine import utils
32 32
 LOG = logging.getLogger(__name__)
33 33
 
34 34
 
35
-def generate_chart(chart_str, records_collection, doc_folder):
35
+def generate_chart(chart_str, records_collection, doc_folder, tag):
36 36
     chart = yaml.safe_load(chart_str)
37 37
     pipeline = chart.get('pipeline')
38 38
     title = chart.get('title')
39 39
     axes = chart.get('axes') or dict(x='x', y='y')
40 40
 
41
+    if tag:
42
+        pipeline.insert(0, {'$match': {'tag': tag}})
43
+
41 44
     chart_data = records_collection.aggregate(pipeline)
42 45
 
43 46
     line = []
@@ -81,7 +84,8 @@ def _make_dir(name):
81 84
             raise
82 85
 
83 86
 
84
-def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder):
87
+def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder,
88
+                    tag=None):
85 89
     LOG.info('Generate report')
86 90
 
87 91
     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):
101 105
     jinja_env.filters['chart'] = functools.partial(
102 106
         generate_chart,
103 107
         records_collection=records_collection,
104
-        doc_folder=doc_folder)
108
+        doc_folder=doc_folder,
109
+        tag=tag)
105 110
 
106 111
     template = utils.read_file(report_template, base_dir=base_dir)
107 112
     compiled_template = jinja_env.from_string(template)

Loading…
Cancel
Save