Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 增加GSE任务结果响应中的agentId(ip)不正确的错误日志 #2165 #2166

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 @@ 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)) {
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上下文传参的问题,在下发用户脚本的时候,实际上下下发两个脚本。第一个脚本是用户脚本,第二个脚本
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释错误,多了一个“下”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*是获取上下文参数的脚本。所以m_id=0的是用户脚本的执行日志,需要分析记录;m_id=1的,则是获取上下文参数
*输出的日志内容,不需要记录,仅需要从日志分析提取上下文参数*/
boolean isUserScriptResult = agentTaskResult.getAtomicTaskId() == 0;
if (isUserScriptResult) {
addScriptLogsAndRefreshPullProgress(scriptLogs, agentTaskResult, agentId, agentTask, currentTime);
}
Expand Down Expand Up @@ -333,6 +335,20 @@ GseTaskExecuteResult analyseGseTaskResult(GseTaskResult<ScriptTaskResult> 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<ServiceScriptLogDTO> logs,
ScriptAgentTaskResult agentTaskResult,
String agentId,
Expand Down