Load benchmark results as JSON

Load the JSON at the API side instead of client side, because that's
what the API doc says it is and it just makes more sense.
This commit is contained in:
Joshua Boniface 2021-09-30 23:36:27 -04:00
parent 23977b04fc
commit ce06e4d81b
2 changed files with 7 additions and 6 deletions

View File

@ -78,6 +78,8 @@ def close_database(conn, cur, failed=False):
def list_benchmarks(job=None): def list_benchmarks(job=None):
from json import loads
if job is not None: if job is not None:
query = "SELECT * FROM {} WHERE job = %s;".format('storage_benchmarks') query = "SELECT * FROM {} WHERE job = %s;".format('storage_benchmarks')
args = (job, ) args = (job, )
@ -93,7 +95,7 @@ def list_benchmarks(job=None):
benchmark_data = dict() benchmark_data = dict()
benchmark_data['id'] = benchmark['id'] benchmark_data['id'] = benchmark['id']
benchmark_data['job'] = benchmark['job'] benchmark_data['job'] = benchmark['job']
benchmark_data['benchmark_result'] = benchmark['result'] benchmark_data['benchmark_result'] = loads(benchmark['result'])
# Append the new data to our actual output structure # Append the new data to our actual output structure
data.append(benchmark_data) data.append(benchmark_data)
close_database(conn, cur) close_database(conn, cur)

View File

@ -19,7 +19,6 @@
# #
############################################################################### ###############################################################################
import json
import math import math
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor
@ -1479,12 +1478,12 @@ def format_list_benchmark(config, benchmark_information):
if benchmark['benchmark_result'] == 'Running': if benchmark['benchmark_result'] == 'Running':
continue continue
benchmark_data = json.loads(benchmark['benchmark_result']) benchmark_data = benchmark['benchmark_result']
benchmark_bandwidth = dict() benchmark_bandwidth = dict()
benchmark_iops = dict() benchmark_iops = dict()
for test in ["seq_read", "seq_write", "rand_read_4K", "rand_write_4K"]: for test in ["seq_read", "seq_write", "rand_read_4K", "rand_write_4K"]:
benchmark_data = json.loads(benchmark['benchmark_result']) benchmark_data = benchmark['benchmark_result']
benchmark_bandwidth[test] = format_bytes_tohuman(int(benchmark_data[test]['overall']['bandwidth']) * 1024) benchmark_bandwidth[test] = format_bytes_tohuman(int(benchmark_data[test]['overall']['bandwidth']) * 1024)
benchmark_iops[test] = format_ops_tohuman(int(benchmark_data[test]['overall']['iops'])) benchmark_iops[test] = format_ops_tohuman(int(benchmark_data[test]['overall']['iops']))
@ -1558,7 +1557,7 @@ def format_list_benchmark(config, benchmark_information):
benchmark_bandwidth = dict() benchmark_bandwidth = dict()
benchmark_iops = dict() benchmark_iops = dict()
for test in ["seq_read", "seq_write", "rand_read_4K", "rand_write_4K"]: for test in ["seq_read", "seq_write", "rand_read_4K", "rand_write_4K"]:
benchmark_data = json.loads(benchmark['benchmark_result']) benchmark_data = benchmark['benchmark_result']
benchmark_bandwidth[test] = format_bytes_tohuman(int(benchmark_data[test]['overall']['bandwidth']) * 1024) benchmark_bandwidth[test] = format_bytes_tohuman(int(benchmark_data[test]['overall']['bandwidth']) * 1024)
benchmark_iops[test] = format_ops_tohuman(int(benchmark_data[test]['overall']['iops'])) benchmark_iops[test] = format_ops_tohuman(int(benchmark_data[test]['overall']['iops']))
@ -1595,7 +1594,7 @@ def format_info_benchmark(config, benchmark_information):
if benchmark_information[0]['benchmark_result'] == "Running": if benchmark_information[0]['benchmark_result'] == "Running":
return "Benchmark test is still running." return "Benchmark test is still running."
benchmark_details = json.loads(benchmark_information[0]['benchmark_result']) benchmark_details = benchmark_information[0]['benchmark_result']
# Format a nice output; do this line-by-line then concat the elements at the end # Format a nice output; do this line-by-line then concat the elements at the end
ainformation = [] ainformation = []