From 8ebbbf47ca5483d6b7ed5679aac3a792c52252c7 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Sun, 12 Aug 2018 00:31:40 +0000 Subject: [PATCH] Upload test results to from client to web server --- client/benchmarks/runner.py | 21 ++++++++++++++++++++- client/perffarm-client.py | 3 ++- client/settings.py | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/client/benchmarks/runner.py b/client/benchmarks/runner.py index a0532e2..05bbe57 100644 --- a/client/benchmarks/runner.py +++ b/client/benchmarks/runner.py @@ -1,5 +1,7 @@ import json import os +import codecs +import urllib2 from multiprocessing import Process, Queue from time import gmtime, strftime @@ -11,7 +13,7 @@ from utils.logging import log class BenchmarkRunner(object): 'manages runs of all the benchmarks, including cluster restarts etc.' - def __init__(self, out_dir, cluster, collector): + def __init__(self, out_dir, url, secret, cluster, collector): '' self._output = out_dir # where to store output files @@ -19,6 +21,8 @@ class BenchmarkRunner(object): self._configs = {} # config name => (bench name, config) self._cluster = cluster self._collector = collector + self._url = url + self._secret = secret def register_benchmark(self, benchmark_name, benchmark_class): '' @@ -125,6 +129,21 @@ class BenchmarkRunner(object): with open('%s/results.json' % self._output, 'w') as f: f.write(json.dumps(r, indent=4)) + try: + self._upload_results(r) + except Exception as e: + print e + + def _upload_results(self, results): + postdata = results + post = [] + post.append(postdata) + req = urllib2.Request(self._url, json.dumps(post)) + req.add_header('Authorization', self._secret) # add token in header + req.add_header('Content-Type', 'application/json') + response = urllib2.urlopen(req) + + def run(self): 'run all the configured benchmarks' diff --git a/client/perffarm-client.py b/client/perffarm-client.py index 48a1916..e258bb4 100644 --- a/client/perffarm-client.py +++ b/client/perffarm-client.py @@ -54,7 +54,8 @@ if __name__ == '__main__': bin_path=('%s/bin' % (BUILD_PATH))) collectors.register('postgres', pg_collector) - runner = BenchmarkRunner(OUTPUT_DIR, cluster, collectors) + runner = BenchmarkRunner(OUTPUT_DIR, PERFFARM_URL, SECRET, + cluster, collectors) # register the three tests we currently have diff --git a/client/settings.py b/client/settings.py index 1afdfc2..16279db 100644 --- a/client/settings.py +++ b/client/settings.py @@ -2,6 +2,9 @@ import os import sys # global configuration +PERFFARM_URL = 'http://140.211.168.111:8000/upload/' +SECRET='CHANGEME' + GIT_URL = 'https://github.com/postgres/postgres.git' REPOSITORY_PATH = '/tmp/git-postgres' BUILD_PATH = '/tmp/bin-postgres' -- 2.39.5