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: 后台日志输出使用容器执行功能的作业信息,方便统计和分析 #3088 #3089

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -44,6 +44,10 @@ public class TaskInstanceExecuteObjects {
* 当前作业实例是否包含主机执行对象
*/
private boolean containsAnyHost;
/**
* 当前作业实例是否包含容器执行对象
*/
private boolean containsAnyContainer;

/**
* 合法的主机(在当前业务下)
Expand Down Expand Up @@ -78,4 +82,11 @@ public void addContainers(Collection<Container> containers) {
}
validContainers.addAll(containers);
}

public void addContainer(Container container) {
if (validContainers == null) {
validContainers = new HashSet<>();
}
validContainers.add(container);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ private TaskInstanceDTO executeFastTaskInternal(FastTaskDTO fastTask) {
taskInstance.setAllHosts(allHosts);
auditFastJobExecute(taskInstance);

// 日志记录容器执行对象的作业,用于统计、分析
logContainerExecuteObjectJob(taskInstance, taskInstanceExecuteObjects);

return taskInstance;
} finally {
if (watch.isRunning()) {
Expand All @@ -317,6 +320,21 @@ private TaskInstanceDTO executeFastTaskInternal(FastTaskDTO fastTask) {
}
}

/*
* 对于包含容器执行对象的作业,输出日志用于统计、分析(后续版本删除)
*/
private void logContainerExecuteObjectJob(TaskInstanceDTO taskInstance,
TaskInstanceExecuteObjects taskInstanceExecuteObjects) {
if (taskInstanceExecuteObjects.isContainsAnyContainer()) {
log.info("ContainerJobRecord -> resourceScope|{}|appCode|{}|jobInstanceId|{}|name|{}",
GlobalAppScopeMappingService.get().getScopeByAppId(taskInstance.getAppId()).toResourceScopeUniqueId(),
StringUtils.isNotEmpty(taskInstance.getAppCode()) ? taskInstance.getAppCode() : "None",
taskInstance.getId(),
taskInstance.getName()
);
}
}

/*
* 检查正在执行的作业配额限制,防止单个业务占用所有的执行引擎调度资源
*/
Expand Down Expand Up @@ -973,6 +991,9 @@ private TaskInstanceDTO executeJobPlanInternal(StopWatch watch, TaskExecuteParam
startTask(taskInstance.getId());
watch.stop();

// 日志记录容器执行对象的作业,用于统计、分析
logContainerExecuteObjectJob(taskInstance, taskInstanceExecuteObjects);

return taskInstance;
} finally {
if (watch.isRunning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ private void acquireAndSetContainers(TaskInstanceExecuteObjects taskInstanceExec
// 根据 ContainerFilter 方式获取并设置容器执行对象
acquireAndSetContainersByContainerFilters(taskInstanceExecuteObjects,
taskInstance, stepInstances);

taskInstanceExecuteObjects.setContainsAnyContainer(
CollectionUtils.isNotEmpty(taskInstanceExecuteObjects.getValidContainers()));
}

private void acquireAndSetContainersByStaticContainerList(TaskInstanceExecuteObjects taskInstanceExecuteObjects,
Expand Down Expand Up @@ -692,6 +695,7 @@ private void fillTaskInstanceContainerDetail(TaskInstanceExecuteObjects taskInst
notExistContainerIds.add(container.getId());
return;
}
taskInstanceExecuteObjects.addContainer(containDetail);
container.updatePropsByContainer(containDetail);
});
}
Expand Down
Loading