[Why] user need to compare the specific metrics
[how] add new api: /compare_template that can be access like: curl -X POST 'localhost:32767/compare_template' -H 'Content-Type: Application/json' -d '{ "compare_metrics": ["fio.write_iops", "fio.read_iops"], "filter": {"suite": ["fio-basic"], "os_arch": ["aarch64", "x86"]}, "compare_dimensions": [ {"os": "debian", "os_version": "sid"}, {"os": "openeuler", "os_version": 20.03} ], "x_params": ["bs", "test_size"], "title": "Hackbench Performance Testing", "unit": "KB/s"}'
Signed-off-by: Lu Weitao luweitaobe@163.com --- container/web-backend/web-backend | 32 +++++++++++++++++++++++++++++++ src/lib/web_backend.rb | 18 +++++++++++++++++ 2 files changed, 50 insertions(+)
diff --git a/container/web-backend/web-backend b/container/web-backend/web-backend index 7db82ac..d68e9f2 100755 --- a/container/web-backend/web-backend +++ b/container/web-backend/web-backend @@ -71,3 +71,35 @@ end get '/get_repos' do get_repos(params) end + +# POST /compare_template +# - header: "Content-Type: Application/json" +# - body: json +# eg: +# { +# "compare_metrics": ["fio.write_iops", "fio.read_iops"], +# "filter":{ +# "suite": ["fio-basic"], +# "os_arch": ["aarch64", "x86"] +# }, +# "compare_dimensions": [ +# { +# "os": "debian", +# "os_version": "sid" +# }, +# { +# "os": "openeuler", +# "os_version: 20.03 +# } +# ], +# "x_params": ["bs", "test_size"], +# "title": "Hackbench Performance Testing", +# "unit": "KB/s" +# } +# +# Response: +# - compare result +post '/compare_template' do + request.body.rewind # in case someone already read it + compare_template(request.body.read) +end diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 1f7224e..23716cb 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -12,6 +12,7 @@ require "#{CCI_SRC}/lib/compare.rb" require "#{CCI_SRC}/lib/constants.rb" require "#{CCI_SRC}/lib/es_query.rb" require "#{CCI_SRC}/lib/matrix2.rb" +require "#{CCI_SRC}/lib/compare_data_format.rb"
UPSTREAM_REPOS_PATH = ENV['UPSTREAM_REPOS_PATH'] || '/c/upstream-repos'
@@ -413,3 +414,20 @@ def get_repos(params) end [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] end + +def compare_template(data) + begin + body = template_body(JSON.parse(data)) + rescue StandardError => e + warn e.message + return [500, headers.merge('Access-Control-Allow-Origin' => '*'), 'compare error'] + end + [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] +end + +def template_body(request_body) + groups_matrices = create_groups_matrices(request_body) + compare_results = compare_metrics_values(groups_matrices) + formatter = FormatEchartData.new(compare_results, request_body) + formatter.format_for_echart.to_json +end