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