Upload test results to from client to web server
authorMark Wong <mark@2ndQuadrant.com>
Sun, 12 Aug 2018 00:31:40 +0000 (00:31 +0000)
committerMark Wong <mark@2ndQuadrant.com>
Sun, 12 Aug 2018 00:31:40 +0000 (00:31 +0000)
client/benchmarks/runner.py
client/perffarm-client.py
client/settings.py

index a0532e24d5fbd1b544c14010f262d8ec4f792cfb..05bbe57a1e4a04c22b2eafa6d32efbf8e26edfbf 100644 (file)
@@ -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'
 
index 48a1916841675f76fa91affdd394a37aca44a405..e258bb4f71c5a2d4bf26516676ee4209cb3038bd 100644 (file)
@@ -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
 
index 1afdfc2da0f8c0e883a2699a1a00bfc49bd33d70..16279db2a68a1744db8caceaa95db7be4346a648 100644 (file)
@@ -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'