diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java index 04052b600b..595f17065e 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java @@ -552,25 +552,33 @@ private boolean shouldAnalyse(AtomicFileTaskResult result) { boolean isDownloadMode = content.isDownloadMode(); String agentId = isDownloadMode ? content.getDestAgentId() : content.getSourceAgentId(); - boolean shouldAnalyse = true; if (isDownloadMode) { - if (this.analyseFinishedTargetAgentIds.contains(agentId) // 该ip已经日志分析结束,不要再分析 + if (this.analyseFinishedTargetAgentIds.contains(agentId) // 该Agent已经分析结束,不需要再分析 // 该文件下载任务已结束 || (this.finishedDownloadFileMap.get(agentId) != null - && this.finishedDownloadFileMap.get(agentId).contains(content.getTaskId())) - // 非目标IP - || !this.fileDownloadTaskNumMap.containsKey(agentId)) { - shouldAnalyse = false; + && this.finishedDownloadFileMap.get(agentId).contains(content.getTaskId()))) { + return false; + } + // 不属于当前任务的目标Agent + if (!this.fileDownloadTaskNumMap.containsKey(agentId)) { + log.warn("[{}] Unexpected target agentId {}. result: {}", gseTaskInfo, agentId, + JsonUtils.toJson(result)); + return false; } } else { - if ((this.finishedUploadFileMap.get(agentId) != null - && this.finishedUploadFileMap.get(agentId).contains(content.getTaskId())) - // 非源IP - || !this.fileUploadTaskNumMap.containsKey(agentId)) { - shouldAnalyse = false; + if (this.analyseFinishedSourceAgentIds.contains(agentId) // 该Agent已经分析结束,不需要再分析 + || (this.finishedUploadFileMap.get(agentId) != null + && this.finishedUploadFileMap.get(agentId).contains(content.getTaskId()))) { + return false; + } + // 不属于当前任务的源Agent + if (!this.fileUploadTaskNumMap.containsKey(agentId)) { + log.warn("[{}] Unexpected source agentId {}. result: {}", gseTaskInfo, agentId, + JsonUtils.toJson(result)); + return false; } } - return shouldAnalyse; + return true; } private void analyseFailedFileResult(JobAtomicFileTaskResult result, diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ScriptResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ScriptResultHandleTask.java index 431d9ee876..b76ed6521b 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ScriptResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ScriptResultHandleTask.java @@ -33,6 +33,7 @@ import com.tencent.bk.job.common.model.dto.HostDTO; import com.tencent.bk.job.common.util.BatchUtil; import com.tencent.bk.job.common.util.date.DateUtils; +import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.execute.constants.VariableValueTypeEnum; import com.tencent.bk.job.execute.engine.consts.AgentTaskStatusEnum; import com.tencent.bk.job.execute.engine.evict.TaskEvictPolicyExecutor; @@ -284,23 +285,24 @@ GseTaskExecuteResult analyseGseTaskResult(GseTaskResult taskDe StopWatch watch = new StopWatch("analyse-gse-script-task"); watch.start("analyse"); for (ScriptAgentTaskResult agentTaskResult : taskDetail.getResult().getResult()) { - log.info("[{}]: Analyse agent task result, result: {}", gseTaskInfo, agentTaskResult); - - /*为了解决shell上下文传参的问题,在下发用户脚本的时候,实际上下下发两个脚本。第一个脚本是用户脚本,第二个脚本 - *是获取上下文参数的脚本。所以m_id=0的是用户脚本的执行日志,需要分析记录;m_id=1的,则是获取上下文参数 - *输出的日志内容,不需要记录,仅需要从日志分析提取上下文参数*/ - boolean isUserScriptResult = agentTaskResult.getAtomicTaskId() == 0; String agentId = agentTaskResult.getAgentId(); - - // 该Agent已经日志分析结束,不要再分析 - if (this.analyseFinishedTargetAgentIds.contains(agentId)) { + if (!shouldAnalyse(agentTaskResult)) { continue; } + AgentTaskDTO agentTask = targetAgentTasks.get(agentId); if (agentTask == null) { + log.warn("[{}] No agent task found for agentId {}. result: {}", gseTaskInfo, agentId, + JsonUtils.toJson(agentTaskResult)); continue; } + log.info("[{}]: Analyse agent task result, result: {}", gseTaskInfo, agentTaskResult); + + /*为了解决shell上下文传参的问题,在下发用户脚本的时候,实际上下发两个脚本。第一个脚本是用户脚本,第二个脚本 + *是获取上下文参数的脚本。所以m_id=0的是用户脚本的执行日志,需要分析记录;m_id=1的,则是获取上下文参数 + *输出的日志内容,不需要记录,仅需要从日志分析提取上下文参数*/ + boolean isUserScriptResult = agentTaskResult.getAtomicTaskId() == 0; if (isUserScriptResult) { addScriptLogsAndRefreshPullProgress(scriptLogs, agentTaskResult, agentId, agentTask, currentTime); } @@ -333,6 +335,20 @@ GseTaskExecuteResult analyseGseTaskResult(GseTaskResult taskDe return rst; } + private boolean shouldAnalyse(ScriptAgentTaskResult agentTaskResult) { + String agentId = agentTaskResult.getAgentId(); + // 该Agent已经日志分析结束,不要再分析 + if (this.analyseFinishedTargetAgentIds.contains(agentId)) { + return false; + } + if (!this.targetAgentIds.contains(agentId)) { + log.warn("[{}] Unexpected target agentId {}. result: {}", gseTaskInfo, agentId, + JsonUtils.toJson(agentTaskResult)); + return false; + } + return true; + } + private void addScriptLogsAndRefreshPullProgress(List logs, ScriptAgentTaskResult agentTaskResult, String agentId,