es-jobs -e group_id=xxxx
error.result.path=/srv/result/openeuler_docker/xxxx: ["Error: unable to find a
match"]
Signed-off-by: Wu Zhende <wuzhende666(a)163.com>
---
lib/es_jobs.rb | 24 +++++++++++++++++++++++-
sbin/es-jobs | 7 ++++++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/lib/es_jobs.rb b/lib/es_jobs.rb
index b0d0fb2..e4e9530 100644
--- a/lib/es_jobs.rb
+++ b/lib/es_jobs.rb
@@ -12,13 +12,14 @@ require_relative './es_query'
# deal jobs search from es
class ESJobs
- def initialize(es_query, my_refine = [], fields = [], stats_filter = [])
+ def initialize(es_query, my_refine = [], fields = [], stats_filter = [], error_result = false)
@es_query = es_query
@jobs = query_jobs_from_es
@refine = my_refine
@fields = fields
@stats_filter = stats_filter
@refine_jobs = []
+ @error_result = error_result
set_jobs_summary
end
@@ -98,6 +99,7 @@ class ESJobs
'max.stats' => {},
'min.stats' => {}
}
+ result['error.result'] = {} if @error_result
metrics.each { |metric| result['raw.stats'][metric] = [] }
result
end
@@ -119,7 +121,27 @@ class ESJobs
result['kvcount']["#{keyword}=#{job[keyword]}"] += 1
result['raw.id']["[#{keyword}=#{job[keyword]}]"] ||= []
result['raw.id']["[#{keyword}=#{job[keyword]}]"] << job['id']
+
+ next unless @error_result && job[keyword] == "failed"
+
+ get_failed_result(result, job)
+ end
+ end
+
+ def get_failed_result(result, job)
+ path = "/srv#{job['result_root']}/#{job['suite']}"
+ res = find_error_lines(path)
+ result['error.result']["path=#{path}"] = res
+ end
+
+ def find_error_lines(path)
+ res = []
+ return res unless File.exist?(path)
+
+ File.open(path).each do |line|
+ res << line.to_s if line.match(/error:/i)
end
+ res
end
def stats_count(result)
diff --git a/sbin/es-jobs b/sbin/es-jobs
index ff0d540..3804dc9 100755
--- a/sbin/es-jobs
+++ b/sbin/es-jobs
@@ -22,6 +22,7 @@ end
opt_refine = [-1]
opt_fields = []
opt_stats_filter = []
+opt_error_result = false
opt_parser = OptionParser.new do |opts|
opts.banner = 'Usage: es-jobs [options] search_key1=val1[,val2..] ..'
@@ -45,11 +46,15 @@ opt_parser = OptionParser.new do |opts|
opts.on('-s fields', '--stats-filter fields', 'return data contains fields in stats') do |fields|
opt_stats_filter = fields.split(',')
end
+
+ opts.on('-e', '--error.result', 'obtain the error information about job failure') do
+ opt_error_result = true
+ end
end
opt_parser.parse!(ARGV)
items = parse_argv
raise 'Please enter a query' if items.empty?
-es_jobs = ESJobs.new(items, opt_refine, opt_fields, opt_stats_filter)
+es_jobs = ESJobs.new(items, opt_refine, opt_fields, opt_stats_filter, opt_error_result)
es_jobs.output
--
2.23.0