Skip to content

Commit

Permalink
Merge pull request #3089 from wangyu096/issue_3088
Browse files Browse the repository at this point in the history
perf: 后台日志输出使用容器执行功能的作业信息,方便统计和分析 #3088
  • Loading branch information
wangyu096 authored Jul 2, 2024
2 parents b742818 + f39a003 commit 39be431
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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

0 comments on commit 39be431

Please sign in to comment.