diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/TaskInstanceExecuteObjects.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/TaskInstanceExecuteObjects.java index ed7878e975..e2fb0867f3 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/TaskInstanceExecuteObjects.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/TaskInstanceExecuteObjects.java @@ -44,6 +44,10 @@ public class TaskInstanceExecuteObjects { * 当前作业实例是否包含主机执行对象 */ private boolean containsAnyHost; + /** + * 当前作业实例是否包含容器执行对象 + */ + private boolean containsAnyContainer; /** * 合法的主机(在当前业务下) @@ -78,4 +82,11 @@ public void addContainers(Collection containers) { } validContainers.addAll(containers); } + + public void addContainer(Container container) { + if (validContainers == null) { + validContainers = new HashSet<>(); + } + validContainers.add(container); + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java index c751227973..72c9efcb12 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java @@ -306,6 +306,9 @@ private TaskInstanceDTO executeFastTaskInternal(FastTaskDTO fastTask) { taskInstance.setAllHosts(allHosts); auditFastJobExecute(taskInstance); + // 日志记录容器执行对象的作业,用于统计、分析 + logContainerExecuteObjectJob(taskInstance, taskInstanceExecuteObjects); + return taskInstance; } finally { if (watch.isRunning()) { @@ -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() + ); + } + } + /* * 检查正在执行的作业配额限制,防止单个业务占用所有的执行引擎调度资源 */ @@ -973,6 +991,9 @@ private TaskInstanceDTO executeJobPlanInternal(StopWatch watch, TaskExecuteParam startTask(taskInstance.getId()); watch.stop(); + // 日志记录容器执行对象的作业,用于统计、分析 + logContainerExecuteObjectJob(taskInstance, taskInstanceExecuteObjects); + return taskInstance; } finally { if (watch.isRunning()) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskInstanceExecuteObjectProcessor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskInstanceExecuteObjectProcessor.java index aee4b0a09a..cb617c3580 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskInstanceExecuteObjectProcessor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskInstanceExecuteObjectProcessor.java @@ -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, @@ -692,6 +695,7 @@ private void fillTaskInstanceContainerDetail(TaskInstanceExecuteObjects taskInst notExistContainerIds.add(container.getId()); return; } + taskInstanceExecuteObjects.addContainer(containDetail); container.updatePropsByContainer(containDetail); }); }