Browse Source

Add info block into report toolkit

Ilya Shakhat 3 years ago
parent
commit
d5e8cfc269
2 changed files with 82 additions and 5 deletions
  1. 57
    3
      performa/engine/report.py
  2. 25
    2
      performa/scenarios/mq/omsimulator-ha-cast.rst

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

@@ -61,16 +61,24 @@ def generate_chart(chart_str, db, doc_folder, tag):
61 61
    *
62 62
 ''' % dict(title=title)
63 63
 
64
-    table += ''.join(('     - %s\n' % axes[k]) for k in sorted(axes.keys()))
64
+    axes_keys = sorted(axes.keys())
65
+
66
+    table += ''.join(('     - %s\n' % axes[k]) for k in axes_keys)
65 67
 
66 68
     y_keys = set(axes.keys()) ^ set('x')
67 69
 
68 70
     for chart_rec in chart_data:
69 71
         for k in y_keys:
70 72
             lines[k].append((chart_rec['x'], chart_rec[k]))
73
+
74
+        values = []
75
+        for v in axes_keys:
76
+            cv = chart_rec[v] or 0
77
+            patt = '     - %%%s' % ('d' if isinstance(cv, int) else '.1f')
78
+            values.append(patt % cv)
79
+
71 80
         table += ('   *\n' +
72
-                  '\n'.join('     - %.1f' % (chart_rec[v] or 0)
73
-                            for v in sorted(axes.keys())) +
81
+                  '\n'.join(values) +
74 82
                   '\n')
75 83
 
76 84
     xy_chart = pygal.XY(style=style.RedBlueStyle,
@@ -94,6 +102,47 @@ def generate_chart(chart_str, db, doc_folder, tag):
94 102
     return doc
95 103
 
96 104
 
105
+def generate_info(definition_str, db, doc_folder, tag):
106
+    definition = yaml.safe_load(definition_str)
107
+    pipeline = definition.get('pipeline')
108
+    title = definition.get('title')
109
+    fields = definition.get('fields')
110
+
111
+    collection_name = definition.get('collection') or 'records'
112
+    collection = db.get_collection(collection_name)
113
+
114
+    LOG.debug('Title: %s', title)
115
+
116
+    pipeline.insert(0, {'$match': {'status': 'OK'}})
117
+
118
+    if tag:
119
+        pipeline.insert(0, {'$match': {'tag': tag}})
120
+
121
+    data = [r for r in collection.aggregate(pipeline)]
122
+    if not data:
123
+        LOG.warning('No data returned for info block: %s', title)
124
+        return '**No data**'
125
+
126
+    data = data[0]
127
+
128
+    table = '''
129
+.. list-table::
130
+   :header-rows: 1
131
+
132
+   *
133
+     - attribute
134
+     - value
135
+'''
136
+
137
+    for field_name, field_title in sorted(fields.items(), key=lambda a: a[0]):
138
+        value = data[field_name]
139
+        patt = ('''   *\n     - %%s\n     - %%%s\n''' %
140
+                ('d' if isinstance(value, int) else '.1f'))
141
+        table += patt % (field_title, value)
142
+
143
+    return table
144
+
145
+
97 146
 def _make_dir(name):
98 147
     try:
99 148
         os.makedirs(name)
@@ -128,6 +177,11 @@ def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder,
128 177
         db=db,
129 178
         doc_folder=doc_folder,
130 179
         tag=tag)
180
+    jinja_env.filters['info'] = functools.partial(
181
+        generate_info,
182
+        db=db,
183
+        doc_folder=doc_folder,
184
+        tag=tag)
131 185
 
132 186
     template = utils.read_file(report_template, base_dir=base_dir)
133 187
     compiled_template = jinja_env.from_string(template)

+ 25
- 2
performa/scenarios/mq/omsimulator-ha-cast.rst View File

@@ -5,8 +5,31 @@ This report is result of `message_queue_performance`_ execution
5 5
 with `Oslo.messaging Simulator`_
6 6
 
7 7
 
8
-Test Case 1: RPC CAST Throughput Test
9
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8
+RPC CAST failover throughput test
9
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
+
11
+**Summary**
12
+
13
+{{'''
14
+    title: Execution summary
15
+    fields:
16
+      a1: Client sent, msg
17
+      b1: Server received, msg
18
+      b2: Loss, msg
19
+      c1: Avg. latency, ms
20
+      c2: Max latency, ms
21
+    collection: records
22
+    pipeline:
23
+    - $match: { task: omsimulator, mode: cast }
24
+    - $project:
25
+        a1: "$client.count"
26
+        b1: "$server.count"
27
+        b2: { $subtract: ["$client.count", "$server.count" ] }
28
+        c1: { $multiply: ["$server.latency", 1000] }
29
+        c2: { $multiply: ["$server.max_latency", 1000] }
30
+''' | info
31
+}}
32
+
10 33
 
11 34
 **Messages sent by the client**
12 35
 

Loading…
Cancel
Save