from config import *
from es import ES
import pprint 

prt = pprint.PrettyPrinter(indent=1)

es = ES().getES()
query = {
	"query":{
		"match_all":{}
	}
}

response = es.search(index = index_name, doc_type = doc_type, 
	body = query, size = 10, request_timeout = 10)

prt.pprint(response)

class BaseResultsAnalyzer(object):
    def __init__(self,
                 es_index,
                 es_doc_type,
                 send_email=False,
                 email_recipients=(),
                 email_template_fp="",
                 query_limit=1000,
                 logger=None):
        self._es = ES()
        self._conf = self._es._conf
        self._es_index = es_index
        self._es_doc_type = es_doc_type
        self._limit = query_limit
        self._send_email = send_email
        self._email_recipients = email_recipients
        self._email_template_fp = email_template_fp
        self.log = logger if logger else log

    def get_all(self):
        """
        Get all the test results in json format
        """
        return self._es.search(index=self._es_index, size=self._limit)

    def get_test_by_id(self, test_id):
        """
        Get test results by test id
        :param test_id: test id created by performance test
        :return: test results in json format
        """
        if not self._es.exists(
                index=self._es_index, doc_type=self._es_doc_type, id=test_id):
            self.log.error('Test results not found: {}'.format(test_id))
            return None
        return self._es.get(index=self._es_index,
                            doc_type=self._es_doc_type,
                            id=test_id)

    def _test_version(self, test_doc):
        if test_doc['_source'].get('versions'):
            for v in ('scylla-server', 'scylla-enterprise-server'):
                k = test_doc['_source']['versions'].get(v)
                if k:
                    return k

        self.log.error('Scylla version is not found for test %s',
                       test_doc['_id'])
        return None

    def render_to_html(self, results, html_file_path=""):
        """
        Render analysis results to html template
        :param results: results dictionary
        :param html_file_path: Boolean, whether to save html file on disk
        :return: html string
        """
        self.log.info("Rendering results to html using '%s' template...",
                      self._email_template_fp)
        loader = jinja2.FileSystemLoader(
            os.path.dirname(os.path.abspath(__file__)))
        env = jinja2.Environment(loader=loader, autoescape=True)
        template = env.get_template(self._email_template_fp)
        html = template.render(results)
        if html_file_path:
            with open(html_file_path, "w") as f:
                f.write(html)
            self.log.info("HTML report saved to '%s'.", html_file_path)
        return html

    def send_email(self, subject, content, html=True, files=()):
        if self._send_email and self._email_recipients:
            self.log.debug('Send email to {}'.format(self._email_recipients))
            em = Email()
            em.send(subject,
                    content,
                    html=html,
                    recipients=self._email_recipients,
                    files=files)
        else:
            self.log.warning(
                "Won't send email (send_email: %s, recipients: %s)",
                self._send_email, self._email_recipients)

    def gen_kibana_dashboard_url(self, dashboard_path=""):
        return "%s/%s" % (self._conf.get('kibana_url'), dashboard_path)

    def check_regression(self):
        return NotImplementedError("check_regression should be implemented!")
Example #3
0
"""
Run and plot the ES results for Ackley
"""
from es import ES
import helper


total_data = None
for h in range(30):
    print(h)
    es = ES(limits=[15.0]*30)
    
    # search 30 times and get med
    data = es.search(1000, 1e-5)
    
    if not total_data:
        total_data = [[], [],[],[], []]
        total_data[0] = data[0]
        total_data[1] = data[1]
        total_data[2] = data[2]
        total_data[3] = data[3]
        total_data[4] = data[4]
    else:
        for i in range(len(total_data[0])):
            total_data[1][i] += data[1][i]
            total_data[2][i] += data[2][i]
            total_data[3][i] += data[3][i]
            total_data[4][i] += data[4][i]

for i in range(len(total_data[0])):
    total_data[1][i] /= 30