From 9a95898fe2d1c95cb5b673ff9c55c69d573991fc Mon Sep 17 00:00:00 2001 From: jsonwan Date: Fri, 20 Sep 2024 19:49:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf:=20=E6=A0=B9=E6=8D=AE=E8=93=9D?= =?UTF-8?q?=E9=B2=B8=E8=A7=84=E8=8C=83=E8=B0=83=E6=95=B4=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=20#3217?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新BK_DOC_JOB_ROOT_URL变量取值与job-analysis中静态数据文档链接 --- .../VersionInfoLogApplicationRunner.java | 15 ++++-------- .../config/JobCommonAutoConfiguration.java | 11 +++++++++ .../bk/job/common/util/JobContextUtil.java | 6 +++++ .../bk/job/analysis/service/IndexService.java | 2 +- .../inner/ServiceGlobalSettingsResource.java | 11 +++++++++ .../ServiceGlobalSettingsResourceImpl.java | 8 ++++++- .../globalsetting/GlobalSettingsService.java | 2 ++ .../impl/GlobalSettingsServiceImpl.java | 23 ++++++++++++++++++- ...ob_analysis_20240920-2000_V3.9.6_mysql.sql | 10 ++++++++ 9 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 support-files/sql/job-analysis/0008_job_analysis_20240920-2000_V3.9.6_mysql.sql diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/VersionInfoLogApplicationRunner.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/VersionInfoLogApplicationRunner.java index 9c24d0b66c..101e66970a 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/VersionInfoLogApplicationRunner.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/VersionInfoLogApplicationRunner.java @@ -27,28 +27,23 @@ package com.tencent.bk.job.common; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.info.BuildProperties; -import org.springframework.stereotype.Component; -@Component @Slf4j public class VersionInfoLogApplicationRunner implements ApplicationRunner { - @Value("${spring.application.name:bk-job}") - private String serviceName; + private final String serviceName; private final BuildProperties buildProperties; - @Autowired - public VersionInfoLogApplicationRunner(BuildProperties buildProperties) { + public VersionInfoLogApplicationRunner(String serviceName, BuildProperties buildProperties) { + this.serviceName = serviceName; this.buildProperties = buildProperties; } @Override - public void run(ApplicationArguments args){ + public void run(ApplicationArguments args) { String version = buildProperties.getVersion(); - log.info("Service name: '{}', Version: '{}'", serviceName, version); + log.info("serviceName= {}, version= {}", serviceName, version); } } diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/service/config/JobCommonAutoConfiguration.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/service/config/JobCommonAutoConfiguration.java index 5d0d58f2ac..c68730e67c 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/service/config/JobCommonAutoConfiguration.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/service/config/JobCommonAutoConfiguration.java @@ -24,8 +24,11 @@ package com.tencent.bk.job.common.service.config; +import com.tencent.bk.job.common.VersionInfoLogApplicationRunner; import com.tencent.bk.job.common.config.BkConfig; import com.tencent.bk.job.common.util.ApplicationContextRegister; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.info.BuildProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -39,4 +42,12 @@ public class JobCommonAutoConfiguration { public ApplicationContextRegister applicationContextRegister() { return new ApplicationContextRegister(); } + + @Value("${spring.application.name:bk-job}") + private String serviceName; + + @Bean + public VersionInfoLogApplicationRunner versionInfoLogApplicationRunner(BuildProperties buildProperties) { + return new VersionInfoLogApplicationRunner(serviceName, buildProperties); + } } diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/JobContextUtil.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/JobContextUtil.java index c168f3adce..5052984312 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/JobContextUtil.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/JobContextUtil.java @@ -26,6 +26,7 @@ import com.tencent.bk.job.common.context.JobContext; import com.tencent.bk.job.common.context.JobContextThreadLocal; +import com.tencent.bk.job.common.i18n.locale.LocaleUtils; import com.tencent.bk.job.common.model.dto.AppResourceScope; import io.micrometer.core.instrument.Tag; import lombok.extern.slf4j.Slf4j; @@ -135,6 +136,11 @@ public static void setUserLang(String userLang) { jobContext.setUserLang(userLang); } + public static boolean isEnglishLocale() { + String normalLang = LocaleUtils.getNormalLang(getUserLang()); + return normalLang.equals(LocaleUtils.LANG_EN) || normalLang.equals(LocaleUtils.LANG_EN_US); + } + public static List getDebugMessage() { JobContext jobContext = JobContextThreadLocal.get(); List debugMessage = null; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java index 1934f166aa..368695647b 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java @@ -73,7 +73,7 @@ public IndexService(AnalysisTaskInstanceDAO analysisTaskInstanceDAO, private Map getVariablesMap() { Map variablesMap = new HashMap<>(); - variablesMap.put("BK_DOCS_CENTER", globalSettingsResource.getDocCenterBaseUrl().getData()); + variablesMap.put("BK_DOC_JOB_ROOT_URL", globalSettingsResource.getDocJobRootUrl().getData()); return variablesMap; } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java index f41c9c5d4d..fcc0fff132 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java @@ -37,10 +37,21 @@ @InternalAPI public interface ServiceGlobalSettingsResource { + /** + * 获取文档中心基础Url + * Deprecated:3.9.x中不推荐使用,3.10.x中下线,请使用getDocJobRootUrl + * + * @return 文档中心基础Url + */ + @Deprecated @ApiOperation(value = "获取文档中心基础Url", produces = "application/json") @GetMapping("/service/globalSettings/docCenterBaseUrl") InternalResponse getDocCenterBaseUrl(); + @ApiOperation(value = "获取文档中心Job文档基础Url", produces = "application/json") + @GetMapping("/service/globalSettings/docJobRootUrl") + InternalResponse getDocJobRootUrl(); + @ApiOperation(value = "获取文件上传设置", produces = "application/json") @GetMapping("/service/globalSettings/fileUploadSettings") InternalResponse getFileUploadSettings(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceGlobalSettingsResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceGlobalSettingsResourceImpl.java index e714ce0789..74e8e06aa2 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceGlobalSettingsResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceGlobalSettingsResourceImpl.java @@ -49,14 +49,20 @@ public InternalResponse getDocCenterBaseUrl() { return InternalResponse.buildSuccessResp(globalSettingsService.getDocCenterBaseUrl()); } + @Override + public InternalResponse getDocJobRootUrl() { + return InternalResponse.buildSuccessResp(globalSettingsService.getDocJobRootUrl()); + } + @Override public InternalResponse getFileUploadSettings() { FileUploadSettingVO fileUploadSettingVO = globalSettingsService.getFileUploadSettings(); return InternalResponse.buildSuccessResp(convertToServiceFileUploadSettingDTO(fileUploadSettingVO)); } + private ServiceFileUploadSettingDTO convertToServiceFileUploadSettingDTO(FileUploadSettingVO fileUploadSettingVO) { ServiceFileUploadSettingDTO serviceFileUploadSettingDTO = new ServiceFileUploadSettingDTO(); - if(fileUploadSettingVO != null){ + if (fileUploadSettingVO != null) { serviceFileUploadSettingDTO.setSuffixList(fileUploadSettingVO.getSuffixList()); serviceFileUploadSettingDTO.setUnit(fileUploadSettingVO.getUnit()); serviceFileUploadSettingDTO.setAmount(fileUploadSettingVO.getAmount()); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/GlobalSettingsService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/GlobalSettingsService.java index 10f4fdb71a..569077824a 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/GlobalSettingsService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/GlobalSettingsService.java @@ -100,6 +100,8 @@ ChannelTemplateDetailWithDefaultVO getChannelTemplateDetail(String username, Str String getDocCenterBaseUrl(); + String getDocJobRootUrl(); + Map getRelatedSystemUrls(String username); Map getJobConfig(String username); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java index 2d62d19ff0..4a4f9f52ec 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java @@ -602,6 +602,27 @@ public List listChannelTemplateStatus(String username) return resultList; } + @Override + public String getDocJobRootUrl() { + String docCenterBaseUrl = getDocCenterBaseUrl(); + StringBuilder sb = new StringBuilder(docCenterBaseUrl); + sb.append("/markdown/"); + if (JobContextUtil.isEnglishLocale()) { + sb.append("ZH"); + } else { + sb.append("EN"); + } + sb.append("/JOB/"); + sb.append(getTwoDigitVersion()); + return sb.toString(); + } + + private String getTwoDigitVersion() { + String completeVersion = buildProperties.getVersion(); + String[] versionParts = completeVersion.split("\\."); + return versionParts[0] + "." + versionParts[1]; + } + @Override public String getDocCenterBaseUrl() { String url; @@ -656,7 +677,7 @@ public Map getRelatedSystemUrls(String username) { removeSuffixBackSlash(jobManageConfig.getCmdbServerUrl()) + jobManageConfig.getCmdbAppIndexPath()); urlMap.put(RelatedUrlKeys.KEY_BK_NODEMAN_ROOT_URL, getNodemanRootUrl()); urlMap.put(RelatedUrlKeys.KEY_BK_DOC_CENTER_ROOT_URL, getDocCenterBaseUrl()); - urlMap.put(RelatedUrlKeys.KEY_BK_DOC_JOB_ROOT_URL, getDocCenterBaseUrl()); + urlMap.put(RelatedUrlKeys.KEY_BK_DOC_JOB_ROOT_URL, getDocJobRootUrl()); urlMap.put(RelatedUrlKeys.KEY_BK_FEED_BACK_ROOT_URL, getFeedBackRootUrl()); urlMap.put(RelatedUrlKeys.KEY_BK_SHARED_RES_BASE_JS_URL, getBkSharedResBaseJsUrl()); return urlMap; diff --git a/support-files/sql/job-analysis/0008_job_analysis_20240920-2000_V3.9.6_mysql.sql b/support-files/sql/job-analysis/0008_job_analysis_20240920-2000_V3.9.6_mysql.sql new file mode 100644 index 0000000000..6363a82f45 --- /dev/null +++ b/support-files/sql/job-analysis/0008_job_analysis_20240920-2000_V3.9.6_mysql.sql @@ -0,0 +1,10 @@ +SET NAMES utf8mb4; +USE job_analysis; + +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (1, -1, -1, 2, '使用作业平台 Shell 脚本的内置函数 `job_success` `job_fail`,可以轻松实现简单的执行结果归类分组效果;更多使用技巧,详见[文档](${BK_DOC_JOB_ROOT_URL}/UserGuide/Best-Practices/Use-built-in-functions-to-make-exec-result-grouping.md)', 'Using built-in functions `job_success` `job_fail`, execution results can be grouped easily. Find out more tips with [Docs](${BK_DOC_JOB_ROOT_URL}/UserGuide/Best-Practices/Use-built-in-functions-to-make-exec-result-grouping.md)', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (2, -1, -1, 2, '如何让同一批主机在不同的步骤中享有独立的变量空间?这样在应对多批次机器执行同一场景时,而无需设置过多的字符串变量或数组索引;详见[文档](${BK_DOC_JOB_ROOT_URL}/UserGuide/Best-Practices/How-to-make-same-host-have-its-own-namespace.md)', 'How to make bunch of hosts own its independent variable space in different steps? In this way, when dealing with multiple hosts to execute the same scene, not necessary to set too many string variables or array indexes. For more information see [Docs](${BK_DOC_JOB_ROOT_URL}/UserGuide/Best-Practices/How-to-make-same-host-have-its-own-namespace.md)', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (3, -1, -1, 2, '脚本传参涉及到敏感信息(如密码)该如何规避因明文传输而导致信息泄露的风险?`密文` 变量可以帮你解决这个问题!', 'Params involves sensitive information (such as passwords). How to avoid the risk of information leakage? The `Ciphertext` variable can help you solve this problem!', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (4, -1, -1, 2, '为你的作业模板设置一个标签可以方便你更好的进行分类管理,在「作业」页面左侧可以快速通过分类标签找到你的作业模板。', 'Job tags can help you manage template classification better, you can easily toggle different tags in left side on Jobs page.', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (5, -1, -1, 2, '收藏的作业除了可以在列表中置顶,还会显示到首页中,这样你就能更快的找到你常用的作业了。', 'Favorited Jobs can be displayed on the top of the Job list, also in HOME page, so you can found it faster when you need it.', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (6, -1, -1, 2, '你知道么,Shell 也支持数组变量喔~ 写法示例: `var[0]=\'test1\'; var[1]=\'test2\';` 通过 `echo ${var[*]}` 可以打印变量的所有索引值,`echo ${#var[*]}` 可以打印变量一共有多少个索引。', 'You know what, Array variable is supported in Bash. How? `var[0]=\'test1\'; var[1]=\'test2\';` and using `echo ${var[*]}` to print all index values of Array variable, using `echo ${#var[*]}` to show how many index the Array variable has.', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); +REPLACE INTO `job_analysis`.`analysis_task_static_instance`(`id`, `app_id`, `task_id`, `status`, `result_data`, `result_data_en`, `priority`, `active`, `creator`, `last_modify_user`, `create_time`, `last_modify_time`) VALUES (7, -1, -1, 2, '当发现某个线上脚本出现严重漏洞时,如何快速止损?脚本版本管理的 `禁用` 可以帮到你,详见[文档](${BK_DOC_JOB_ROOT_URL}/UserGuide/Best-Practices/How-to-stop-the-spread-of-the-problem-script-immediately.md)', 'How to stop loss immediately when a serious bug in an online script is found? You can set the version status to `BANNED` in script version management. See [Docs](${BK_DOC_JOB_ROOT_URL}/UserGuide/Best-Practices/How-to-stop-the-spread-of-the-problem-script-immediately.md)', 100, b'1', 'admin', 'admin', 1583492717314, 1583492717318); From 04739708567e4f536ac44e2915be611f77f524b3 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Fri, 20 Sep 2024 20:53:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20=E6=A0=B9=E6=8D=AE=E8=93=9D?= =?UTF-8?q?=E9=B2=B8=E8=A7=84=E8=8C=83=E8=B0=83=E6=95=B4=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=20#3217?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加migrate日志 --- support-files/kubernetes/images/migration/startup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/support-files/kubernetes/images/migration/startup.sh b/support-files/kubernetes/images/migration/startup.sh index 9f7158fdd1..f017f74c47 100644 --- a/support-files/kubernetes/images/migration/startup.sh +++ b/support-files/kubernetes/images/migration/startup.sh @@ -30,7 +30,9 @@ function migrateMySQL(){ done for sql in "${ALL_SQL[@]}"; do + echo "migrate $sql" mysql -h $BK_JOB_MYSQL_HOST -P $BK_JOB_MYSQL_PORT -u$BK_JOB_MYSQL_ADMIN_USERNAME -p$BK_JOB_MYSQL_ADMIN_PASSWORD < $sql + echo "migrate $sql done" done } From 5bfaf0fc174bd58c6572ad5bb95db4233e262d63 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Fri, 20 Sep 2024 21:21:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?perf:=20=E6=A0=B9=E6=8D=AE=E8=93=9D?= =?UTF-8?q?=E9=B2=B8=E8=A7=84=E8=8C=83=E8=B0=83=E6=95=B4=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=20#3217?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/globalsetting/impl/GlobalSettingsServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java index 4a4f9f52ec..9717b5ece0 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/globalsetting/impl/GlobalSettingsServiceImpl.java @@ -608,9 +608,9 @@ public String getDocJobRootUrl() { StringBuilder sb = new StringBuilder(docCenterBaseUrl); sb.append("/markdown/"); if (JobContextUtil.isEnglishLocale()) { - sb.append("ZH"); - } else { sb.append("EN"); + } else { + sb.append("ZH"); } sb.append("/JOB/"); sb.append(getTwoDigitVersion());