[why]
get field state count for overview of report page.
[input]
suite/os/tbox_group/...
eg: suite
[output]
{"build-pkg"=> {"failed"=>5543, "finished"=>906, "incomplete"=>197, "submit"=>136, "OOM"=>11, "post_run"=>2},
"cci-depends"=> {"finished"=>1782, "failed"=>675, "incomplete"=>279, "post_run"=>3, "OOM"=>1, "running"=>1},
"cci-makepkg"=> {"failed"=>1659, "finished"=>1231, "incomplete"=>384, "OOM"=>4, "post_run"=>1},
"iperf"=>{"finished"=>179, "failed"=>94},
"spinlock"=>{"finished"=>52, "failed"=>1},
"iperf-walk-os-test"=>{"finished"=>172, "failed"=>24, "OOM"=>1},
"stream"=>{"finished"=>242, "incomplete"=>157, "failed"=>7},
"deploy-cci"=>{"finished"=>27, "failed"=>19},
"borrow"=>{"finished"=>101, "incomplete"=>12, "failed"=>4},
"bisect"=>{"finished"=>169, "failed"=>151},
...
}
Signed-off-by: Lu Kaiyi <2392863668(a)qq.com>
---
src/lib/web_backend.rb | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb
index ea67064..15e2ad0 100644
--- a/src/lib/web_backend.rb
+++ b/src/lib/web_backend.rb
@@ -509,3 +509,37 @@ def get_tbox_state(params)
end
[200, headers.merge('Access-Control-Allow-Origin' => '*'), body]
end
+
+def query_field_state(field)
+ query = {
+ aggs: {
+ "all_#{field}" => {
+ terms: { field: field, size: 1000 },
+ aggs: {
+ all_state: {
+ terms: { field: 'job_state' }
+ }
+ }
+ }
+ },
+ size: 0
+ }
+ es_result = es_query(query)['aggregations']["all_#{field}"]['buckets']
+ es_result.sort_by! { |h| h['doc_count'] }
+ es_result.reverse!
+
+ parse_field_state(es_result)
+end
+
+def parse_field_state(es_result)
+ result_hash = {}
+ es_result.each do |result|
+ key = result['key']
+ all_state = result['all_state']['buckets']
+ state_count = {}
+ all_state.map { |state| state_count[state['key']] = state['doc_count'] }
+ result_hash[key] = state_count unless state_count.empty?
+ end
+
+ result_hash
+end
--
2.23.0