Skip to content

Commit

Permalink
perf: 容器化Values暴露定时任务独立DB等生产环境需要的配置项 #2551
Browse files Browse the repository at this point in the history
暴露相关配置项
  • Loading branch information
jsonwan committed Nov 7, 2023
1 parent a451d4a commit 4004d93
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import com.tencent.bk.job.common.service.boot.JobBootApplication;
import com.tencent.bk.job.common.service.feature.config.FeatureToggleConfig;
import com.tencent.bk.job.crontab.config.JobQuartzProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration;
Expand All @@ -38,7 +37,7 @@
"com.tencent.bk.job.crontab"},
exclude = {JooqAutoConfiguration.class, ApplicationAvailabilityAutoConfiguration.class})
@EnableFeignClients(basePackages = {"com.tencent.bk.job.manage.api", "com.tencent.bk.job.execute.api"})
@EnableConfigurationProperties({FeatureToggleConfig.class, JobQuartzProperties.class})
@EnableConfigurationProperties({FeatureToggleConfig.class})
public class JobCrontabBootApplication {

public static void main(String[] args) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@

package com.tencent.bk.job.crontab.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.sql.DataSource;

Expand All @@ -40,54 +37,15 @@
*/
@Configuration
@Profile("!test")
@EnableConfigurationProperties({JobQuartzProperties.class})
public class QuartzConfig {

private final JobQuartzProperties jobQuartzProperties;

@Autowired
public QuartzConfig(JobQuartzProperties quartzProperties) {
this.jobQuartzProperties = quartzProperties;
}

@Bean("quartzTaskExecutor")
public ThreadPoolTaskExecutor quartzTaskExecutor() {
JobQuartzProperties.ThreadPool threadPoolConfig = jobQuartzProperties.getThreadPool();
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setThreadNamePrefix(threadPoolConfig.getThreadNamePrefix());
threadPoolTaskExecutor.setThreadGroupName(threadPoolConfig.getThreadGroupName());
threadPoolTaskExecutor.setDaemon(threadPoolConfig.isDaemon());
threadPoolTaskExecutor.setThreadPriority(threadPoolConfig.getThreadPriority());
threadPoolTaskExecutor.setCorePoolSize(threadPoolConfig.getCorePoolSize());
threadPoolTaskExecutor.setMaxPoolSize(threadPoolConfig.getMaxPoolSize());
threadPoolTaskExecutor.setQueueCapacity(threadPoolConfig.getQueueCapacity());
threadPoolTaskExecutor.setKeepAliveSeconds(threadPoolConfig.getKeepAliveSeconds());
threadPoolTaskExecutor.setAllowCoreThreadTimeOut(threadPoolConfig.isAllowCoreThreadTimeOut());
threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(
threadPoolConfig.isWaitForTasksToCompleteOnShutdown());
threadPoolTaskExecutor.setAwaitTerminationSeconds(
threadPoolConfig.getAwaitTerminationSeconds());

return threadPoolTaskExecutor;
}

@Bean
public SchedulerFactoryBeanCustomizer schedulerFactoryBeanCustomizer(
@Qualifier("quartzTaskExecutor") ThreadPoolTaskExecutor quartzTaskExecutor,
@Qualifier("job-crontab-data-source") DataSource dataSource) {
return schedulerFactoryBean -> {
// 自定义taskExecutor
schedulerFactoryBean.setTaskExecutor(quartzTaskExecutor);

// 自定义scheduler
schedulerFactoryBean.setSchedulerName(jobQuartzProperties.getScheduler().getSchedulerName());
schedulerFactoryBean.setApplicationContextSchedulerContextKey(
jobQuartzProperties.getScheduler().getApplicationContextSchedulerContextKey());
schedulerFactoryBean.setOverwriteExistingJobs(jobQuartzProperties.getScheduler().isOverwriteExistingJobs());
schedulerFactoryBean.setAutoStartup(jobQuartzProperties.getScheduler().isAutoStartup());
schedulerFactoryBean.setStartupDelay(jobQuartzProperties.getScheduler().getStartupDelay());
schedulerFactoryBean.setOverwriteExistingJobs(true);
schedulerFactoryBean.setStartupDelay(10);
schedulerFactoryBean.setDataSource(dataSource);
};

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,8 @@
package com.tencent.bk.job.crontab.metrics;

public class CronMetricsConstants {
/**
* Quartz工作线程池线程数
*/
public static final String NAME_CRON_QUARTZ_TASK_EXECUTOR_POOL_SIZE = "cron.quartz.task.executor.pool.size";
/**
* Quartz工作线程池队列大小
*/
public static final String NAME_CRON_QUARTZ_TASK_EXECUTOR_QUEUE_SIZE = "cron.quartz.task.executor.queue.size";
/**
* 定时任务调度延迟指标
*/
public static final String NAME_JOB_CRON_SCHEDULE_DELAY = "job.cron.schedule.delay";

public static final String TAG_KEY_MODULE = "module";

public static final String TAG_VALUE_MODULE_CRON = "cron";
}

This file was deleted.

16 changes: 16 additions & 0 deletions support-files/kubernetes/charts/bk-job/VALUES_LOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# chart values 更新日志

## 0.5.4
1. 增加定时任务服务独立数据库配置(若不配置该项则使用与其他服务共用的公共数据库),默认无需配置

```yaml
## job-crontab定时任务配置
crontabConfig:
# 定时任务服务独立数据库配置,若不配置该项则使用与其他服务共用的公共数据库
database:
host: ""
port: 3306
connection:
properties: ?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
username: "job"
password: "job"
```
## 0.5.3
1. 增加操作审计相关配置
Expand Down
28 changes: 27 additions & 1 deletion support-files/kubernetes/charts/bk-job/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ Return the Archive MariaDB secret name
{{ printf "%s-%s" (include "job.fullname" .) "archive-mariadb" }}
{{- end -}}


{{/*
Return the storage PVC name
*/}}
Expand All @@ -683,3 +682,30 @@ Return the job pod terminationGracePeriodSeconds
{{- define "job.podTerminationGracePeriodSeconds" -}}
terminationGracePeriodSeconds: {{ .Values.podTerminationGracePeriodSeconds }}
{{- end -}}

{{/*
Return the Crontab DB secret name
*/}}
{{- define "job.crontabdb.secretName" -}}
{{ printf "%s-%s" (include "job.fullname" .) "crontab-db" }}
{{- end -}}


{{/*
Return the job crontab database config
*/}}
{{- define "job.crontab.databaseConfig" -}}
{{- if .Values.crontabConfig.database.host -}}
jdbc-url: {{ include "job.jdbcMysqlScheme" . }}://{{- .Values.crontabConfig.database.host }}:{{- .Values.crontabConfig.database.port }}/job_crontab{{- .Values.crontabConfig.database.connection.properties }}
username: {{ .Values.crontabConfig.database.username }}
password: ${crontab-db-password}
{{- else -}}
jdbc-url: {{ include "job.jdbcMysqlScheme" . }}://{{- include "job.mariadb.host" . }}:{{- include "job.mariadb.port" . }}/job_crontab{{ include "job.mariadb.connection.properties" . }}
username: {{ include "job.mariadb.username" . }}
{{- if .Values.externalMariaDB.existingPasswordSecret }}
password: {{ .Values.externalMariaDB.existingPasswordKey | default "mariadb-password" | printf "${%s}" }}
{{- else }}
password: ${mariadb-password}
{{- end }}
{{- end }}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ data:
max-file-size: 5GB
max-request-size: 5GB
feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 300000
{{- toYaml .Values.analysisConfig.feign | nindent 6 }}
server:
port: {{ .Values.analysisConfig.containerPort }}
{{- end }}
Loading

0 comments on commit 4004d93

Please sign in to comment.