[Why] The information about the job that fails the account verification can be traced on kibana.
[Log] {"level_num":2,"level":"WARN","time":"2021-01-21T11:08:19.647+0800","msg":"Invalid account","my_email":"wuzhende666@163.com","suite":"iperf","testcase":"iperf"}
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/lib/job.cr | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 17a0f1b..2971a77 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -10,6 +10,7 @@ require "scheduler/jobfile_operate.cr" require "scheduler/kernel_params.cr" require "scheduler/pp_params.cr" require "../scheduler/elasticsearch_client" +require "./json_logger"
struct JSON::Any def []=(key : String, value : String) @@ -53,6 +54,7 @@ class Job @hash = job_content.as_h @es = Elasticsearch::Client.new @account_info = Hash(String, JSON::Any).new + @log = JSONLogger.new
# init job with "-1", or use the original job_content["id"] id = "-1" if "#{id}" == "" @@ -394,17 +396,29 @@ class Job error_msg += "Please refer to https://gitee.com/wu_fengguang/compass-ci/blob/master/doc/manual/apply-accou..."
account_info = @es.get_account(self["my_email"]) - raise error_msg unless account_info.is_a?(JSON::Any) + + flag = is_valid_account?(account_info) + @log.warn({"msg" => "Invalid account", + "my_email" => self["my_email"], + "suite" => self["suite"], + "testcase" => self["testcase"] + }.to_json) unless flag + raise error_msg unless flag + + @hash.delete("my_uuid") + @hash.delete("my_token") + end + + private def is_valid_account?(account_info) + return false unless account_info.is_a?(JSON::Any)
@account_info = account_info.as_h
# my_name can be nil in es # my_token can't be nil in es - raise error_msg unless self["my_name"] == @account_info["my_name"]?.to_s - raise error_msg unless self["my_token"] == @account_info["my_token"]? - - @hash.delete("my_uuid") - @hash.delete("my_token") + return false unless self["my_name"] == @account_info["my_name"]?.to_s + return false unless self["my_token"] == @account_info["my_token"]? + return true end
private def get_initialized_keys