Skip to content

Commit

Permalink
perf: 增加GSE任务结果响应中的agentId(ip)不正确的错误日志 TencentBlueKing#2165
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Jun 26, 2023
1 parent c700544 commit 6d2cc72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -284,23 +285,29 @@ GseTaskExecuteResult analyseGseTaskResult(GseTaskResult<ScriptTaskResult> 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)) {
continue;
}
if (!this.targetAgentIds.contains(agentId)) {
log.warn("[{}] Unexpected target agentId {}. result: {}", gseTaskInfo, agentId,
JsonUtils.toJson(agentTaskResult));
continue;
}

log.info("[{}]: Analyse agent task result, result: {}", gseTaskInfo, agentTaskResult);


AgentTaskDTO agentTask = targetAgentTasks.get(agentId);
if (agentTask == null) {
continue;
}

/*为了解决shell上下文传参的问题,在下发用户脚本的时候,实际上下下发两个脚本。第一个脚本是用户脚本,第二个脚本
*是获取上下文参数的脚本。所以m_id=0的是用户脚本的执行日志,需要分析记录;m_id=1的,则是获取上下文参数
*输出的日志内容,不需要记录,仅需要从日志分析提取上下文参数*/
boolean isUserScriptResult = agentTaskResult.getAtomicTaskId() == 0;
if (isUserScriptResult) {
addScriptLogsAndRefreshPullProgress(scriptLogs, agentTaskResult, agentId, agentTask, currentTime);
}
Expand Down

0 comments on commit 6d2cc72

Please sign in to comment.