Skip to content

Commit

Permalink
Merge pull request #1288 from jsonwan/github_perf/apm
Browse files Browse the repository at this point in the history
perf: 接入蓝鲸监控APM调用链追踪 #1161
  • Loading branch information
wangyu096 authored Sep 15, 2022
2 parents 7295760 + 08736a9 commit 5c90556
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ spring:
cloud:
config:
enabled: false
quartz:
thread-pool:
core-pool-size: 3
max-pool-size: 5
keep-alive-seconds: 60
queue-capacity: 3
waitfor-tasks-tocomplete-onshutdown: true
await-termination-seconds: 900
job:
security:
service:
Expand All @@ -47,4 +55,4 @@ notification-policy:
#通知频率:默认 5 - 每5次通知, 1 - 每次通知
frequency: 5
#通知次数:默认 -1 - 不限制通知次数, 0 - 不通知, 1 - 只通知1次,
totalTimes: -1
totalTimes: -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

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

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Slf4j
@Configuration
public class ExecutorConfiguration {

@Bean
public ThreadPoolTaskExecutor quartzTaskExecutor(QuartzProperties quartzProperties) {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(quartzProperties.getThreadPool().getCorePoolSize());
threadPoolTaskExecutor.setMaxPoolSize(quartzProperties.getThreadPool().getMaxPoolSize());
threadPoolTaskExecutor.setQueueCapacity(quartzProperties.getThreadPool().getQueueCapacity());
threadPoolTaskExecutor.setKeepAliveSeconds(quartzProperties.getThreadPool().getKeepAliveSeconds());
threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(
quartzProperties.getThreadPool().isWaitForTasksToCompleteOnShutdown());
threadPoolTaskExecutor.setAwaitTerminationSeconds(
quartzProperties.getThreadPool().getAwaitTerminationSeconds());

return threadPoolTaskExecutor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,14 @@ public QuartzConfig(PlatformTransactionManager transactionManager, QuartzPropert
}

@Bean
public ThreadPoolTaskExecutor quartzTaskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(quartzProperties.getThreadPool().getCorePoolSize());
threadPoolTaskExecutor.setMaxPoolSize(quartzProperties.getThreadPool().getMaxPoolSize());
threadPoolTaskExecutor.setQueueCapacity(quartzProperties.getThreadPool().getQueueCapacity());
threadPoolTaskExecutor.setKeepAliveSeconds(quartzProperties.getThreadPool().getKeepAliveSeconds());
threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(
quartzProperties.getThreadPool().isWaitForTasksToCompleteOnShutdown());
threadPoolTaskExecutor.setAwaitTerminationSeconds(
quartzProperties.getThreadPool().getAwaitTerminationSeconds());

return threadPoolTaskExecutor;
}

@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
public SchedulerFactoryBean schedulerFactoryBean(ThreadPoolTaskExecutor quartzTaskExecutor) {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setConfigLocation(quartzProperties.getScheduler().getConfigLocation());
// 此处设置数据源之后,会覆盖quartz.properties中的myDS数据源
schedulerFactoryBean.setDataSource(dataSource);
schedulerFactoryBean.setJobFactory(autowiredSpringBeanJobFactory);
schedulerFactoryBean.setSchedulerName(quartzProperties.getScheduler().getSchedulerName());
schedulerFactoryBean.setTaskExecutor(quartzTaskExecutor());
schedulerFactoryBean.setTaskExecutor(quartzTaskExecutor);
schedulerFactoryBean.setTransactionManager(transactionManager);
schedulerFactoryBean.setApplicationContextSchedulerContextKey(
quartzProperties.getScheduler().getApplicationContextSchedulerContextKey());
Expand All @@ -97,8 +82,8 @@ public SchedulerFactoryBean schedulerFactoryBean() {
}

@Bean
public Scheduler scheduler() {
return schedulerFactoryBean().getObject();
public Scheduler scheduler(SchedulerFactoryBean schedulerFactoryBean) {
return schedulerFactoryBean.getObject();
}

private Properties asProperties(Map<String, String> source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;

import java.util.HashMap;
Expand All @@ -36,7 +35,6 @@
* @since 1.0
*/
@Data
@Profile({"prod", "dev"})
@ConfigurationProperties(prefix = "spring.quartz")
public class QuartzProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public MeasureServiceImpl(MeterRegistry meterRegistry, ThreadPoolTaskExecutor qu
// 同步线程池监控:Agent状态
meterRegistry.gauge(
CronMetricsConstants.NAME_CRON_QUARTZ_TASK_EXECUTOR_POOL_SIZE,
Collections.singletonList(Tag.of(CronMetricsConstants.TAG_KEY_MODULE, CronMetricsConstants.TAG_VALUE_MODULE_CRON)),
Collections.singletonList(Tag.of(CronMetricsConstants.TAG_KEY_MODULE,
CronMetricsConstants.TAG_VALUE_MODULE_CRON)),
quartzTaskExecutor,
taskExecutor -> taskExecutor.getThreadPoolExecutor().getPoolSize()
);
meterRegistry.gauge(
CronMetricsConstants.NAME_CRON_QUARTZ_TASK_EXECUTOR_QUEUE_SIZE,
Collections.singletonList(Tag.of(CronMetricsConstants.TAG_KEY_MODULE, CronMetricsConstants.TAG_VALUE_MODULE_CRON)),
Collections.singletonList(Tag.of(CronMetricsConstants.TAG_KEY_MODULE,
CronMetricsConstants.TAG_VALUE_MODULE_CRON)),
quartzTaskExecutor,
taskExecutor -> taskExecutor.getThreadPoolExecutor().getQueue().size()
);
Expand Down

0 comments on commit 5c90556

Please sign in to comment.