|
1
|
|
|
from .base_report_backend import BaseReportBackend |
|
2
|
|
|
from ..elasticsearch_storage import ElasticsearchStorage |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class ElasticReportBackend(BaseReportBackend): |
|
6
|
|
|
def __init__(self, config): |
|
7
|
|
|
self.elasticsearch_hosts = config.getoption("benchmark_elasticsearch_hosts") |
|
8
|
|
|
self.elasticsearch_index = config.getoption("benchmark_elasticsearch_index") |
|
9
|
|
|
self.elasticsearch_doctype = config.getoption("benchmark_elasticsearch_doctype") |
|
10
|
|
|
self.project_name = config.getoption("benchmark_project_name") |
|
11
|
|
|
super(ElasticReportBackend, self).__init__(config) |
|
12
|
|
|
self.storage = ElasticsearchStorage(self.elasticsearch_hosts, |
|
13
|
|
|
self.elasticsearch_index, |
|
14
|
|
|
self.elasticsearch_doctype, |
|
15
|
|
|
self.logger, |
|
16
|
|
|
default_machine_id=self.machine_id) |
|
17
|
|
|
|
|
18
|
|
|
def _save(self, output_json, save): |
|
19
|
|
|
output_benchmarks = output_json.pop("benchmarks") |
|
20
|
|
|
for bench in output_benchmarks: |
|
21
|
|
|
# add top level info from output_json dict to each record |
|
22
|
|
|
bench.update(output_json) |
|
23
|
|
|
doc_id = "%s_%s" % (save, bench["fullname"]) |
|
24
|
|
|
self.storage.save(bench, doc_id) |
|
25
|
|
|
self.logger.info("Saved benchmark data to %s to index %s as doctype %s" % |
|
26
|
|
|
( |
|
27
|
|
|
self.elasticsearch_hosts, |
|
28
|
|
|
self.elasticsearch_index, |
|
29
|
|
|
self.elasticsearch_doctype |
|
30
|
|
|
) |
|
31
|
|
|
) |
|
32
|
|
|
|
|
33
|
|
|
def _load(self, id_prefix=None): |
|
34
|
|
|
return self.storage.load(self.project_name, id_prefix) |
|
35
|
|
|
|