From 36e46582168f06beaa0cf478c55ba13b844168ad Mon Sep 17 00:00:00 2001 From: emeroad Date: Tue, 26 Sep 2023 18:49:36 +0900 Subject: [PATCH] [#noissue] Refactor Executor Configuration --- batch/pom.xml | 5 +- .../collector/PinpointCollectorModule.java | 7 +- .../config/BatchHbaseClientConfiguration.java | 2 +- .../config/CollectorConfiguration.java | 62 ++++++ .../collector/config/CollectorProperties.java | 21 -- .../collector/config/ExecutorProperties.java | 94 --------- .../config/CollectorGrpcConfiguration.java | 43 ++++ .../GrpcAgentDataReceiverConfiguration.java | 91 ++++---- .../GrpcAgentDataReceiverProperties.java | 40 ---- .../grpc/config/GrpcReceiverProperties.java | 35 +--- .../config/GrpcSpanReceiverConfiguration.java | 95 +++++---- .../config/GrpcSpanReceiverProperties.java | 39 ---- .../config/GrpcStatReceiverConfiguration.java | 93 ++++---- .../config/GrpcStatReceiverProperties.java | 39 ---- .../grpc/config/GrpcStreamProperties.java | 119 ++++------- .../config/GrpcStreamReceiverProperties.java | 15 +- ...GrpcAgentDataSslReceiverConfiguration.java | 4 +- .../ssl/GrpcSpanSslReceiverConfiguration.java | 4 +- .../ssl/GrpcStatSslReceiverConfiguration.java | 2 + .../MonitoredThreadPoolExecutorFactory.java | 85 ++++++++ .../monitor/MonitoringExecutors.java | 61 ++++++ .../collector/receiver/BindAddress.java | 14 +- .../receiver/ExecutorFactoryBean.java | 91 +------- .../applicationContext-collector-grpc.xml | 49 +---- .../applicationContext-collector.xml | 23 -- .../pinpoint-collector-root.properties | 5 +- .../local/pinpoint-collector-grpc.properties | 49 +++-- .../pinpoint-collector-grpc.properties | 49 +++-- ...rpcAgentDataReceiverConfigurationTest.java | 87 ++++++-- .../GrpcSpanReceiverConfigurationTest.java | 93 ++++++-- .../GrpcStatReceiverConfigurationTest.java | 91 ++++++-- .../grpc/config/TestReceiverConfig.java | 36 ++++ ...AgentDataSslReceiverConfigurationTest.java | 20 +- .../GrpcSpanSslReceiverConfigurationTest.java | 21 +- .../GrpcStatSslReceiverConfigurationTest.java | 21 +- .../MonitoredThreadPoolExecutorTest.java | 2 - .../receiver/grpc/SpanServerTestMain.java | 10 +- .../receiver/grpc/StatServerTestMain.java | 10 +- .../test-pinpoint-collector.properties | 198 ------------------ commons-config/pom.xml | 4 + .../config/executor/ExecutorProperties.java | 33 ++- .../ThreadPoolExecutorCustomizer.java | 4 +- .../config/HbaseClientConfiguration.java | 4 +- .../profiler/logging/ThrottledLogger.java | 5 +- .../thread/MonitoringExecutorProperties.java | 63 ++++++ .../common/server/util/CallerUtils.java | 68 ++++++ .../common/server/util/CallerUtilsTest.java | 62 ++++++ flink/pom.xml | 4 + .../navercorp/pinpoint/flink/FlinkModule.java | 26 ++- .../flink/config/DataReceiverProperties.java | 32 --- .../config/FlinkExecutorConfiguration.java | 68 ++++++ .../applicationContext-flink-clean.xml | 8 - .../applicationContext-flink-profile.xml | 29 --- .../resources/applicationContext-flink.xml | 17 -- .../resources/applicationContext-hbase.xml | 3 +- .../profiles/local/pinpoint-flink.properties | 10 +- .../release/pinpoint-flink.properties | 10 +- .../config/DataReceiverPropertiesTest.java | 42 +++- .../grpc/GrpcLogReceiverProperties.java | 6 +- .../grpc/GrpcLogReceiverPropertiesConfig.java | 30 ++- .../grpc/LogCollectorGrpcServerConfig.java | 71 ++----- .../pinpoint-collector-log-grpc.properties | 17 +- .../pinpoint-collector-log-grpc.properties | 21 +- .../local/pinpoint-collector-grpc.properties | 54 +++-- .../pinpoint-collector-grpc.properties | 54 +++-- web/pom.xml | 4 + .../config/ApplicationMapModule.java | 28 ++- .../config/BasicExecutorCustomizer.java | 49 ----- .../config/ExecutorCustomizer.java | 25 --- .../config/ExecutorProperties.java | 39 ---- .../config/TaskExecutorCustomizer.java | 55 +++++ .../pinpoint/web/realtime/RealtimeConfig.java | 2 +- .../resources/pinpoint-web-root.properties | 13 +- 73 files changed, 1431 insertions(+), 1354 deletions(-) create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorConfiguration.java delete mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/config/ExecutorProperties.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/CollectorGrpcConfiguration.java delete mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverProperties.java delete mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverProperties.java delete mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverProperties.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactory.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoringExecutors.java create mode 100644 collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java delete mode 100644 collector/src/test/resources/test-pinpoint-collector.properties create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/thread/MonitoringExecutorProperties.java create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/CallerUtils.java create mode 100644 commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/CallerUtilsTest.java create mode 100644 flink/src/main/java/com/navercorp/pinpoint/flink/config/FlinkExecutorConfiguration.java delete mode 100644 flink/src/main/resources/applicationContext-flink-clean.xml delete mode 100644 flink/src/main/resources/applicationContext-flink-profile.xml delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/BasicExecutorCustomizer.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorCustomizer.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorProperties.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/TaskExecutorCustomizer.java diff --git a/batch/pom.xml b/batch/pom.xml index 122091ee6406..ff2214a60be0 100644 --- a/batch/pom.xml +++ b/batch/pom.xml @@ -99,7 +99,10 @@ org.springframework.boot spring-boot-starter-log4j2 - + + org.springframework.boot + spring-boot-starter-validation + org.springframework diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/PinpointCollectorModule.java b/collector/src/main/java/com/navercorp/pinpoint/collector/PinpointCollectorModule.java index ba1a703eb555..7759b66d9f5c 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/PinpointCollectorModule.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/PinpointCollectorModule.java @@ -2,10 +2,12 @@ import com.navercorp.pinpoint.collector.config.ClusterModule; +import com.navercorp.pinpoint.collector.config.CollectorConfiguration; import com.navercorp.pinpoint.collector.config.CollectorProperties; import com.navercorp.pinpoint.collector.config.FlinkContextModule; import com.navercorp.pinpoint.collector.config.MetricConfiguration; import com.navercorp.pinpoint.collector.event.config.CollectorEventConfiguration; +import com.navercorp.pinpoint.collector.grpc.config.CollectorGrpcConfiguration; import com.navercorp.pinpoint.collector.grpc.ssl.GrpcSslModule; import com.navercorp.pinpoint.common.server.CommonsServerConfiguration; import com.navercorp.pinpoint.common.server.config.TypeLoaderConfiguration; @@ -21,7 +23,7 @@ "classpath:applicationContext-collector.xml", "classpath:servlet-context-collector.xml", - "classpath:applicationContext-collector-grpc.xml", + }) @Import({ CollectorAppPropertySources.class, @@ -29,8 +31,11 @@ TypeLoaderConfiguration.class, FlinkContextModule.class, + CollectorConfiguration.class, CollectorHbaseModule.class, + CollectorGrpcConfiguration.class, + CollectorEventConfiguration.class, ClusterModule.class, diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/config/BatchHbaseClientConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/config/BatchHbaseClientConfiguration.java index 5dfe3e0348d4..75b3670939e4 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/config/BatchHbaseClientConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/config/BatchHbaseClientConfiguration.java @@ -37,7 +37,7 @@ public FactoryBean batchConnectionFactory(Configuration configuratio } @Bean - public FactoryBean batchHbaseThreadPool(ExecutorCustomizer executorCustomizer, + public FactoryBean batchHbaseThreadPool(@Qualifier("hbaseExecutorCustomizer") ExecutorCustomizer executorCustomizer, @Qualifier("hbaseClientExecutorProperties") com.navercorp.pinpoint.common.config.executor.ExecutorProperties properties) { ThreadPoolExecutorFactoryBean factory = new ThreadPoolExecutorFactoryBean(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorConfiguration.java new file mode 100644 index 000000000000..f49cd1634146 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorConfiguration.java @@ -0,0 +1,62 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.collector.config; + +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import com.navercorp.pinpoint.common.config.executor.ExecutorProperties; +import com.navercorp.pinpoint.common.config.executor.ThreadPoolExecutorCustomizer; +import com.navercorp.pinpoint.common.server.util.CallerUtils; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; +import org.springframework.validation.annotation.Validated; + +import java.util.concurrent.ExecutorService; + +@Configuration +public class CollectorConfiguration { + + @Bean + public ExecutorCustomizer collectorExecutorCustomizer() { + return new ThreadPoolExecutorCustomizer(); + } + + @Bean + @Validated + @ConfigurationProperties(prefix="collector.agent-event-worker") + public ExecutorProperties agentEventWorkerExecutorProperties() { + return new ExecutorProperties(); + } + + @Bean + public FactoryBean agentEventWorker(@Qualifier("collectorExecutorCustomizer") ExecutorCustomizer executorCustomizer, + @Qualifier("agentEventWorkerExecutorProperties") ExecutorProperties properties) { + + ThreadPoolExecutorFactoryBean factory = new ThreadPoolExecutorFactoryBean(); + executorCustomizer.customize(factory, properties); + + String beanName = CallerUtils.getCallerMethodName(); + factory.setThreadNamePrefix(beanName); + return factory; + } + + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorProperties.java index 55a61a082016..34d6043396d3 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorProperties.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/config/CollectorProperties.java @@ -34,10 +34,6 @@ public class CollectorProperties { private final Logger logger = LogManager.getLogger(getClass()); - @Value("${collector.agentEventWorker.threadSize:32}") - private int agentEventWorkerThreadSize; - @Value("${collector.agentEventWorker.queueSize:5120}") - private int agentEventWorkerQueueSize; @Value("${collector.l4.ip:}") private String[] l4IpList = new String[0]; @Value("${collector.metric.jmx:false}") @@ -50,21 +46,6 @@ public class CollectorProperties { @Value("${collector.statistics.agent-state.enable:false}") private boolean statisticsAgentStateEnable; - public int getAgentEventWorkerThreadSize() { - return this.agentEventWorkerThreadSize; - } - - public void setAgentEventWorkerThreadSize(int agentEventWorkerThreadSize) { - this.agentEventWorkerThreadSize = agentEventWorkerThreadSize; - } - - public int getAgentEventWorkerQueueSize() { - return agentEventWorkerQueueSize; - } - - public void setAgentEventWorkerQueueSize(int agentEventWorkerQueueSize) { - this.agentEventWorkerQueueSize = agentEventWorkerQueueSize; - } public List getL4IpList() { return List.of(l4IpList); @@ -117,8 +98,6 @@ public void log() { @Override public String toString() { final StringBuilder sb = new StringBuilder("CollectorConfiguration{"); - sb.append("agentEventWorkerThreadSize=").append(agentEventWorkerThreadSize); - sb.append(", agentEventWorkerQueueSize=").append(agentEventWorkerQueueSize); sb.append(", l4IpList=").append(Arrays.toString(l4IpList)); sb.append(", metricJmxEnable=").append(metricJmxEnable); sb.append(", metricJmxDomainName='").append(metricJmxDomainName).append('\''); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/config/ExecutorProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/config/ExecutorProperties.java deleted file mode 100644 index 8f928ddbe963..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/config/ExecutorProperties.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2021 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.collector.config; - -/** - * @author emeroad - */ -public class ExecutorProperties { - private final int threadSize; - private final int queueSize; - private final boolean monitorEnable; - - public ExecutorProperties(int threadSize, int queueSize, boolean monitorEnable) { - this.threadSize = threadSize; - this.queueSize = queueSize; - this.monitorEnable = monitorEnable; - } - - public int getThreadSize() { - return threadSize; - } - - public int getQueueSize() { - return queueSize; - } - - public boolean isMonitorEnable() { - return monitorEnable; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public static class Builder { - private int threadSize = 128; - private int queueSize = 1024 * 5; - private boolean monitorEnable; - - Builder() { - } - - public int getThreadSize() { - return threadSize; - } - - public void setThreadSize(int threadSize) { - this.threadSize = threadSize; - } - - public int getQueueSize() { - return queueSize; - } - - public void setQueueSize(int queueSize) { - this.queueSize = queueSize; - } - - public boolean isMonitorEnable() { - return monitorEnable; - } - - public void setMonitorEnable(boolean monitorEnable) { - this.monitorEnable = monitorEnable; - } - - public ExecutorProperties build() { - return new ExecutorProperties(this.threadSize, this.queueSize, this.monitorEnable); - } - } - - @Override - public String toString() { - return "ExecutorConfiguration{" + - "threadSize=" + threadSize + - ", queueSize=" + queueSize + - ", monitorEnable=" + monitorEnable + - '}'; - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/CollectorGrpcConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/CollectorGrpcConfiguration.java new file mode 100644 index 000000000000..20cd429deb6c --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/CollectorGrpcConfiguration.java @@ -0,0 +1,43 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.collector.grpc.config; + +import com.codahale.metrics.MetricRegistry; +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; + +@Configuration +@ImportResource({ + "classpath:applicationContext-collector-grpc.xml" +}) +public class CollectorGrpcConfiguration { + + @Bean + public MonitoringExecutors monitoringExecutors( + @Qualifier("collectorExecutorCustomizer") ExecutorCustomizer customizer, + @Autowired(required = false) MetricRegistry metricRegistry) { + return new MonitoringExecutors(customizer, metricRegistry); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfiguration.java index e41eb6bad9eb..0155881592b5 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfiguration.java @@ -16,13 +16,19 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; +import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.server.ServerOption; +import org.springframework.beans.factory.FactoryBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.validation.annotation.Validated; + +import java.util.concurrent.ExecutorService; /** * @author emeroad @@ -30,63 +36,76 @@ @Configuration public class GrpcAgentDataReceiverConfiguration { - public static final String BIND_ADDRESS = "collector.receiver.grpc.agent.bindaddress"; - - public static final String SERVER_EXECUTOR = "collector.receiver.grpc.agent.server.executor"; - - public static final String SERVER_CALL_EXECUTOR = "collector.receiver.grpc.agent.server-call.executor"; - - public static final String WORKER_EXECUTOR = "collector.receiver.grpc.agent.worker.executor"; - - public static final String SERVER_OPTION = "collector.receiver.grpc.agent"; - public GrpcAgentDataReceiverConfiguration() { } - @Bean(BIND_ADDRESS) - @ConfigurationProperties(BIND_ADDRESS) - public BindAddress.Builder newBindAddressBuilder() { + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.agent.bindaddress") + public BindAddress.Builder grpcAgentBindAddressBuilder() { BindAddress.Builder builder = BindAddress.newBuilder(); builder.setPort(9991); return builder; } - @Bean(SERVER_EXECUTOR) - @ConfigurationProperties(SERVER_EXECUTOR) - public ExecutorProperties.Builder newServerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.agent.server.executor") + public MonitoringExecutorProperties grpcAgentServerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(SERVER_CALL_EXECUTOR) - @ConfigurationProperties(SERVER_CALL_EXECUTOR) - public ExecutorProperties.Builder newServerCallExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.agent.server-call.executor") + public MonitoringExecutorProperties grpcAgentServerCallExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(WORKER_EXECUTOR) - @ConfigurationProperties(WORKER_EXECUTOR) - public ExecutorProperties.Builder newWorkerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.agent.worker.executor") + public MonitoringExecutorProperties grpcAgentWorkerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(SERVER_OPTION) - @ConfigurationProperties(SERVER_OPTION) - public GrpcPropertiesServerOptionBuilder newServerOption() { + @Bean + @ConfigurationProperties("collector.receiver.grpc.agent") + public GrpcPropertiesServerOptionBuilder grpcAgentServerOption() { // Server option return new GrpcPropertiesServerOptionBuilder(); } @Bean - public GrpcAgentDataReceiverProperties grpcAgentReceiverProperties(Environment environment) { + public GrpcReceiverProperties grpcAgentReceiverProperties(Environment environment) { boolean enable = environment.getProperty("collector.receiver.grpc.agent.enable", boolean.class, false); - ServerOption serverOption = newServerOption().build(); - BindAddress bindAddress = newBindAddressBuilder().build(); - ExecutorProperties serverExecutor = newServerExecutorBuilder().build(); - ExecutorProperties serverCallExecutor = newServerCallExecutorBuilder().build(); - ExecutorProperties workerExecutor = newWorkerExecutorBuilder().build(); + ServerOption serverOption = grpcAgentServerOption().build(); + BindAddress bindAddress = grpcAgentBindAddressBuilder().build(); + + return new GrpcReceiverProperties(enable, bindAddress, serverOption); + } + + @Bean + public FactoryBean grpcAgentWorkerExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcAgentWorkerExecutorProperties(); + return executors.newExecutorFactoryBean(properties, beanName); + } + - return new GrpcAgentDataReceiverProperties(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption); + @Bean + public FactoryBean grpcAgentServerExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcAgentServerExecutorProperties(); + return executors.newExecutorFactoryBean(properties, beanName); } + @Bean + public FactoryBean grpcAgentServerCallExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcAgentServerCallExecutorProperties(); + properties.setLogRate(1); + return executors.newExecutorFactoryBean(properties, beanName); + } } \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverProperties.java deleted file mode 100644 index cd126c1ef633..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverProperties.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2021 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.collector.grpc.config; - -import com.navercorp.pinpoint.collector.config.ExecutorProperties; -import com.navercorp.pinpoint.collector.receiver.BindAddress; -import com.navercorp.pinpoint.grpc.server.ServerOption; - -/** - * Marker class for debugging - * @author Taejin Koo - * @author emeroad - */ -public class GrpcAgentDataReceiverProperties extends GrpcReceiverProperties { - - - public GrpcAgentDataReceiverProperties(boolean enable, - BindAddress bindAddress, - ExecutorProperties serverExecutor, - ExecutorProperties serverCallExecutor, - ExecutorProperties workerExecutor, - ServerOption serverOption) { - super(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption); - } - -} \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcReceiverProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcReceiverProperties.java index 6a0839db1284..d122c5dd34ee 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcReceiverProperties.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcReceiverProperties.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; import com.navercorp.pinpoint.collector.receiver.BindAddress; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.apache.logging.log4j.LogManager; @@ -37,27 +36,14 @@ public class GrpcReceiverProperties { private final BindAddress bindAddress; - private final ExecutorProperties serverExecutor; - - private final ExecutorProperties serverCallExecutor; - - private final ExecutorProperties workerExecutor; - private final ServerOption serverOption; protected GrpcReceiverProperties(boolean enable, - BindAddress bindAddress, - ExecutorProperties serverExecutor, - ExecutorProperties serverCallExecutor, - ExecutorProperties workerExecutor, - ServerOption serverOption) { + BindAddress bindAddress, + ServerOption serverOption) { this.enable = enable; this.serverOption = Objects.requireNonNull(serverOption, "serverOption"); - this.bindAddress = Objects.requireNonNull(bindAddress, "bindAddress"); - this.serverExecutor = Objects.requireNonNull(serverExecutor, "serverExecutor"); - this.serverCallExecutor = Objects.requireNonNull(serverCallExecutor, "serverCallExecutor"); - this.workerExecutor = Objects.requireNonNull(workerExecutor, "workerExecutor"); } @@ -65,9 +51,6 @@ protected GrpcReceiverProperties(boolean enable, public void log() { this.logger.info("enable:{}", this.enable); this.logger.info("bindAddress:{}", bindAddress); - this.logger.info("serverExecutor:{}", serverExecutor); - this.logger.info("serverCallExecutor:{}", serverCallExecutor); - this.logger.info("workerExecutor:{}", workerExecutor); this.logger.info("serverOption:{}", serverOption); } @@ -79,17 +62,6 @@ public BindAddress getBindAddress() { return bindAddress; } - public ExecutorProperties getServerExecutor() { - return serverExecutor; - } - - public ExecutorProperties getServerCallExecutor() { - return serverCallExecutor; - } - - public ExecutorProperties getWorkerExecutor() { - return workerExecutor; - } public ServerOption getServerOption() { return serverOption; @@ -99,9 +71,6 @@ public ServerOption getServerOption() { public String toString() { return "GrpcAgentDataReceiverProperties{" + "enable=" + enable + ", bindAddress='" + bindAddress + '\'' + - ", serverExecutor=" + serverExecutor + - ", serverCallExecutor=" + serverCallExecutor + - ", workerExecutor=" + workerExecutor + ", serverOption=" + serverOption + '}'; } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfiguration.java index ccd0aab7b279..925201197136 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfiguration.java @@ -16,13 +16,19 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; +import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.server.ServerOption; +import org.springframework.beans.factory.FactoryBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.validation.annotation.Validated; + +import java.util.concurrent.ExecutorService; /** @@ -31,74 +37,77 @@ @Configuration public class GrpcSpanReceiverConfiguration { - public static final String BIND_ADDRESS = "collector.receiver.grpc.span.bindaddress"; - - public static final String SERVER_EXECUTOR = "collector.receiver.grpc.span.server.executor"; - - public static final String SERVER_CALL_EXECUTOR = "collector.receiver.grpc.span.server-call.executor"; - - public static final String WORKER_EXECUTOR = "collector.receiver.grpc.span.worker.executor"; - - public static final String STREAM = "collector.receiver.grpc.span.stream"; - - public static final String SERVER_OPTION = "collector.receiver.grpc.span"; - public GrpcSpanReceiverConfiguration() { } - @Bean(BIND_ADDRESS) - @ConfigurationProperties(BIND_ADDRESS) - public BindAddress.Builder newBindAddressBuilder() { + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.span.bindaddress") + public BindAddress.Builder grpcSpanBindAddressBuilder() { BindAddress.Builder builder = BindAddress.newBuilder(); builder.setPort(9993); return builder; } - @Bean(SERVER_EXECUTOR) - @ConfigurationProperties(SERVER_EXECUTOR) - public ExecutorProperties.Builder newServerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.span.server.executor") + public MonitoringExecutorProperties grpcSpanServerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(SERVER_CALL_EXECUTOR) - @ConfigurationProperties(SERVER_CALL_EXECUTOR) - public ExecutorProperties.Builder newServerCallExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.span.server-call.executor") + public MonitoringExecutorProperties grpcSpanServerCallExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(WORKER_EXECUTOR) - @ConfigurationProperties(WORKER_EXECUTOR) - public ExecutorProperties.Builder newWorkerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.span.worker.executor") + public MonitoringExecutorProperties grpcSpanWorkerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(STREAM) - @ConfigurationProperties(STREAM) - public GrpcStreamProperties.Builder newStreamConfigurationBuilder() { - return GrpcStreamProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.span.stream") + public GrpcStreamProperties grpcSpanStreamProperties() { + return new GrpcStreamProperties(); } - @Bean(SERVER_OPTION) - @ConfigurationProperties(SERVER_OPTION) - public GrpcPropertiesServerOptionBuilder newServerOption() { + @Bean + @ConfigurationProperties("collector.receiver.grpc.span") + public GrpcPropertiesServerOptionBuilder grpcSpanServerOption() { // Server option return new GrpcPropertiesServerOptionBuilder(); } @Bean - public GrpcSpanReceiverProperties grpcSpanReceiverProperties(Environment environment) { + public GrpcReceiverProperties grpcSpanReceiverProperties(Environment environment) { boolean enable = environment.getProperty("collector.receiver.grpc.span.enable", boolean.class, false); - ServerOption serverOption = newServerOption().build(); + ServerOption serverOption = grpcSpanServerOption().build(); - BindAddress bindAddress = newBindAddressBuilder().build(); - ExecutorProperties serverExecutor = newServerExecutorBuilder().build(); - ExecutorProperties serverCallExecutor = newServerCallExecutorBuilder().build(); - ExecutorProperties workerExecutor = newWorkerExecutorBuilder().build(); + BindAddress bindAddress = grpcSpanBindAddressBuilder().build(); + + return new GrpcReceiverProperties(enable, bindAddress, serverOption); + } - GrpcStreamProperties streamConfiguration = newStreamConfigurationBuilder().build(); - return new GrpcSpanReceiverProperties(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption, streamConfiguration); + @Bean + public FactoryBean grpcSpanWorkerExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcSpanWorkerExecutorProperties(); + return executors.newExecutorFactoryBean(properties, beanName); + } + + @Bean + public FactoryBean grpcSpanServerExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcSpanServerExecutorProperties(); + return executors.newExecutorFactoryBean(properties, beanName); } } \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverProperties.java deleted file mode 100644 index 3297ab35bd96..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverProperties.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.collector.grpc.config; - -import com.navercorp.pinpoint.collector.config.ExecutorProperties; -import com.navercorp.pinpoint.collector.receiver.BindAddress; -import com.navercorp.pinpoint.grpc.server.ServerOption; - -/** - * Marker class for debugging - * @author Taejin Koo - * @author emeroad - */ -public class GrpcSpanReceiverProperties extends GrpcStreamReceiverProperties { - - public GrpcSpanReceiverProperties(boolean enable, BindAddress bindAddress, - ExecutorProperties serverExecutor, - ExecutorProperties serverCallExecutor, - ExecutorProperties workerExecutor, - ServerOption serverOption, - GrpcStreamProperties streamConfiguration) { - super(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption, streamConfiguration); - } - -} \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfiguration.java index 12f108025772..0d2b7ace6940 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfiguration.java @@ -16,13 +16,20 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; +import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.server.ServerOption; +import jakarta.inject.Provider; +import org.springframework.beans.factory.FactoryBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.validation.annotation.Validated; + +import java.util.concurrent.ExecutorService; /** @@ -31,76 +38,72 @@ @Configuration public class GrpcStatReceiverConfiguration { - public static final String BIND_ADDRESS = "collector.receiver.grpc.stat.bindaddress"; - - public static final String SERVER_EXECUTOR = "collector.receiver.grpc.stat.server.executor"; - - public static final String SERVER_CALL_EXECUTOR = "collector.receiver.grpc.stat.server-call.executor"; - - public static final String WORKER_EXECUTOR = "collector.receiver.grpc.stat.worker.executor"; - - public static final String STREAM = "collector.receiver.grpc.stat.stream"; - - public static final String SERVER_OPTION = "collector.receiver.grpc.stat"; - public GrpcStatReceiverConfiguration() { } - @Bean(BIND_ADDRESS) - @ConfigurationProperties(BIND_ADDRESS) - public BindAddress.Builder newBindAddressBuilder() { + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.stat.bindaddress") + public Provider grpcStatBindAddressBuilder() { BindAddress.Builder builder = BindAddress.newBuilder(); builder.setPort(9992); return builder; } - @Bean(SERVER_EXECUTOR) - @ConfigurationProperties(SERVER_EXECUTOR) - public ExecutorProperties.Builder newServerExecutorBuilder() { - return ExecutorProperties.newBuilder(); - } - - @Bean(SERVER_CALL_EXECUTOR) - @ConfigurationProperties(SERVER_CALL_EXECUTOR) - public ExecutorProperties.Builder newServerCallExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.stat.server.executor") + public MonitoringExecutorProperties grpcStatServerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(WORKER_EXECUTOR) - @ConfigurationProperties(WORKER_EXECUTOR) - public ExecutorProperties.Builder newWorkerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.stat.worker.executor") + public MonitoringExecutorProperties grpcStatWorkerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(STREAM) - @ConfigurationProperties(STREAM) - public GrpcStreamProperties.Builder newStreamConfigurationBuilder() { - return GrpcStreamProperties.newBuilder(); + @Bean + @Validated + @ConfigurationProperties("collector.receiver.grpc.stat.stream") + public GrpcStreamProperties grpcStatStreamProperties() { + return new GrpcStreamProperties(); } - @Bean(SERVER_OPTION) - @ConfigurationProperties(SERVER_OPTION) - public GrpcPropertiesServerOptionBuilder newServerOption() { + @Bean + @ConfigurationProperties("collector.receiver.grpc.stat") + public GrpcPropertiesServerOptionBuilder grpcStatServerOption() { // Server option return new GrpcPropertiesServerOptionBuilder(); } @Bean - public GrpcStatReceiverProperties grpcStatReceiverProperties( + public GrpcReceiverProperties grpcStatReceiverProperties( Environment environment) { boolean enable = environment.getProperty("collector.receiver.grpc.stat.enable", boolean.class, false); - ServerOption serverOption = newServerOption().build(); + ServerOption serverOption = grpcStatServerOption().build(); + + BindAddress bindAddress = grpcStatBindAddressBuilder().get(); - BindAddress bindAddress = newBindAddressBuilder().build(); - ExecutorProperties serverExecutor = newServerExecutorBuilder().build(); - ExecutorProperties serverCallExecutor = newServerCallExecutorBuilder().build(); - ExecutorProperties workerExecutor = newWorkerExecutorBuilder().build(); + return new GrpcReceiverProperties(enable, bindAddress, serverOption); + } - GrpcStreamProperties streamConfiguration = newStreamConfigurationBuilder().build(); - return new GrpcStatReceiverProperties(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption, streamConfiguration); + @Bean + public FactoryBean grpcStatWorkerExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcStatWorkerExecutorProperties(); + return executors.newExecutorFactoryBean(properties, beanName); + } + + @Bean + public FactoryBean grpcStatServerExecutor(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = grpcStatServerExecutorProperties(); + return executors.newExecutorFactoryBean(properties, beanName); } } \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverProperties.java deleted file mode 100644 index e8929c1c0f9f..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverProperties.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.collector.grpc.config; - -import com.navercorp.pinpoint.collector.config.ExecutorProperties; -import com.navercorp.pinpoint.collector.receiver.BindAddress; -import com.navercorp.pinpoint.grpc.server.ServerOption; - -/** - * Marker class for debugging - * @author Taejin Koo - * @author emeroad - */ -public class GrpcStatReceiverProperties extends GrpcStreamReceiverProperties { - - public GrpcStatReceiverProperties(boolean enable, BindAddress bindAddress, - ExecutorProperties serverExecutor, - ExecutorProperties serverCallExecutor, - ExecutorProperties workerExecutor, - ServerOption serverOption, - GrpcStreamProperties streamConfiguration) { - super(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption, streamConfiguration); - } - -} \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamProperties.java index e6ef2b30f6ec..a83ed0a09ed6 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamProperties.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamProperties.java @@ -16,115 +16,72 @@ package com.navercorp.pinpoint.collector.grpc.config; -public class GrpcStreamProperties { - private final int schedulerThreadSize; - private final int callInitRequestCount; - private final int schedulerPeriodMillis; - private final int schedulerRecoveryMessageCount; - private final long idleTimeout; - private final long throttledLoggerRatio; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; - GrpcStreamProperties(int schedulerThreadSize, int callInitRequestCount, - int schedulerPeriodMillis, int schedulerRecoveryMessageCount, - long idleTimeout, long throttledLoggerRatio) { - this.schedulerThreadSize = schedulerThreadSize; - this.callInitRequestCount = callInitRequestCount; - this.schedulerPeriodMillis = schedulerPeriodMillis; - this.schedulerRecoveryMessageCount = schedulerRecoveryMessageCount; - this.idleTimeout = idleTimeout; - this.throttledLoggerRatio = throttledLoggerRatio; +public class GrpcStreamProperties { + @PositiveOrZero + private int schedulerThreadSize = 1; + @PositiveOrZero + private int callInitRequestCount = 1000; + @Positive + private int schedulerPeriodMillis = 64; + private int schedulerRecoveryMessageCount = 10; + + private long idleTimeout = -1; + @PositiveOrZero + private long throttledLoggerRatio = 1; + + public GrpcStreamProperties() { } public int getSchedulerThreadSize() { return schedulerThreadSize; } + public void setSchedulerThreadSize(int schedulerThreadSize) { + this.schedulerThreadSize = schedulerThreadSize; + } + public int getCallInitRequestCount() { return callInitRequestCount; } + public void setCallInitRequestCount(int callInitRequestCount) { + this.callInitRequestCount = callInitRequestCount; + } + public int getSchedulerPeriodMillis() { return schedulerPeriodMillis; } + public void setSchedulerPeriodMillis(int schedulerPeriodMillis) { + this.schedulerPeriodMillis = schedulerPeriodMillis; + } + public int getSchedulerRecoveryMessageCount() { return schedulerRecoveryMessageCount; } + public void setSchedulerRecoveryMessageCount(int schedulerRecoveryMessageCount) { + this.schedulerRecoveryMessageCount = schedulerRecoveryMessageCount; + } + public long getIdleTimeout() { return idleTimeout; } - public long getThrottledLoggerRatio() { - return throttledLoggerRatio; + public void setIdleTimeout(long idleTimeout) { + this.idleTimeout = idleTimeout; } - public static Builder newBuilder() { - return new Builder(); + public long getThrottledLoggerRatio() { + return throttledLoggerRatio; } - public static class Builder { - private int schedulerThreadSize = 1; - private int callInitRequestCount = 1000; - private int schedulerPeriodMillis = 64; - private int schedulerRecoveryMessageCount = 10; - private long idleTimeout = -1; - private long throttledLoggerRatio = 1; - - - public int getSchedulerThreadSize() { - return schedulerThreadSize; - } - - public void setSchedulerThreadSize(int schedulerThreadSize) { - this.schedulerThreadSize = schedulerThreadSize; - } - - public int getCallInitRequestCount() { - return callInitRequestCount; - } - - public void setCallInitRequestCount(int callInitRequestCount) { - this.callInitRequestCount = callInitRequestCount; - } - - public int getSchedulerPeriodMillis() { - return schedulerPeriodMillis; - } - - public void setSchedulerPeriodMillis(int schedulerPeriodMillis) { - this.schedulerPeriodMillis = schedulerPeriodMillis; - } - - public int getSchedulerRecoveryMessageCount() { - return schedulerRecoveryMessageCount; - } - - public void setSchedulerRecoveryMessageCount(int schedulerRecoveryMessageCount) { - this.schedulerRecoveryMessageCount = schedulerRecoveryMessageCount; - } - - public long getIdleTimeout() { - return idleTimeout; - } - - public void setIdleTimeout(long idleTimeout) { - this.idleTimeout = idleTimeout; - } - - public long getThrottledLoggerRatio() { - return throttledLoggerRatio; - } - - public void setThrottledLoggerRatio(long throttledLoggerRatio) { - this.throttledLoggerRatio = throttledLoggerRatio; - } - - public GrpcStreamProperties build() { - return new GrpcStreamProperties(this.schedulerThreadSize, this.callInitRequestCount, - this.schedulerPeriodMillis, this.schedulerRecoveryMessageCount, this.idleTimeout, this.throttledLoggerRatio); - } + public void setThrottledLoggerRatio(long throttledLoggerRatio) { + this.throttledLoggerRatio = throttledLoggerRatio; } @Override diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamReceiverProperties.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamReceiverProperties.java index 35b033c97dca..49a80839e5b9 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamReceiverProperties.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStreamReceiverProperties.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; import com.navercorp.pinpoint.collector.receiver.BindAddress; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.grpc.server.ServerOption; @@ -34,12 +33,9 @@ public class GrpcStreamReceiverProperties extends GrpcReceiverProperties { public GrpcStreamReceiverProperties(boolean enable, BindAddress bindAddress, - ExecutorProperties serverExecutor, - ExecutorProperties serverCallExecutor, - ExecutorProperties workerExecutor, ServerOption serverOption, GrpcStreamProperties streamProperties) { - super(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption); + super(enable, bindAddress, serverOption); this.streamProperties = streamProperties; } @@ -48,16 +44,7 @@ public GrpcStreamReceiverProperties(boolean enable, public void log() { super.log(); logger.info("streamProperties:{}", streamProperties); - - Assert.isTrue(getServerExecutor().getThreadSize() > 0, "grpcServerExecutorThreadSize must be greater than 0"); - Assert.isTrue(getServerExecutor().getQueueSize() > 0, "grpcServerExecutorQueueSize must be greater than 0"); - - // Work executor - Assert.isTrue(getWorkerExecutor().getThreadSize() > 0, "grpcWorkerExecutorThreadSize must be greater than 0"); - Assert.isTrue(getWorkerExecutor().getQueueSize() > 0, "grpcWorkerExecutorQueueSize must be greater than 0"); - Assert.isTrue(streamProperties.getSchedulerThreadSize() > 0, "grpcStreamSchedulerThreadSize must be greater than 0"); - } public GrpcStreamProperties getStreamProperties() { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfiguration.java index 59465f98cbbe..fd3eb44ad3fc 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfiguration.java @@ -21,6 +21,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.validation.annotation.Validated; /** * @author Taejin Koo @@ -36,6 +37,7 @@ public GrpcAgentDataSslReceiverConfiguration() { } @Bean(BIND_ADDRESS) + @Validated @ConfigurationProperties(BIND_ADDRESS) public BindAddress.Builder newBindAddressBuilder() { BindAddress.Builder builder = BindAddress.newBuilder(); @@ -51,7 +53,7 @@ public GrpcSslProperties.Builder newGrpcSslConfigurationBuilder() { @Bean public GrpcSslReceiverProperties grpcAgentSslReceiverProperties( - @Qualifier(GrpcAgentDataSslReceiverConfiguration.SSL) GrpcSslProperties.Builder sslPropertiesBuilder) throws Exception { + @Qualifier(GrpcAgentDataSslReceiverConfiguration.SSL) GrpcSslProperties.Builder sslPropertiesBuilder) { BindAddress bindAddress = newBindAddressBuilder().build(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfiguration.java index 846d2230b95e..e6317353c43d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfiguration.java @@ -21,6 +21,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.validation.annotation.Validated; /** * @author Taejin Koo @@ -34,6 +35,7 @@ public GrpcSpanSslReceiverConfiguration() { } @Bean(BIND_ADDRESS) + @Validated @ConfigurationProperties(BIND_ADDRESS) public BindAddress.Builder newBindAddressBuilder() { BindAddress.Builder builder = BindAddress.newBuilder(); @@ -43,7 +45,7 @@ public BindAddress.Builder newBindAddressBuilder() { @Bean public GrpcSslReceiverProperties grpcSpanSslReceiverProperties( - @Qualifier(GrpcAgentDataSslReceiverConfiguration.SSL) GrpcSslProperties.Builder sslPropertiesBuilder) throws Exception { + @Qualifier(GrpcAgentDataSslReceiverConfiguration.SSL) GrpcSslProperties.Builder sslPropertiesBuilder) { BindAddress bindAddress = newBindAddressBuilder().build(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfiguration.java index aae5cba8508c..7d913841e839 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfiguration.java @@ -21,6 +21,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.validation.annotation.Validated; /** * @author Taejin Koo @@ -34,6 +35,7 @@ public GrpcStatSslReceiverConfiguration() { } @Bean(BIND_ADDRESS) + @Validated @ConfigurationProperties(BIND_ADDRESS) public BindAddress.Builder newBindAddressBuilder() { BindAddress.Builder builder = BindAddress.newBuilder(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactory.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactory.java new file mode 100644 index 000000000000..61fdb8087d5d --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorFactory.java @@ -0,0 +1,85 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.collector.monitor; + +import com.codahale.metrics.Gauge; +import com.codahale.metrics.MetricRegistry; + +import java.util.Objects; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class MonitoredThreadPoolExecutorFactory { + + private final String name; + private final MetricRegistry registry; + private final int logRate; + + public MonitoredThreadPoolExecutorFactory(String name, MetricRegistry registry, int logRate) { + this.name = Objects.requireNonNull(name, "name"); + this.registry = registry; + this.logRate = logRate; + } + + public boolean isEnable() { + return registry != null; + } + + public ThreadPoolExecutor createExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue queue, + ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { + rejectedExecutionHandler = wrapHandlerChain(rejectedExecutionHandler); + + RunnableDecorator runnableDecorator = new BypassRunnableDecorator(name); + + MonitoredThreadPoolExecutor monitoredThreadPoolExecutor = new MonitoredThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.MILLISECONDS, + queue, threadFactory, rejectedExecutionHandler, runnableDecorator); + + Gauge submitGauge = () -> (long) monitoredThreadPoolExecutor.getSubmitCount(); + this.registry.register(MetricRegistry.name(name, "submitted"), submitGauge); + + Gauge runningGauge = () -> (long) monitoredThreadPoolExecutor.getActiveCount(); + this.registry.register(MetricRegistry.name(name, "running"), runningGauge); + + Gauge completedTaskGauge = () -> (long) monitoredThreadPoolExecutor.getCompletedTaskCount(); + this.registry.register(MetricRegistry.name(name, "completed"), completedTaskGauge); + + return monitoredThreadPoolExecutor; + } + + private RejectedExecutionHandler wrapHandlerChain(RejectedExecutionHandler rejectedExecutionHandler) { + + RejectedExecutionHandlerChain.Builder builder = new RejectedExecutionHandlerChain.Builder(); + if (registry != null) { + RejectedExecutionHandler countingHandler = new CountingRejectedExecutionHandler(name, registry); + builder.addRejectHandler(countingHandler); + } + + if (logRate > -1) { + RejectedExecutionHandler loggingHandler = new LoggingRejectedExecutionHandler(name, logRate); + builder.addRejectHandler(loggingHandler); + } + + // original exception policy + builder.addRejectHandler(rejectedExecutionHandler); + + return builder.build(); + } +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoringExecutors.java b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoringExecutors.java new file mode 100644 index 000000000000..9495cc735ab3 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/monitor/MonitoringExecutors.java @@ -0,0 +1,61 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.collector.monitor; + +import com.codahale.metrics.MetricRegistry; +import com.navercorp.pinpoint.collector.receiver.ExecutorFactoryBean; +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; + +import java.util.Objects; + +public class MonitoringExecutors { + + private final ExecutorCustomizer customizer; + private final MetricRegistry metricRegistry; + + public MonitoringExecutors(@Qualifier("collectorExecutorCustomizer") + ExecutorCustomizer customizer, + @Autowired(required = false) MetricRegistry metricRegistry) { + this.customizer = Objects.requireNonNull(customizer, "customizer"); + this.metricRegistry = metricRegistry; + } + + + public MonitoredThreadPoolExecutorFactory newFactory(String name, int logRate) { + return new MonitoredThreadPoolExecutorFactory(name, metricRegistry, logRate); + } + + public ThreadPoolExecutorFactoryBean newExecutorFactoryBean(MonitoringExecutorProperties properties, String beanName) { + MonitoredThreadPoolExecutorFactory factory = null; + if (properties.isMonitorEnable()) { + factory = this.newFactory(beanName, properties.getLogRate()); + } + ExecutorFactoryBean executor = new ExecutorFactoryBean(); + executor.setExecutorFactory(factory); + + customizer.customize(executor, properties); + if (properties.getThreadNamePrefix() == null) { + executor.setThreadNamePrefix(beanName); + } + return executor; + } +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/BindAddress.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/BindAddress.java index e091336c436d..c1c30695c858 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/BindAddress.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/BindAddress.java @@ -16,6 +16,10 @@ package com.navercorp.pinpoint.collector.receiver; +import jakarta.inject.Provider; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Positive; import java.util.Objects; /** @@ -42,8 +46,10 @@ public static Builder newBuilder() { return new Builder(); } - public static class Builder { + public static class Builder implements Provider { + @NotNull private String ip = "0.0.0.0"; + @Positive private int port; Builder() { @@ -62,6 +68,12 @@ public Builder setPort(int port) { public BindAddress build() { return new BindAddress(this.ip, this.port); } + + + @Override + public BindAddress get() { + return build(); + } } @Override diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/ExecutorFactoryBean.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/ExecutorFactoryBean.java index 9175b4ca043d..32aeb80e6c43 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/ExecutorFactoryBean.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/ExecutorFactoryBean.java @@ -16,109 +16,36 @@ package com.navercorp.pinpoint.collector.receiver; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; -import com.navercorp.pinpoint.collector.monitor.BypassRunnableDecorator; -import com.navercorp.pinpoint.collector.monitor.CountingRejectedExecutionHandler; -import com.navercorp.pinpoint.collector.monitor.LoggingRejectedExecutionHandler; -import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutor; -import com.navercorp.pinpoint.collector.monitor.RejectedExecutionHandlerChain; -import com.navercorp.pinpoint.collector.monitor.RunnableDecorator; +import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactory; +import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; import java.util.concurrent.BlockingQueue; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; /** * @author Woonduk Kang(emeroad) */ -public class ExecutorFactoryBean extends org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean { +public class ExecutorFactoryBean extends ThreadPoolExecutorFactoryBean { - private int logRate = 100; - private String beanName; - - private boolean enableMonitoring = false; - - private MetricRegistry registry; + private MonitoredThreadPoolExecutorFactory executorFactory; public ExecutorFactoryBean() { } - - @Override - public void setBeanName(String name) { - super.setBeanName(name); - this.beanName = name; + public void setExecutorFactory(MonitoredThreadPoolExecutorFactory executorFactory) { + this.executorFactory = executorFactory; } @Override protected ThreadPoolExecutor createExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue queue, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { - if (enableMonitoring) { - return newMonitoredExecutorService(corePoolSize, maxPoolSize, keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler); - } - - return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.MILLISECONDS, queue, threadFactory, rejectedExecutionHandler); - } - - private ThreadPoolExecutor newMonitoredExecutorService(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue queue, - ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { - - rejectedExecutionHandler = wrapHandlerChain(rejectedExecutionHandler); - - RunnableDecorator runnableDecorator = new BypassRunnableDecorator(beanName); - - MonitoredThreadPoolExecutor monitoredThreadPoolExecutor = new MonitoredThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.MILLISECONDS, - queue, threadFactory, rejectedExecutionHandler, runnableDecorator); - - Gauge submitGauge = () -> (long) monitoredThreadPoolExecutor.getSubmitCount(); - this.registry.register(MetricRegistry.name(beanName, "submitted"), submitGauge); - - Gauge runningGauge = () -> (long) monitoredThreadPoolExecutor.getActiveCount(); - this.registry.register(MetricRegistry.name(beanName, "running"), runningGauge); - - Gauge completedTaskGauge = () -> (long) monitoredThreadPoolExecutor.getCompletedTaskCount(); - this.registry.register(MetricRegistry.name(beanName, "completed"), completedTaskGauge); - - return monitoredThreadPoolExecutor; - } - - private RejectedExecutionHandler wrapHandlerChain(RejectedExecutionHandler rejectedExecutionHandler) { - - RejectedExecutionHandlerChain.Builder builder = new RejectedExecutionHandlerChain.Builder(); - if (registry != null) { - RejectedExecutionHandler countingHandler = new CountingRejectedExecutionHandler(beanName, registry); - builder.addRejectHandler(countingHandler); + if (executorFactory != null && executorFactory.isEnable()) { + return executorFactory.createExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler); } - if (logRate > -1) { - RejectedExecutionHandler loggingHandler = new LoggingRejectedExecutionHandler(beanName, logRate); - builder.addRejectHandler(loggingHandler); - } - - // original exception policy - builder.addRejectHandler(rejectedExecutionHandler); - - return builder.build(); - } - - - public void setExecutorProperties(ExecutorProperties executorProperties) { - setCorePoolSize(executorProperties.getThreadSize()); - setMaxPoolSize(executorProperties.getThreadSize()); - setQueueCapacity(executorProperties.getQueueSize()); - this.enableMonitoring = executorProperties.isMonitorEnable(); - } - - public void setRegistry(MetricRegistry registry) { - this.registry = registry; - } - - public void setLogRate(int logRate) { - this.logRate = logRate; + return super.createExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler); } } diff --git a/collector/src/main/resources/applicationContext-collector-grpc.xml b/collector/src/main/resources/applicationContext-collector-grpc.xml index 14002522a16a..ecca77e3b0c0 100644 --- a/collector/src/main/resources/applicationContext-collector-grpc.xml +++ b/collector/src/main/resources/applicationContext-collector-grpc.xml @@ -46,11 +46,6 @@ - - - - - @@ -106,19 +101,6 @@ - - - - - - - - - - - - - @@ -136,24 +118,18 @@ - + - - - - - - - + @@ -165,11 +141,6 @@ - - - - - @@ -184,26 +155,19 @@ - - + - - - - - - - + @@ -215,11 +179,6 @@ - - - - - diff --git a/collector/src/main/resources/applicationContext-collector.xml b/collector/src/main/resources/applicationContext-collector.xml index 22b0a90fd8e2..197f4f380b81 100644 --- a/collector/src/main/resources/applicationContext-collector.xml +++ b/collector/src/main/resources/applicationContext-collector.xml @@ -23,17 +23,6 @@ - - - - - - - - - - - @@ -51,18 +40,6 @@ - - - - - - - - - - - diff --git a/collector/src/main/resources/pinpoint-collector-root.properties b/collector/src/main/resources/pinpoint-collector-root.properties index e64493fe8427..9011ff361ef0 100644 --- a/collector/src/main/resources/pinpoint-collector-root.properties +++ b/collector/src/main/resources/pinpoint-collector-root.properties @@ -11,9 +11,10 @@ collector.l4.ip= #$ /sbin/sysctl -a | grep -e rmem -e wmem # number of agent event worker threads -collector.agentEventWorker.threadSize=4 +collector.agentEventWorker.corePoolSize=4 +collector.agentEventWorker.maxPoolSize=4 # capacity of agent event worker queue -collector.agentEventWorker.queueSize=1024 +collector.agentEventWorker.queueCapacity=1024 # Determines whether to register the information held by com.navercorp.pinpoint.collector.monitor.CollectorMetric to jmx collector.metric.jmx=false diff --git a/collector/src/main/resources/profiles/local/pinpoint-collector-grpc.properties b/collector/src/main/resources/profiles/local/pinpoint-collector-grpc.properties index 205245f3847f..a6ff37c0c9e2 100644 --- a/collector/src/main/resources/profiles/local/pinpoint-collector-grpc.properties +++ b/collector/src/main/resources/profiles/local/pinpoint-collector-grpc.properties @@ -4,17 +4,20 @@ collector.receiver.grpc.agent.enable=true collector.receiver.grpc.agent.bindaddress.ip=0.0.0.0 collector.receiver.grpc.agent.bindaddress.port=9991 # Executor of Server -collector.receiver.grpc.agent.server.executor.thread_size=8 -collector.receiver.grpc.agent.server.executor.queue_size=256 -collector.receiver.grpc.agent.server.executor.monitor_enable=false +collector.receiver.grpc.agent.server.executor.corePoolSize=8 +collector.receiver.grpc.agent.server.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server.executor.queueCapacity=256 +collector.receiver.grpc.agent.server.executor.monitor-enable=false # Call Executor of Server -collector.receiver.grpc.agent.server-call.executor.thread_size=8 -collector.receiver.grpc.agent.server-call.executor.queue_size=256 -collector.receiver.grpc.agent.server-call.executor.monitor_enable=true +collector.receiver.grpc.agent.server-call.executor.corePoolSize=8 +collector.receiver.grpc.agent.server-call.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server-call.executor.queueCapacity=256 +collector.receiver.grpc.agent.server-call.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.agent.worker.executor.thread_size=16 -collector.receiver.grpc.agent.worker.executor.queue_size=1024 -collector.receiver.grpc.agent.worker.executor.monitor_enable=true +collector.receiver.grpc.agent.worker.executor.corePoolSize=16 +collector.receiver.grpc.agent.worker.executor.maxPoolSize=16 +collector.receiver.grpc.agent.worker.executor.queueCapacity=1024 +collector.receiver.grpc.agent.worker.executor.monitor-enable=true # Stat @@ -22,13 +25,15 @@ collector.receiver.grpc.stat.enable=true collector.receiver.grpc.stat.bindaddress.ip=0.0.0.0 collector.receiver.grpc.stat.bindaddress.port=9992 # Executor of Server -collector.receiver.grpc.stat.server.executor.thread_size=4 -collector.receiver.grpc.stat.server.executor.queue_size=256 -collector.receiver.grpc.stat.server.executor.monitor_enable=true +collector.receiver.grpc.stat.server.executor.corePoolSize=4 +collector.receiver.grpc.stat.server.executor.maxPoolSize=4 +collector.receiver.grpc.stat.server.executor.queueCapacity=256 +collector.receiver.grpc.stat.server.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.stat.worker.executor.thread_size=16 -collector.receiver.grpc.stat.worker.executor.queue_size=1024 -collector.receiver.grpc.stat.worker.executor.monitor_enable=true +collector.receiver.grpc.stat.worker.executor.corePoolSize=16 +collector.receiver.grpc.stat.worker.executor.maxPoolSize=16 +collector.receiver.grpc.stat.worker.executor.queueCapacity=1024 +collector.receiver.grpc.stat.worker.executor.monitor-enable=true # Stream scheduler for rejected execution collector.receiver.grpc.stat.stream.scheduler_thread_size=1 collector.receiver.grpc.stat.stream.scheduler_period_millis=1000 @@ -42,13 +47,15 @@ collector.receiver.grpc.span.enable=true collector.receiver.grpc.span.bindaddress.ip=0.0.0.0 collector.receiver.grpc.span.bindaddress.port=9993 # Executor of Server -collector.receiver.grpc.span.server.executor.thread_size=4 -collector.receiver.grpc.span.server.executor.queue_size=256 -collector.receiver.grpc.span.server.executor.monitor_enable=true +collector.receiver.grpc.span.server.executor.corePoolSize=4 +collector.receiver.grpc.span.server.executor.maxPoolSize=4 +collector.receiver.grpc.span.server.executor.queueCapacity=256 +collector.receiver.grpc.span.server.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.span.worker.executor.thread_size=32 -collector.receiver.grpc.span.worker.executor.queue_size=1024 -collector.receiver.grpc.span.worker.executor.monitor_enable=true +collector.receiver.grpc.span.worker.executor.corePoolSize=32 +collector.receiver.grpc.span.worker.executor.maxPoolSize=32 +collector.receiver.grpc.span.worker.executor.queueCapacity=1024 +collector.receiver.grpc.span.worker.executor.monitor-enable=true # Stream scheduler for rejected execution collector.receiver.grpc.span.stream.scheduler_thread_size=1 diff --git a/collector/src/main/resources/profiles/release/pinpoint-collector-grpc.properties b/collector/src/main/resources/profiles/release/pinpoint-collector-grpc.properties index ab37a2ed13df..51d0597b7eef 100644 --- a/collector/src/main/resources/profiles/release/pinpoint-collector-grpc.properties +++ b/collector/src/main/resources/profiles/release/pinpoint-collector-grpc.properties @@ -4,18 +4,21 @@ collector.receiver.grpc.agent.enable=true collector.receiver.grpc.agent.bindaddress.ip=0.0.0.0 collector.receiver.grpc.agent.bindaddress.port=9991 # Executor of Server -collector.receiver.grpc.agent.server.executor.thread_size=8 -collector.receiver.grpc.agent.server.executor.queue_size=256 -collector.receiver.grpc.agent.server.executor.monitor_enable=false +collector.receiver.grpc.agent.server.executor.corePoolSize=8 +collector.receiver.grpc.agent.server.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server.executor.queueCapacity=256 +collector.receiver.grpc.agent.server.executor.monitor-enable=false # Call Executor of Server -collector.receiver.grpc.agent.server-call.executor.thread_size=8 -collector.receiver.grpc.agent.server-call.executor.queue_size=256 -collector.receiver.grpc.agent.server-call.executor.monitor_enable=true +collector.receiver.grpc.agent.server-call.executor.corePoolSize=8 +collector.receiver.grpc.agent.server-call.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server-call.executor.queueCapacity=256 +collector.receiver.grpc.agent.server-call.executor.monitor-enable=true collector.receiver.grpc.agent.server-call.executor.monitor.duration.enable=false # Executor of Worker -collector.receiver.grpc.agent.worker.executor.thread_size=256 -collector.receiver.grpc.agent.worker.executor.queue_size=5120 -collector.receiver.grpc.agent.worker.executor.monitor_enable=true +collector.receiver.grpc.agent.worker.executor.corePoolSize=256 +collector.receiver.grpc.agent.worker.executor.maxPoolSize=256 +collector.receiver.grpc.agent.worker.executor.queueCapacity=5120 +collector.receiver.grpc.agent.worker.executor.monitor-enable=true collector.receiver.grpc.agent.worker.executor.monitor.duration.enable=true @@ -24,14 +27,16 @@ collector.receiver.grpc.stat.enable=true collector.receiver.grpc.stat.bindaddress.ip=0.0.0.0 collector.receiver.grpc.stat.bindaddress.port=9992 # Executor of Server -collector.receiver.grpc.stat.server.executor.thread_size=4 -collector.receiver.grpc.stat.server.executor.queue_size=256 -collector.receiver.grpc.stat.server.executor.monitor_enable=true +collector.receiver.grpc.stat.server.executor.corePoolSize=4 +collector.receiver.grpc.stat.server.executor.maxPoolSize=4 +collector.receiver.grpc.stat.server.executor.queueCapacity=256 +collector.receiver.grpc.stat.server.executor.monitor-enable=true collector.receiver.grpc.stat.server.executor.monitor.duration.enable=false # Executor of Worker -collector.receiver.grpc.stat.worker.executor.thread_size=64 -collector.receiver.grpc.stat.worker.executor.queue_size=5120 -collector.receiver.grpc.stat.worker.executor.monitor_enable=true +collector.receiver.grpc.stat.worker.executor.corePoolSize=64 +collector.receiver.grpc.stat.worker.executor.maxPoolSize=64 +collector.receiver.grpc.stat.worker.executor.queueCapacity=5120 +collector.receiver.grpc.stat.worker.executor.monitor-enable=true collector.receiver.grpc.stat.worker.executor.monitor.duration.enable=true # Stream scheduler for rejected execution collector.receiver.grpc.stat.stream.scheduler_thread_size=1 @@ -46,15 +51,17 @@ collector.receiver.grpc.span.enable=true collector.receiver.grpc.span.bindaddress.ip=0.0.0.0 collector.receiver.grpc.span.bindaddress.port=9993 # Executor of Server -collector.receiver.grpc.span.server.executor.thread_size=4 -collector.receiver.grpc.span.server.executor.queue_size=256 -collector.receiver.grpc.span.server.executor.monitor_enable=true +collector.receiver.grpc.span.server.executor.corePoolSize=4 +collector.receiver.grpc.span.server.executor.maxPoolSize=4 +collector.receiver.grpc.span.server.executor.queueCapacity=256 +collector.receiver.grpc.span.server.executor.monitor-enable=true collector.receiver.grpc.span.server.executor.monitor.duration.enable=false # Executor of Worker -collector.receiver.grpc.span.worker.executor.thread_size=512 -collector.receiver.grpc.span.worker.executor.queue_size=10240 -collector.receiver.grpc.span.worker.executor.monitor_enable=true +collector.receiver.grpc.span.worker.executor.corePoolSize=512 +collector.receiver.grpc.span.worker.executor.maxPoolSize=512 +collector.receiver.grpc.span.worker.executor.queueCapacity=10240 +collector.receiver.grpc.span.worker.executor.monitor-enable=true collector.receiver.grpc.span.worker.executor.monitor.duration.enable=true # Stream scheduler for rejected execution collector.receiver.grpc.span.stream.scheduler_thread_size=1 diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfigurationTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfigurationTest.java index 1cc21e26fc59..263d4a5e6df2 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfigurationTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentDataReceiverConfigurationTest.java @@ -16,66 +16,111 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.util.unit.DataSize; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; @EnableConfigurationProperties -@TestPropertySource(locations = "classpath:test-pinpoint-collector.properties") -@ContextConfiguration(classes = GrpcAgentDataReceiverConfiguration.class) +@TestPropertySource(properties = { + // # Agent + "collector.receiver.grpc.agent.enable=false", + "collector.receiver.grpc.agent.bindaddress.ip=1.1.1.1", + "collector.receiver.grpc.agent.bindaddress.port=1", + // # Executor of Server + "collector.receiver.grpc.agent.server.executor.corePoolSize=1", + "collector.receiver.grpc.agent.server.executor.maxPoolSize=1", + "collector.receiver.grpc.agent.server.executor.queueCapacity=11", + "collector.receiver.grpc.agent.server.executor.monitor-enable=true", + // # Executor of Worker + "collector.receiver.grpc.agent.worker.executor.corePoolSize=1", + "collector.receiver.grpc.agent.worker.executor.maxPoolSize=1", + "collector.receiver.grpc.agent.worker.executor.queueCapacity=21", + "collector.receiver.grpc.agent.worker.executor.monitor-enable=true", + // # Server Option + "collector.receiver.grpc.agent.keepalive_time_millis=1", + "collector.receiver.grpc.agent.keepalive_timeout_millis=2", + "collector.receiver.grpc.agent.permit_keepalive_time_millis=3", + "collector.receiver.grpc.agent.connection_idle_timeout_millis=4", + "collector.receiver.grpc.agent.concurrent-calls_per-connection_max=1", + "collector.receiver.grpc.agent.handshake_timeout_millis=1", + "collector.receiver.grpc.agent.flow-control_window_size_init=1MB", + "collector.receiver.grpc.agent.header_list_size_max=1KB", + "collector.receiver.grpc.agent.inbound_message_size_max=1MB", + "collector.receiver.grpc.agent.receive_buffer_size=1MB", +}) +@ContextConfiguration(classes = { + GrpcAgentDataReceiverConfiguration.class, + TestReceiverConfig.class, +}) @ExtendWith(SpringExtension.class) public class GrpcAgentDataReceiverConfigurationTest { @Autowired - private GrpcAgentDataReceiverProperties configuration; + GrpcReceiverProperties properties; + + @Autowired + @Qualifier("grpcAgentServerExecutorProperties") + MonitoringExecutorProperties serverExecutor; + @Autowired + @Qualifier("grpcAgentServerCallExecutorProperties") + MonitoringExecutorProperties serverCallExecutor; + @Autowired + @Qualifier("grpcAgentWorkerExecutorProperties") + MonitoringExecutorProperties workerExecutor; @Test public void properties() { - assertEquals(Boolean.FALSE, configuration.isEnable()); - BindAddress bindAddress = configuration.getBindAddress(); + assertFalse(properties.isEnable()); + + BindAddress bindAddress = properties.getBindAddress(); assertEquals("1.1.1.1", bindAddress.getIp()); assertEquals(1, bindAddress.getPort()); - ExecutorProperties serverExecutor = configuration.getServerExecutor(); - assertEquals(10, serverExecutor.getThreadSize()); - assertEquals(11, serverExecutor.getQueueSize()); + assertEquals(1, serverExecutor.getCorePoolSize()); + assertEquals(1, serverExecutor.getMaxPoolSize()); + assertEquals(11, serverExecutor.getQueueCapacity()); + + assertEquals(1, workerExecutor.getCorePoolSize()); + assertEquals(1, workerExecutor.getMaxPoolSize()); + assertEquals(21, workerExecutor.getQueueCapacity()); - ExecutorProperties workerExecutor = configuration.getWorkerExecutor(); - assertEquals(20, workerExecutor.getThreadSize()); - assertEquals(21, workerExecutor.getQueueSize()); - assertEquals(Boolean.FALSE, workerExecutor.isMonitorEnable()); + assertTrue(workerExecutor.isMonitorEnable()); } @Test public void serverOption() { - ServerOption serverOption = configuration.getServerOption(); + ServerOption serverOption = properties.getServerOption(); assertEquals(1, serverOption.getKeepAliveTime()); - assertEquals(1, serverOption.getKeepAliveTimeout()); - assertEquals(1, serverOption.getPermitKeepAliveTime()); - assertEquals(1, serverOption.getMaxConnectionIdle()); + assertEquals(2, serverOption.getKeepAliveTimeout()); + assertEquals(3, serverOption.getPermitKeepAliveTime()); + assertEquals(4, serverOption.getMaxConnectionIdle()); assertEquals(1, serverOption.getMaxConcurrentCallsPerConnection()); // 1M - assertEquals(1024 * 1024, serverOption.getMaxInboundMessageSize()); + assertEquals(DataSize.ofMegabytes(1).toBytes(), serverOption.getMaxInboundMessageSize()); // 1K - assertEquals(1024, serverOption.getMaxHeaderListSize()); + assertEquals(DataSize.ofKilobytes(1).toBytes(), serverOption.getMaxHeaderListSize()); // 1M - assertEquals(1024 * 1024, serverOption.getFlowControlWindow()); + assertEquals(DataSize.ofMegabytes(1).toBytes(), serverOption.getFlowControlWindow()); assertEquals(1, serverOption.getHandshakeTimeout()); // 1M - assertEquals(1024 * 1024, serverOption.getReceiveBufferSize()); + assertEquals(DataSize.ofMegabytes(1).toBytes(), serverOption.getReceiveBufferSize()); } } \ No newline at end of file diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfigurationTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfigurationTest.java index dc904e598bf7..6e1b5ec71a5b 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfigurationTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcSpanReceiverConfigurationTest.java @@ -16,68 +16,115 @@ package com.navercorp.pinpoint.collector.grpc.config; +import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.util.unit.DataSize; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * @author Woonduk Kang(emeroad) */ @EnableConfigurationProperties -@TestPropertySource(locations = "classpath:test-pinpoint-collector.properties") -@ContextConfiguration(classes = GrpcSpanReceiverConfiguration.class) +@TestPropertySource(properties = { + // # Stat + "collector.receiver.grpc.span.enable=false", + "collector.receiver.grpc.span.bindaddress.ip=2.2.2.2", + "collector.receiver.grpc.span.bindaddress.port=2", + + // # Executor of Worker + "collector.receiver.grpc.span.worker.executor.corePoolSize=1", + "collector.receiver.grpc.span.worker.executor.maxPoolSize=1", + "collector.receiver.grpc.span.worker.executor.queueCapacity=4", + "collector.receiver.grpc.span.worker.executor.monitor-enable=false", + + // # Stream scheduler for rejected execution + "collector.receiver.grpc.span.stream.scheduler_thread_size=2", + "collector.receiver.grpc.span.stream.scheduler_period_millis=3", + "collector.receiver.grpc.span.stream.call_init_request_count=4", + "collector.receiver.grpc.span.stream.throttled_logger_ratio=5", + + // # Server Option + "collector.receiver.grpc.span.keepalive_time_millis=2", + "collector.receiver.grpc.span.keepalive_timeout_millis=3", + "collector.receiver.grpc.span.permit_keepalive_time_millis=4", + "collector.receiver.grpc.span.connection_idle_timeout_millis=5", + "collector.receiver.grpc.span.concurrent-calls_per-connection_max=6", + "collector.receiver.grpc.span.handshake_timeout_millis=2", + "collector.receiver.grpc.span.flow-control_window_size_init=3MB", + "collector.receiver.grpc.span.header_list_size_max=3KB", + "collector.receiver.grpc.span.inbound_message_size_max=3MB", + "collector.receiver.grpc.span.receive_buffer_size=3MB", +}) +@ContextConfiguration(classes = { + GrpcSpanReceiverConfiguration.class, + TestReceiverConfig.class, +}) @ExtendWith(SpringExtension.class) public class GrpcSpanReceiverConfigurationTest { private final Logger logger = LogManager.getLogger(this.getClass()); @Autowired - private GrpcStreamReceiverProperties configuration; + GrpcReceiverProperties properties; + @Autowired + GrpcStreamProperties streamProperties; + + @Autowired + @Qualifier("grpcSpanWorkerExecutorProperties") + MonitoringExecutorProperties workerExecutor; @Test public void properties() { - assertEquals(Boolean.FALSE, configuration.isEnable()); - assertEquals("3.3.3.3", configuration.getBindAddress().getIp()); - assertEquals(3, configuration.getBindAddress().getPort()); - assertEquals(3, configuration.getWorkerExecutor().getThreadSize()); - assertEquals(3, configuration.getWorkerExecutor().getQueueSize()); - assertEquals(Boolean.FALSE, configuration.getWorkerExecutor().isMonitorEnable()); - assertEquals(3, configuration.getStreamProperties().getSchedulerThreadSize()); - assertEquals(3, configuration.getStreamProperties().getSchedulerPeriodMillis()); - assertEquals(3, configuration.getStreamProperties().getCallInitRequestCount()); - assertEquals(3, configuration.getStreamProperties().getThrottledLoggerRatio()); + assertFalse(properties.isEnable()); + + BindAddress bindAddress = properties.getBindAddress(); + assertEquals("2.2.2.2", bindAddress.getIp()); + assertEquals(2, bindAddress.getPort()); + + assertEquals(1, workerExecutor.getCorePoolSize()); + assertEquals(1, workerExecutor.getMaxPoolSize()); + assertEquals(4, workerExecutor.getQueueCapacity()); + assertFalse(workerExecutor.isMonitorEnable()); + assertEquals(2, streamProperties.getSchedulerThreadSize()); + assertEquals(3, streamProperties.getSchedulerPeriodMillis()); + assertEquals(4, streamProperties.getCallInitRequestCount()); + assertEquals(5, streamProperties.getThrottledLoggerRatio()); } @Test public void serverOption() { - ServerOption serverOption = configuration.getServerOption(); + ServerOption serverOption = properties.getServerOption(); - assertEquals(3, serverOption.getKeepAliveTime()); + assertEquals(2, serverOption.getKeepAliveTime()); assertEquals(3, serverOption.getKeepAliveTimeout()); - assertEquals(3, serverOption.getPermitKeepAliveTime()); - assertEquals(3, serverOption.getMaxConnectionIdle()); - assertEquals(3, serverOption.getMaxConcurrentCallsPerConnection()); + assertEquals(4, serverOption.getPermitKeepAliveTime()); + assertEquals(5, serverOption.getMaxConnectionIdle()); + assertEquals(6, serverOption.getMaxConcurrentCallsPerConnection()); // 3M - assertEquals(3 * 1024 * 1024, serverOption.getMaxInboundMessageSize()); + assertEquals(DataSize.ofMegabytes(3).toBytes(), serverOption.getMaxInboundMessageSize()); // 3K - assertEquals(3 * 1024, serverOption.getMaxHeaderListSize()); + assertEquals(DataSize.ofKilobytes(3).toBytes(), serverOption.getMaxHeaderListSize()); // 3M - assertEquals(3 * 1024 * 1024, serverOption.getFlowControlWindow()); + assertEquals(DataSize.ofMegabytes(3).toBytes(), serverOption.getFlowControlWindow()); - assertEquals(3, serverOption.getHandshakeTimeout()); + assertEquals(2, serverOption.getHandshakeTimeout()); // 3M - assertEquals(3 * 1024 * 1024, serverOption.getReceiveBufferSize()); + assertEquals(DataSize.ofMegabytes(3).toBytes(), serverOption.getReceiveBufferSize()); } } \ No newline at end of file diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfigurationTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfigurationTest.java index de815e7cea43..5900683c1c4b 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfigurationTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/GrpcStatReceiverConfigurationTest.java @@ -16,39 +16,86 @@ package com.navercorp.pinpoint.collector.grpc.config; +import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.util.unit.DataSize; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; @EnableConfigurationProperties -@TestPropertySource(locations = "classpath:test-pinpoint-collector.properties") -@ContextConfiguration(classes = GrpcStatReceiverConfiguration.class) +@TestPropertySource(properties = { + // # Stat + "collector.receiver.grpc.stat.enable=false", + "collector.receiver.grpc.stat.bindaddress.ip=2.2.2.2", + "collector.receiver.grpc.stat.bindaddress.port=2", + + // # Executor of Worker + "collector.receiver.grpc.stat.worker.executor.corePoolSize=2", + "collector.receiver.grpc.stat.worker.executor.maxPoolSize=2", + "collector.receiver.grpc.stat.worker.executor.queueCapacity=2", + "collector.receiver.grpc.stat.worker.executor.monitor-enable=false", + + // # Stream scheduler for rejected execution + "collector.receiver.grpc.stat.stream.scheduler_thread_size=2", + "collector.receiver.grpc.stat.stream.scheduler_period_millis=2", + "collector.receiver.grpc.stat.stream.call_init_request_count=2", + "collector.receiver.grpc.stat.stream.throttled_logger_ratio=2", + + // # Server Option + "collector.receiver.grpc.stat.keepalive_time_millis=2", + "collector.receiver.grpc.stat.keepalive_timeout_millis=3", + "collector.receiver.grpc.stat.permit_keepalive_time_millis=4", + "collector.receiver.grpc.stat.connection_idle_timeout_millis=5", + "collector.receiver.grpc.stat.concurrent-calls_per-connection_max=6", + "collector.receiver.grpc.stat.handshake_timeout_millis=2", + "collector.receiver.grpc.stat.flow-control_window_size_init=2MB", + "collector.receiver.grpc.stat.header_list_size_max=2KB", + "collector.receiver.grpc.stat.inbound_message_size_max=2MB", + "collector.receiver.grpc.stat.receive_buffer_size=2MB", +}) +@ContextConfiguration(classes = { + GrpcStatReceiverConfiguration.class, + TestReceiverConfig.class +}) @ExtendWith(SpringExtension.class) public class GrpcStatReceiverConfigurationTest { @Autowired - private GrpcStatReceiverProperties configuration; + GrpcReceiverProperties properties; + @Autowired + GrpcStreamProperties streamProperties; + + @Autowired + @Qualifier("grpcStatWorkerExecutorProperties") + MonitoringExecutorProperties workerExecutor; @Test public void properties() { - assertEquals(Boolean.FALSE, configuration.isEnable()); - assertEquals("2.2.2.2", configuration.getBindAddress().getIp()); - assertEquals(2, configuration.getBindAddress().getPort()); - assertEquals(2, configuration.getWorkerExecutor().getThreadSize()); - assertEquals(2, configuration.getWorkerExecutor().getQueueSize()); - assertEquals(Boolean.FALSE, configuration.getWorkerExecutor().isMonitorEnable()); - assertEquals(2, configuration.getStreamProperties().getSchedulerThreadSize()); - assertEquals(2, configuration.getStreamProperties().getSchedulerPeriodMillis()); - assertEquals(2, configuration.getStreamProperties().getCallInitRequestCount()); - assertEquals(2, configuration.getStreamProperties().getThrottledLoggerRatio()); + assertFalse(properties.isEnable()); + + BindAddress bindAddress = properties.getBindAddress(); + assertEquals("2.2.2.2", bindAddress.getIp()); + assertEquals(2, bindAddress.getPort()); + + assertEquals(2, workerExecutor.getCorePoolSize()); + assertEquals(2, workerExecutor.getQueueCapacity()); + assertFalse(workerExecutor.isMonitorEnable()); + + assertEquals(2, streamProperties.getSchedulerThreadSize()); + assertEquals(2, streamProperties.getSchedulerPeriodMillis()); + assertEquals(2, streamProperties.getCallInitRequestCount()); + assertEquals(2, streamProperties.getThrottledLoggerRatio()); } @@ -56,23 +103,23 @@ public void properties() { @Test public void serverOption() { - ServerOption serverOption = configuration.getServerOption(); + ServerOption serverOption = properties.getServerOption(); assertEquals(2, serverOption.getKeepAliveTime()); - assertEquals(2, serverOption.getKeepAliveTimeout()); - assertEquals(2, serverOption.getPermitKeepAliveTime()); - assertEquals(2, serverOption.getMaxConnectionIdle()); - assertEquals(2, serverOption.getMaxConcurrentCallsPerConnection()); + assertEquals(3, serverOption.getKeepAliveTimeout()); + assertEquals(4, serverOption.getPermitKeepAliveTime()); + assertEquals(5, serverOption.getMaxConnectionIdle()); + assertEquals(6, serverOption.getMaxConcurrentCallsPerConnection()); // 2M - assertEquals(2 * 1024 * 1024, serverOption.getMaxInboundMessageSize()); + assertEquals(DataSize.ofMegabytes(2).toBytes(), serverOption.getMaxInboundMessageSize()); // 2K - assertEquals(2 * 1024, serverOption.getMaxHeaderListSize()); + assertEquals(DataSize.ofKilobytes(2).toBytes(), serverOption.getMaxHeaderListSize()); // 2M - assertEquals(2 * 1024 * 1024, serverOption.getFlowControlWindow()); + assertEquals(DataSize.ofMegabytes(2).toBytes(), serverOption.getFlowControlWindow()); assertEquals(2, serverOption.getHandshakeTimeout()); // 2M - assertEquals(2 * 1024 * 1024, serverOption.getReceiveBufferSize()); + assertEquals(DataSize.ofMegabytes(2).toBytes(), serverOption.getReceiveBufferSize()); } } \ No newline at end of file diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java new file mode 100644 index 000000000000..3c112ebbafb7 --- /dev/null +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/config/TestReceiverConfig.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.collector.grpc.config; + +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import com.navercorp.pinpoint.common.config.executor.ThreadPoolExecutorCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; + + +@Configuration +@Import(MonitoringExecutors.class) +public class TestReceiverConfig { + @Bean + public ExecutorCustomizer collectorExecutorCustomizer() { + return new ThreadPoolExecutorCustomizer(); + } +} diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfigurationTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfigurationTest.java index ff9cc042fbcf..64756a70ccd6 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfigurationTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcAgentDataSslReceiverConfigurationTest.java @@ -32,13 +32,27 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @EnableConfigurationProperties -@TestPropertySource(locations = "classpath:test-pinpoint-collector.properties") -@ContextConfiguration(classes = GrpcAgentDataSslReceiverConfiguration.class) +@TestPropertySource(properties = { + // # Agent + "collector.receiver.grpc.agent.ssl.bindaddress.ip=1.1.1.1", + "collector.receiver.grpc.agent.ssl.bindaddress.port=19441", + + // ### For ssl config + // # please choose openssl/jdk + "collector.receiver.grpc.ssl.provider_type=jdk", + // # please insert .pem file path + "collector.receiver.grpc.ssl.key_file_path=certs/server0.pem", + // # please insert .crt file path + "collector.receiver.grpc.ssl.key_cert_file_path=certs/server0.key" +}) +@ContextConfiguration(classes = { + GrpcAgentDataSslReceiverConfiguration.class +}) @ExtendWith(SpringExtension.class) public class GrpcAgentDataSslReceiverConfigurationTest { @Autowired - private GrpcSslReceiverProperties configuration; + GrpcSslReceiverProperties configuration; @Test public void properties() { diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfigurationTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfigurationTest.java index 7e76c195d78b..1ad610f585f4 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfigurationTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcSpanSslReceiverConfigurationTest.java @@ -33,14 +33,29 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @EnableConfigurationProperties -@TestPropertySource(locations = "classpath:test-pinpoint-collector.properties") -@ContextConfiguration(classes = {GrpcAgentDataSslReceiverConfiguration.class, GrpcSpanSslReceiverConfiguration.class}) +@TestPropertySource(properties = { + // # Agent + "collector.receiver.grpc.span.ssl.bindaddress.ip=3.3.3.3", + "collector.receiver.grpc.span.ssl.bindaddress.port=39443", + + // ### For ssl config + // # please choose openssl/jdk + "collector.receiver.grpc.ssl.provider_type=jdk", + // # please insert .pem file path + "collector.receiver.grpc.ssl.key_file_path=certs/server0.pem", + // # please insert .crt file path + "collector.receiver.grpc.ssl.key_cert_file_path=certs/server0.key" +}) +@ContextConfiguration(classes = { + GrpcAgentDataSslReceiverConfiguration.class, + GrpcSpanSslReceiverConfiguration.class +}) @ExtendWith(SpringExtension.class) public class GrpcSpanSslReceiverConfigurationTest { @Autowired @Qualifier("grpcSpanSslReceiverProperties") - private GrpcSslReceiverProperties properties; + GrpcSslReceiverProperties properties; @Test public void properties() { diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfigurationTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfigurationTest.java index 6219e8df25cd..2c4928f3bea7 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfigurationTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/ssl/GrpcStatSslReceiverConfigurationTest.java @@ -33,14 +33,29 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @EnableConfigurationProperties -@TestPropertySource(locations = "classpath:test-pinpoint-collector.properties") -@ContextConfiguration(classes = {GrpcAgentDataSslReceiverConfiguration.class, GrpcStatSslReceiverConfiguration.class}) +@TestPropertySource(properties = { + // # Agent + "collector.receiver.grpc.stat.ssl.bindaddress.ip=2.2.2.2", + "collector.receiver.grpc.stat.ssl.bindaddress.port=29442", + + // ### For ssl config + // # please choose openssl/jdk + "collector.receiver.grpc.ssl.provider_type=jdk", + // # please insert .pem file path + "collector.receiver.grpc.ssl.key_file_path=certs/server0.pem", + // # please insert .crt file path + "collector.receiver.grpc.ssl.key_cert_file_path=certs/server0.key" +}) +@ContextConfiguration(classes = { + GrpcAgentDataSslReceiverConfiguration.class, + GrpcStatSslReceiverConfiguration.class +}) @ExtendWith(SpringExtension.class) public class GrpcStatSslReceiverConfigurationTest { @Autowired @Qualifier("grpcStatSslReceiverProperties") - private GrpcSslReceiverProperties configuration; + GrpcSslReceiverProperties configuration; @Test public void properties() { diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorTest.java index a977974c55fb..5ce43cf19385 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/monitor/MonitoredThreadPoolExecutorTest.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.collector.monitor; -import com.codahale.metrics.MetricRegistry; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,7 +38,6 @@ public class MonitoredThreadPoolExecutorTest { @BeforeEach public void setUp() throws Exception { - MetricRegistry metricRegistry = new MetricRegistry(); this.runnableDecorator = spy(new BypassRunnableDecorator("test")); this.threadPoolExecutor = new MonitoredThreadPoolExecutor(1, 1, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), runnableDecorator); } diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanServerTestMain.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanServerTestMain.java index 3f00fa16c1a2..8381b6768bde 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanServerTestMain.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanServerTestMain.java @@ -110,11 +110,11 @@ private ServerServiceDefinition newSpanBindableService(Executor executor) throws } private GrpcStreamProperties newStreamProperties() { - GrpcStreamProperties.Builder builder = GrpcStreamProperties.newBuilder(); - builder.setCallInitRequestCount(100); - builder.setSchedulerPeriodMillis(1000); - builder.setSchedulerRecoveryMessageCount(100); - return builder.build(); + GrpcStreamProperties properties = new GrpcStreamProperties(); + properties.setCallInitRequestCount(100); + properties.setSchedulerPeriodMillis(1000); + properties.setSchedulerRecoveryMessageCount(100); + return properties; } private ExecutorService newWorkerExecutor(int thread) { diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatServerTestMain.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatServerTestMain.java index 256ec345965f..1e5e5bce8d05 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatServerTestMain.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatServerTestMain.java @@ -79,11 +79,11 @@ private ServerServiceDefinition newStatBindableService(Executor executor) throws } private GrpcStreamProperties newStreamProperties() { - GrpcStreamProperties.Builder builder = GrpcStreamProperties.newBuilder(); - builder.setCallInitRequestCount(100); - builder.setSchedulerPeriodMillis(1000); - builder.setSchedulerRecoveryMessageCount(100); - return builder.build(); + GrpcStreamProperties properties = new GrpcStreamProperties(); + properties.setCallInitRequestCount(100); + properties.setSchedulerPeriodMillis(1000); + properties.setSchedulerRecoveryMessageCount(100); + return properties; } public static void main(String[] args) throws Exception { diff --git a/collector/src/test/resources/test-pinpoint-collector.properties b/collector/src/test/resources/test-pinpoint-collector.properties deleted file mode 100644 index c1c089784405..000000000000 --- a/collector/src/test/resources/test-pinpoint-collector.properties +++ /dev/null @@ -1,198 +0,0 @@ -# -# Copyright 2017 NAVER Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# configure l4 ip address to ignore health check logs -collector.l4.ip=127.0.0.1,192.168.0.1,255.255.255.255 - -# tcp listen ip and port -collector.receiver.base.ip=0.0.0.2 -collector.receiver.base.port=39994 - -# number of tcp worker threads -collector.receiver.base.worker.threadSize=33 -# capacity of tcp worker queue -collector.receiver.base.worker.queueSize=29 -# monitoring for tcp worker -collector.receiver.base.worker.monitor=true - -# stat receiver config --------------------------------------------------------------------- -collector.receiver.stat.udp=false -collector.receiver.stat.udp.ip=0.0.0.1 -collector.receiver.stat.udp.port=39995 -collector.receiver.stat.udp.receiveBufferSize=419 - -collector.receiver.stat.tcp=true -collector.receiver.stat.tcp.ip=0.0.0.2 -collector.receiver.stat.tcp.port=39996 - -# number of udp statworker threads -collector.receiver.stat.worker.threadSize=2 -# capacity of udp statworker queue -collector.receiver.stat.worker.queueSize=3 -# monitoring for udp stat worker -collector.receiver.stat.worker.monitor=true - - -# span receiver config --------------------------------------------------------------------- -collector.receiver.span.udp=true -collector.receiver.span.udp.ip=0.0.0.3 -collector.receiver.span.udp.port=39997 -collector.receiver.span.udp.receiveBufferSize=568 - -collector.receiver.span.tcp=false -collector.receiver.span.tcp.ip=0.0.0.4 -collector.receiver.span.tcp.port=39998 - -# number of udp statworker threads -collector.receiver.span.worker.threadSize=3 -# capacity of udp statworker queue -collector.receiver.span.worker.queueSize=4 -# monitoring for udp stat worker -collector.receiver.span.worker.monitor=false - -# change OS level read/write socket buffer size (for linux) -#sudo sysctl -w net.core.rmem_max= -#sudo sysctl -w net.core.wmem_max= -# check current values using: -#$ /sbin/sysctl -a | grep -e rmem -e wmem - -# number of agent event worker threads -collector.agentEventWorker.threadSize=4 -# capacity of agent event worker queue -collector.agentEventWorker.queueSize=1024 - -# Determines whether to register the information held by com.navercorp.pinpoint.collector.monitor.CollectorMetric to jmx -collector.metric.jmx=false -collector.metric.jmx.domain=pinpoint.collector.metrics - -#collector.admin.password= -#collector.admin.api.rest.active= -#collector.admin.api.jmx.active= - -collector.spanEvent.sequence.limit=10000 - -# Flink configuration -flink.cluster.enable=false -flink.cluster.zookeeper.address=localhost -flink.cluster.zookeeper.znode_root=/pinpoint-cluster -flink.cluster.zookeeper.sessiontimeout=3000 - - -# gRPC -# Agent -collector.receiver.grpc.agent.enable=false -collector.receiver.grpc.agent.bindaddress.ip=1.1.1.1 -collector.receiver.grpc.agent.bindaddress.port=1 -# Executor of Server -collector.receiver.grpc.agent.server.executor.thread_size=10 -collector.receiver.grpc.agent.server.executor.queue_size=11 -collector.receiver.grpc.agent.server.executor.monitor_enable=true -# Executor of Worker -collector.receiver.grpc.agent.worker.executor.thread_size=20 -collector.receiver.grpc.agent.worker.executor.queue_size=21 -collector.receiver.grpc.agent.worker.executor.monitor.enable=true -# Server Option -collector.receiver.grpc.agent.keepalive_time_millis=1 -collector.receiver.grpc.agent.keepalive_timeout_millis=1 -collector.receiver.grpc.agent.permit_keepalive_time_millis=1 -collector.receiver.grpc.agent.connection_idle_timeout_millis=1 -collector.receiver.grpc.agent.concurrent-calls_per-connection_max=1 -collector.receiver.grpc.agent.handshake_timeout_millis=1 -collector.receiver.grpc.agent.flow-control_window_size_init=1MB -collector.receiver.grpc.agent.header_list_size_max=1KB -collector.receiver.grpc.agent.inbound_message_size_max=1MB -collector.receiver.grpc.agent.receive_buffer_size=1MB - -# Stat -collector.receiver.grpc.stat.enable=false -collector.receiver.grpc.stat.bindaddress.ip=2.2.2.2 -collector.receiver.grpc.stat.bindaddress.port=2 -# Executor of Server -collector.receiver.grpc.stat.server.executor.thread_size=2 -collector.receiver.grpc.stat.server.executor.queue_size=2 -collector.receiver.grpc.stat.server.executor.monitor_enable=false -# Executor of Worker -collector.receiver.grpc.stat.worker.executor.thread_size=2 -collector.receiver.grpc.stat.worker.executor.queue_size=2 -collector.receiver.grpc.stat.worker.executor.monitor_enable=false -# Stream scheduler for rejected execution -collector.receiver.grpc.stat.stream.scheduler_thread_size=2 -collector.receiver.grpc.stat.stream.scheduler_period_millis=2 -collector.receiver.grpc.stat.stream.call_init_request_count=2 -collector.receiver.grpc.stat.stream.throttled_logger_ratio=2 - -# Server Option -collector.receiver.grpc.stat.keepalive_time_millis=2 -collector.receiver.grpc.stat.keepalive_timeout_millis=2 -collector.receiver.grpc.stat.permit_keepalive_time_millis=2 -collector.receiver.grpc.stat.connection_idle_timeout_millis=2 -collector.receiver.grpc.stat.concurrent-calls_per-connection_max=2 -collector.receiver.grpc.stat.handshake_timeout_millis=2 -collector.receiver.grpc.stat.flow-control_window_size_init=2MB -collector.receiver.grpc.stat.header_list_size_max=2KB -collector.receiver.grpc.stat.inbound_message_size_max=2MB -collector.receiver.grpc.stat.receive_buffer_size=2MB - -# Span -collector.receiver.grpc.span.enable=false -collector.receiver.grpc.span.bindaddress.ip=3.3.3.3 -collector.receiver.grpc.span.bindaddress.port=3 -# Executor of Server -collector.receiver.grpc.span.server.executor.thread_size=3 -collector.receiver.grpc.span.server.executor.queue_size=3 -collector.receiver.grpc.span.server.executor.monitor_enable=false -# Executor of Worker -collector.receiver.grpc.span.worker.executor.thread_size=3 -collector.receiver.grpc.span.worker.executor.queue_size=3 -collector.receiver.grpc.span.worker.executor.monitor_enable=false -# Stream scheduler for rejected execution -collector.receiver.grpc.span.stream.scheduler_thread_size=3 -collector.receiver.grpc.span.stream.scheduler_period_millis=3 -collector.receiver.grpc.span.stream.call_init_request_count=3 -collector.receiver.grpc.span.stream.throttled_logger_ratio=3 - -# Server Option -collector.receiver.grpc.span.keepalive_time_millis=3 -collector.receiver.grpc.span.keepalive_timeout_millis=3 -collector.receiver.grpc.span.permit_keepalive_time_millis=3 -collector.receiver.grpc.span.connection_idle_timeout_millis=3 -collector.receiver.grpc.span.concurrent-calls_per-connection_max=3 -collector.receiver.grpc.span.handshake_timeout_millis=3 -collector.receiver.grpc.span.flow-control_window_size_init=3MB -collector.receiver.grpc.span.header_list_size_max=3KB -collector.receiver.grpc.span.inbound_message_size_max=3MB -collector.receiver.grpc.span.receive_buffer_size=3MB - - -### For ssl config -# please choose openssl/jdk -collector.receiver.grpc.ssl.provider_type=jdk -# please insert .pem file path -collector.receiver.grpc.ssl.key_file_path=certs/server0.pem -# please insert .crt file path -collector.receiver.grpc.ssl.key_cert_file_path=certs/server0.key - -# Agent -collector.receiver.grpc.agent.ssl.bindaddress.ip=1.1.1.1 -collector.receiver.grpc.agent.ssl.bindaddress.port=19441 - -# Stat -collector.receiver.grpc.stat.ssl.bindaddress.ip=2.2.2.2 -collector.receiver.grpc.stat.ssl.bindaddress.port=29442 - -# Span -collector.receiver.grpc.span.ssl.bindaddress.ip=3.3.3.3 -collector.receiver.grpc.span.ssl.bindaddress.port=39443 \ No newline at end of file diff --git a/commons-config/pom.xml b/commons-config/pom.xml index 2927784fe214..0cf4018267f6 100644 --- a/commons-config/pom.xml +++ b/commons-config/pom.xml @@ -22,6 +22,10 @@ spring-context provided + + jakarta.validation + jakarta.validation-api + diff --git a/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ExecutorProperties.java b/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ExecutorProperties.java index 8a575fd9d78f..47b81736e035 100644 --- a/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ExecutorProperties.java +++ b/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ExecutorProperties.java @@ -17,25 +17,37 @@ package com.navercorp.pinpoint.common.config.executor; +import com.navercorp.pinpoint.common.util.CpuUtils; + +import javax.validation.constraints.Null; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + public class ExecutorProperties { - private int corePoolSize = 1; + @PositiveOrZero + protected int corePoolSize = CpuUtils.cpuCount(); - private int maxPoolSize = Integer.MAX_VALUE; + @Positive + protected int maxPoolSize = CpuUtils.workerCount(); - private int keepAliveSeconds = 60; + @PositiveOrZero + protected int keepAliveSeconds = 60; - private boolean prestartAllCoreThreads = true; + protected boolean prestartAllCoreThreads = true; - private int queueCapacity = Integer.MAX_VALUE; + @PositiveOrZero + protected int queueCapacity = 1024 * 10; - private String threadNamePrefix; + @Null + protected String threadNamePrefix; - private boolean daemon = true; + protected boolean daemon = true; - private boolean waitForTasksToCompleteOnShutdown = false; + protected boolean waitForTasksToCompleteOnShutdown = false; - private int awaitTerminationSeconds = 0; + @PositiveOrZero + protected int awaitTerminationSeconds = 0; public ExecutorProperties() { } @@ -113,6 +125,7 @@ public void setAwaitTerminationSeconds(int awaitTerminationSeconds) { this.awaitTerminationSeconds = awaitTerminationSeconds; } + @Override public String toString() { return "ExecutorProperties{" + @@ -124,7 +137,7 @@ public String toString() { ", threadNamePrefix='" + threadNamePrefix + '\'' + ", daemon=" + daemon + ", waitForTasksToCompleteOnShutdown=" + waitForTasksToCompleteOnShutdown + - ", setAwaitTerminationSeconds=" + awaitTerminationSeconds + + ", awaitTerminationSeconds=" + awaitTerminationSeconds + '}'; } } diff --git a/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ThreadPoolExecutorCustomizer.java b/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ThreadPoolExecutorCustomizer.java index a6815695009f..5968baaa750d 100644 --- a/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ThreadPoolExecutorCustomizer.java +++ b/commons-config/src/main/java/com/navercorp/pinpoint/common/config/executor/ThreadPoolExecutorCustomizer.java @@ -27,7 +27,9 @@ public void customize(ThreadPoolExecutorFactoryBean factoryBean, ExecutorPropert factoryBean.setQueueCapacity(properties.getQueueCapacity()); factoryBean.setPrestartAllCoreThreads(properties.isPrestartAllCoreThreads()); - factoryBean.setThreadNamePrefix(properties.getThreadNamePrefix()); + if (properties.getThreadNamePrefix() != null) { + factoryBean.setThreadNamePrefix(properties.getThreadNamePrefix()); + } factoryBean.setPrestartAllCoreThreads(properties.isPrestartAllCoreThreads()); factoryBean.setDaemon(properties.isDaemon()); diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/config/HbaseClientConfiguration.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/config/HbaseClientConfiguration.java index 66744223a687..19a926d727ad 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/config/HbaseClientConfiguration.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/config/HbaseClientConfiguration.java @@ -34,6 +34,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.Environment; import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; +import org.springframework.validation.annotation.Validated; import java.util.Properties; import java.util.concurrent.ExecutorService; @@ -80,13 +81,14 @@ public ExecutorCustomizer hbaseExecutorCustomizer } @Bean + @Validated @ConfigurationProperties(prefix = "hbase.client.executor") public ExecutorProperties hbaseClientExecutorProperties() { return new ExecutorProperties(); } @Bean - public FactoryBean hbaseThreadPool(ExecutorCustomizer executorCustomizer, + public FactoryBean hbaseThreadPool(@Qualifier("hbaseExecutorCustomizer") ExecutorCustomizer executorCustomizer, @Qualifier("hbaseClientExecutorProperties") ExecutorProperties properties) { ThreadPoolExecutorFactoryBean factory = new ThreadPoolExecutorFactoryBean(); executorCustomizer.customize(factory, properties); diff --git a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/logging/ThrottledLogger.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/logging/ThrottledLogger.java index fbfbe06b1fb6..6ef26cf527cf 100644 --- a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/logging/ThrottledLogger.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/logging/ThrottledLogger.java @@ -36,10 +36,7 @@ public static ThrottledLogger getLogger(Logger logger, long ratio) { private ThrottledLogger(Logger logger, long ratio) { this.logger = Objects.requireNonNull(logger, "logger"); - if (ratio < 1) { - ratio = 1; - } - this.ratio = ratio; + this.ratio = Math.max(ratio, 1); } private boolean checkLogCounter() { diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/thread/MonitoringExecutorProperties.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/thread/MonitoringExecutorProperties.java new file mode 100644 index 000000000000..a34619bfdab7 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/thread/MonitoringExecutorProperties.java @@ -0,0 +1,63 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.common.server.thread; + +import com.navercorp.pinpoint.common.config.executor.ExecutorProperties; + +import javax.validation.constraints.Positive; + +public class MonitoringExecutorProperties extends ExecutorProperties { + + protected boolean monitorEnable; + + @Positive + protected int logRate = 100; + + public boolean isMonitorEnable() { + return monitorEnable; + } + + public void setMonitorEnable(boolean monitorEnable) { + this.monitorEnable = monitorEnable; + } + + public int getLogRate() { + return logRate; + } + + public void setLogRate(int logRate) { + this.logRate = logRate; + } + + @Override + public String toString() { + return "MonitoringExecutorProperties{" + + "monitorEnable=" + monitorEnable + + ", logRate=" + logRate + + ", corePoolSize=" + corePoolSize + + ", maxPoolSize=" + maxPoolSize + + ", keepAliveSeconds=" + keepAliveSeconds + + ", prestartAllCoreThreads=" + prestartAllCoreThreads + + ", queueCapacity=" + queueCapacity + + ", threadNamePrefix='" + threadNamePrefix + '\'' + + ", daemon=" + daemon + + ", waitForTasksToCompleteOnShutdown=" + waitForTasksToCompleteOnShutdown + + ", awaitTerminationSeconds=" + awaitTerminationSeconds + + '}'; + } +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/CallerUtils.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/CallerUtils.java new file mode 100644 index 000000000000..30e747cd7af3 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/CallerUtils.java @@ -0,0 +1,68 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.common.server.util; + +import java.util.function.Function; +import java.util.stream.Stream; + +public final class CallerUtils { + + private CallerUtils() { + } + + public static final long DEFAULT_SKIP_FRAME = 1; + public static final Function, StackWalker.StackFrame> DEFAULT_CALLER_METHOD_NAME = new StackFrameFunction(DEFAULT_SKIP_FRAME); + + private static final StackWalker WALKER = StackWalker.getInstance(); + public static String getCallerMethodName() { + // log4j + // StackLocatorUtil.getStackTraceElement(1).getMethodName(); + StackWalker.StackFrame stackFrame = WALKER.walk(DEFAULT_CALLER_METHOD_NAME); + return defaultMethodName(stackFrame); + } + + public static String getCallerMethodName(long skip) { + skip += DEFAULT_SKIP_FRAME; + Function, StackWalker.StackFrame> fun = new StackFrameFunction(skip); + StackWalker.StackFrame stackFrame = WALKER.walk(fun); + return defaultMethodName(stackFrame); + } + + private static String defaultMethodName(StackWalker.StackFrame stackFrame) { + if (stackFrame == null) { + return null; + } + return stackFrame.getMethodName(); + } + + public static class StackFrameFunction implements Function, StackWalker.StackFrame> { + private final long skip; + + public StackFrameFunction(long skip) { + this.skip = skip; + } + + @Override + public StackWalker.StackFrame apply(Stream frames) { + return frames + .skip(skip) + .findFirst() + .orElse(null); + } + } +} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/CallerUtilsTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/CallerUtilsTest.java new file mode 100644 index 000000000000..e6cdc0b4194d --- /dev/null +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/CallerUtilsTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.common.server.util; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.Callable; + +class CallerUtilsTest { + private final Logger logger = LogManager.getLogger(getClass()); + + @Test + void getCallerMethodName() { + String methodName = CallerUtils.getCallerMethodName(); + Assertions.assertEquals("getCallerMethodName", methodName); + } + + @Test + void getCallerMethodName_inner() { + Callable callable = new Callable() { + @Override + public String call() throws Exception { + return CallerUtils.getCallerMethodName(); + } + }; + logger.debug("getCallerMethodName_inner: {}", callable); +// System.out.println(callable); + } + + @Test + void getCallerMethodName_lambda() { + Callable callable = () -> CallerUtils.getCallerMethodName(); + logger.debug("getCallerMethodName_lambda: {}", callable); +// System.out.println(callable); + } + + @Test + void getCallerMethodName_methodRef() { + Callable callable = CallerUtils::getCallerMethodName;; + logger.debug("getCallerMethodName_methodRef: {}", callable); +// System.out.println(callable); + } + +} \ No newline at end of file diff --git a/flink/pom.xml b/flink/pom.xml index 1e0023149ffc..f6ee54491483 100644 --- a/flink/pom.xml +++ b/flink/pom.xml @@ -127,6 +127,10 @@ org.springframework spring-context-support + + org.springframework.boot + spring-boot-starter-validation + com.github.ben-manes.caffeine caffeine diff --git a/flink/src/main/java/com/navercorp/pinpoint/flink/FlinkModule.java b/flink/src/main/java/com/navercorp/pinpoint/flink/FlinkModule.java index 08f73cf8452d..e1298f349d50 100644 --- a/flink/src/main/java/com/navercorp/pinpoint/flink/FlinkModule.java +++ b/flink/src/main/java/com/navercorp/pinpoint/flink/FlinkModule.java @@ -17,13 +17,21 @@ package com.navercorp.pinpoint.flink; +import com.navercorp.pinpoint.common.hbase.HadoopResourceCleanerRegistry; +import com.navercorp.pinpoint.common.hbase.config.HbaseClientConfiguration; +import com.navercorp.pinpoint.common.hbase.config.HbaseMultiplexerProperties; import com.navercorp.pinpoint.common.server.cluster.zookeeper.config.ClusterConfigurationFactory; import com.navercorp.pinpoint.flink.cache.FlinkCacheConfiguration; +import com.navercorp.pinpoint.flink.config.FlinkExecutorConfiguration; import com.navercorp.pinpoint.flink.dao.hbase.ApplicationDaoConfiguration; +import com.navercorp.pinpoint.flink.hbase.Hbase2HadoopResourceCleanerRegistry; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportResource; +import org.springframework.context.annotation.PropertySource; @Configuration @ComponentScan(basePackages = { @@ -32,17 +40,31 @@ @ImportResource({ "classpath:applicationContext-flink.xml", - "classpath:applicationContext-flink-profile.xml", "classpath:applicationContext-flink-extend.xml", - "classpath:applicationContext-flink-clean.xml", "classpath:applicationContext-hbase.xml", }) @Import({ FlinkCacheConfiguration.class, ApplicationDaoConfiguration.class, + FlinkExecutorConfiguration.class, + HbaseClientConfiguration.class, ClusterConfigurationFactory.class }) +@PropertySource(name = "FlinkModule", value = { + "classpath:profiles/${pinpoint.profiles.active:local}/hbase.properties", + "classpath:profiles/${pinpoint.profiles.active:local}/pinpoint-flink.properties" +}) public class FlinkModule { + @Bean + public HadoopResourceCleanerRegistry hbase2HadoopResourceCleanerRegistry() { + return new Hbase2HadoopResourceCleanerRegistry(); + } + + @Bean + @ConfigurationProperties(prefix = "hbase.client.async") + public HbaseMultiplexerProperties hbaseMultiplexerProperties() { + return new HbaseMultiplexerProperties(); + } } diff --git a/flink/src/main/java/com/navercorp/pinpoint/flink/config/DataReceiverProperties.java b/flink/src/main/java/com/navercorp/pinpoint/flink/config/DataReceiverProperties.java index 1e14baa96873..abed6fd727aa 100644 --- a/flink/src/main/java/com/navercorp/pinpoint/flink/config/DataReceiverProperties.java +++ b/flink/src/main/java/com/navercorp/pinpoint/flink/config/DataReceiverProperties.java @@ -16,14 +16,12 @@ package com.navercorp.pinpoint.flink.config; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; import com.navercorp.pinpoint.common.server.config.AnnotationVisitor; import com.navercorp.pinpoint.common.server.config.LoggingEvent; import com.navercorp.pinpoint.common.util.Assert; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; import javax.annotation.PostConstruct; @@ -39,15 +37,6 @@ public class DataReceiverProperties { @Value("${flink.receiver.base.port:9994}") private int bindPort; - @Value("${flink.receiver.base.worker.threadSize:128}") - private int workerThreadSize; - - @Value("${flink.receiver.base.worker.queueSize:5120}") - private int workerQueueSize; - - @Value("${flink.receiver.base.worker.monitor:false}") - private boolean workerMonitorEnable; - public DataReceiverProperties() { } @@ -65,8 +54,6 @@ public void log() { private void validate() { Assert.isTrue(bindPort > 0, "bindPort must be greater than 0"); - Assert.isTrue(workerThreadSize > 0, "workerThreadSize must be greater than 0"); - Assert.isTrue(workerQueueSize > 0, "workerQueueSize must be greater than 0"); } public String getBindIp() { @@ -78,31 +65,12 @@ public int getBindPort() { return bindPort; } - public int getWorkerThreadSize() { - return workerThreadSize; - } - - public int getWorkerQueueSize() { - return workerQueueSize; - } - - public boolean isWorkerMonitorEnable() { - return workerMonitorEnable; - } - - @Bean - public ExecutorProperties baseExecutorProperties() { - return new ExecutorProperties(workerThreadSize, workerQueueSize, workerMonitorEnable); - } @Override public String toString() { final StringBuilder sb = new StringBuilder("AgentBaseDataReceiverProperties{"); sb.append("bindIp='").append(bindIp).append('\''); sb.append(", bindPort=").append(bindPort); - sb.append(", workerThreadSize=").append(workerThreadSize); - sb.append(", workerQueueSize=").append(workerQueueSize); - sb.append(", workerMonitorEnable=").append(workerMonitorEnable); sb.append('}'); return sb.toString(); } diff --git a/flink/src/main/java/com/navercorp/pinpoint/flink/config/FlinkExecutorConfiguration.java b/flink/src/main/java/com/navercorp/pinpoint/flink/config/FlinkExecutorConfiguration.java new file mode 100644 index 000000000000..e26cc8dcb208 --- /dev/null +++ b/flink/src/main/java/com/navercorp/pinpoint/flink/config/FlinkExecutorConfiguration.java @@ -0,0 +1,68 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.flink.config; + +import com.codahale.metrics.MetricRegistry; +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import com.navercorp.pinpoint.common.config.executor.ThreadPoolExecutorCustomizer; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; +import com.navercorp.pinpoint.common.server.util.CallerUtils; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; +import org.springframework.validation.annotation.Validated; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +public class FlinkExecutorConfiguration { + + @Bean + public ExecutorCustomizer flinkExecutorCustomizer() { + return new ThreadPoolExecutorCustomizer(); + } + + @Bean + public MonitoringExecutors flnkMonitoringExecutors(@Autowired(required = false) MetricRegistry metricRegistry) { + ExecutorCustomizer customizer = flinkExecutorCustomizer(); + return new MonitoringExecutors(customizer, metricRegistry); + } + + + @Bean + @Validated + @ConfigurationProperties("flink.receiver.base.worker") + public MonitoringExecutorProperties flinkWorkerExecutorProperties() { + return new MonitoringExecutorProperties(); + } + + @Bean + public FactoryBean flinkWorker(MonitoringExecutors executors) { + String beanName = CallerUtils.getCallerMethodName(); + MonitoringExecutorProperties properties = flinkWorkerExecutorProperties(); + properties.setLogRate(1); + ThreadPoolExecutorFactoryBean factoryBean = executors.newExecutorFactoryBean(properties, beanName); + factoryBean.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); + return factoryBean; + } +} diff --git a/flink/src/main/resources/applicationContext-flink-clean.xml b/flink/src/main/resources/applicationContext-flink-clean.xml deleted file mode 100644 index 81031d7fe704..000000000000 --- a/flink/src/main/resources/applicationContext-flink-clean.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/flink/src/main/resources/applicationContext-flink-profile.xml b/flink/src/main/resources/applicationContext-flink-profile.xml deleted file mode 100644 index 23f26d80f260..000000000000 --- a/flink/src/main/resources/applicationContext-flink-profile.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - classpath:profiles/local/hbase.properties - classpath:profiles/local/pinpoint-flink.properties - - - - - - - - - - classpath:profiles/release/hbase.properties - classpath:profiles/release/pinpoint-flink.properties - - - - - - \ No newline at end of file diff --git a/flink/src/main/resources/applicationContext-flink.xml b/flink/src/main/resources/applicationContext-flink.xml index 7090b853dac6..df387b35b6d8 100644 --- a/flink/src/main/resources/applicationContext-flink.xml +++ b/flink/src/main/resources/applicationContext-flink.xml @@ -83,23 +83,6 @@ - - - - - - - - - - - - - - - - - diff --git a/flink/src/main/resources/applicationContext-hbase.xml b/flink/src/main/resources/applicationContext-hbase.xml index d4f80e340bfb..1479523334a1 100644 --- a/flink/src/main/resources/applicationContext-hbase.xml +++ b/flink/src/main/resources/applicationContext-hbase.xml @@ -8,8 +8,7 @@ - - + diff --git a/flink/src/main/resources/profiles/local/pinpoint-flink.properties b/flink/src/main/resources/profiles/local/pinpoint-flink.properties index e7aa42a53f7e..8febc00bedea 100644 --- a/flink/src/main/resources/profiles/local/pinpoint-flink.properties +++ b/flink/src/main/resources/profiles/local/pinpoint-flink.properties @@ -6,9 +6,10 @@ flink.receiver.base.ip=0.0.0.0 flink.receiver.base.port=19994 # number of tcp worker threads -flink.receiver.base.worker.threadSize=8 +flink.receiver.base.worker.corePoolSize=8 +flink.receiver.base.worker.maxPoolSize=8 # capacity of tcp worker queue -flink.receiver.base.worker.queueSize=1024 +flink.receiver.base.worker.queueCapacity=1024 # monitoring for tcp worker flink.receiver.base.worker.monitor=true @@ -19,9 +20,10 @@ flink.receiver.base.worker.monitor=true #$ /sbin/sysctl -a | grep -e rmem -e wmem # number of agent event worker threads -collector.agentEventWorker.threadSize=4 +collector.agentEventWorker.corePoolSize=4 +collector.agentEventWorker.maxPoolSize=4 # capacity of agent event worker queue -collector.agentEventWorker.queueSize=1024 +collector.agentEventWorker.queueCapacity=1024 #collector.admin.password= #collector.admin.api.rest.active= diff --git a/flink/src/main/resources/profiles/release/pinpoint-flink.properties b/flink/src/main/resources/profiles/release/pinpoint-flink.properties index 15318c6938e1..51e5ed3915b5 100644 --- a/flink/src/main/resources/profiles/release/pinpoint-flink.properties +++ b/flink/src/main/resources/profiles/release/pinpoint-flink.properties @@ -6,9 +6,10 @@ flink.receiver.base.ip=0.0.0.0 flink.receiver.base.port=19994 # number of tcp worker threads -flink.receiver.base.worker.threadSize=8 +flink.receiver.base.worker.corePoolSize=8 +flink.receiver.base.worker.maxPoolSize=8 # capacity of tcp worker queue -flink.receiver.base.worker.queueSize=1024 +flink.receiver.base.worker.queueCapacity=1024 # monitoring for tcp worker flink.receiver.base.worker.monitor=true @@ -19,9 +20,10 @@ flink.receiver.base.worker.monitor=true #$ /sbin/sysctl -a | grep -e rmem -e wmem # number of agent event worker threads -collector.agentEventWorker.threadSize=4 +collector.agentEventWorker.corePoolSize=4 +collector.agentEventWorker.maxPoolSize=4 # capacity of agent event worker queue -collector.agentEventWorker.queueSize=1024 +collector.agentEventWorker.queueCapacity=1024 #collector.admin.password= #collector.admin.api.rest.active= diff --git a/flink/src/test/java/com/navercorp/pinpoint/flink/config/DataReceiverPropertiesTest.java b/flink/src/test/java/com/navercorp/pinpoint/flink/config/DataReceiverPropertiesTest.java index f79579f081ff..b2073025da3e 100644 --- a/flink/src/test/java/com/navercorp/pinpoint/flink/config/DataReceiverPropertiesTest.java +++ b/flink/src/test/java/com/navercorp/pinpoint/flink/config/DataReceiverPropertiesTest.java @@ -1,37 +1,61 @@ package com.navercorp.pinpoint.flink.config; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.validation.annotation.Validated; @TestPropertySource(properties = { "flink.receiver.base.ip:0.0.0.2", "flink.receiver.base.port:39994", - "flink.receiver.base.worker.threadSize:33", - "flink.receiver.base.worker.queueSize:29", - "flink.receiver.base.worker.monitor:true", + "flink.receiver.base.worker.corePoolSize:33", + "flink.receiver.base.worker.maxPoolSize:32", + "flink.receiver.base.worker.queueCapacity:29", + "flink.receiver.base.worker.monitor-enable:true", }) -@ContextConfiguration(classes = DataReceiverProperties.class) +@ContextConfiguration(classes = { + DataReceiverProperties.class, + DataReceiverPropertiesTest.DataReceiverTestConfig.class +}) @ExtendWith(SpringExtension.class) class DataReceiverPropertiesTest { + @Configuration + @EnableConfigurationProperties + static class DataReceiverTestConfig { + @Bean + @Validated + @ConfigurationProperties("flink.receiver.base.worker") + public MonitoringExecutorProperties flinkWorkerExecutorProperties() { + return new MonitoringExecutorProperties(); + } + } + @Autowired DataReceiverProperties properties; + @Autowired + MonitoringExecutorProperties executorProperties; @Test public void properties() { - Assertions.assertEquals(properties.getBindIp(), "0.0.0.2"); - Assertions.assertEquals(properties.getBindPort(), 39994); - Assertions.assertEquals(properties.getWorkerThreadSize(), 33); - Assertions.assertEquals(properties.getWorkerQueueSize(), 29); - Assertions.assertTrue(properties.isWorkerMonitorEnable()); + Assertions.assertEquals("0.0.0.2", properties.getBindIp()); + Assertions.assertEquals(39994, properties.getBindPort()); + Assertions.assertEquals(33, executorProperties.getCorePoolSize()); + Assertions.assertEquals(32, executorProperties.getMaxPoolSize()); + Assertions.assertEquals(29, executorProperties.getQueueCapacity()); + Assertions.assertTrue(executorProperties.isMonitorEnable()); } } \ No newline at end of file diff --git a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverProperties.java b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverProperties.java index 1d4fb58b2a31..3d985c70dc4a 100644 --- a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverProperties.java +++ b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverProperties.java @@ -15,7 +15,6 @@ */ package com.navercorp.pinpoint.log.collector.grpc; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; import com.navercorp.pinpoint.collector.grpc.config.GrpcReceiverProperties; import com.navercorp.pinpoint.collector.receiver.BindAddress; import com.navercorp.pinpoint.grpc.server.ServerOption; @@ -28,12 +27,9 @@ final class GrpcLogReceiverProperties extends GrpcReceiverProperties { GrpcLogReceiverProperties( boolean enable, BindAddress bindAddress, - ExecutorProperties serverExecutor, - ExecutorProperties serverCallExecutor, - ExecutorProperties workerExecutor, ServerOption serverOption ) { - super(enable, bindAddress, serverExecutor, serverCallExecutor, workerExecutor, serverOption); + super(enable, bindAddress, serverOption); } } diff --git a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverPropertiesConfig.java b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverPropertiesConfig.java index e5353970b897..0f9b76fc5bcb 100644 --- a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverPropertiesConfig.java +++ b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/GrpcLogReceiverPropertiesConfig.java @@ -15,9 +15,9 @@ */ package com.navercorp.pinpoint.log.collector.grpc; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; import com.navercorp.pinpoint.collector.grpc.config.GrpcPropertiesServerOptionBuilder; import com.navercorp.pinpoint.collector.receiver.BindAddress; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.grpc.server.ServerOption; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -51,22 +51,22 @@ public BindAddress.Builder newBindAddressBuilder() { return BindAddress.newBuilder(); } - @Bean(SERVER_EXECUTOR) + @Bean @ConfigurationProperties(SERVER_EXECUTOR) - public ExecutorProperties.Builder newServerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + public MonitoringExecutorProperties grpcLogServerExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(SERVER_CALL_EXECUTOR) + @Bean @ConfigurationProperties(SERVER_CALL_EXECUTOR) - public ExecutorProperties.Builder newServerCallExecutorBuilder() { - return ExecutorProperties.newBuilder(); + public MonitoringExecutorProperties grpcLogServerCallExecutorProperties() { + return new MonitoringExecutorProperties(); } - @Bean(WORKER_EXECUTOR) + @Bean @ConfigurationProperties(WORKER_EXECUTOR) - public ExecutorProperties.Builder newWorkerExecutorBuilder() { - return ExecutorProperties.newBuilder(); + public MonitoringExecutorProperties grpcLogWorkerExecutorProperties() { + return new MonitoringExecutorProperties(); } @Bean(SERVER_OPTION) @@ -76,22 +76,16 @@ public GrpcPropertiesServerOptionBuilder newServerOption() { return new GrpcPropertiesServerOptionBuilder(); } - @Bean("grpcLogReceiverConfig") - public GrpcLogReceiverProperties newLogReceiverConfig(Environment environment) { + @Bean + public GrpcLogReceiverProperties grpcLogReceiverConfig(Environment environment) { boolean enable = environment.getProperty("collector.receiver.grpc.log.enable", boolean.class, false); final ServerOption serverOption = newServerOption().build(); final BindAddress bindAddress = newBindAddressBuilder().build(); - final ExecutorProperties serverExecutor = newServerExecutorBuilder().build(); - final ExecutorProperties serverCallExecutor = newServerCallExecutorBuilder().build(); - final ExecutorProperties workerExecutor = newWorkerExecutorBuilder().build(); return new GrpcLogReceiverProperties( enable, bindAddress, - serverExecutor, - serverCallExecutor, - workerExecutor, serverOption ); } diff --git a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/LogCollectorGrpcServerConfig.java b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/LogCollectorGrpcServerConfig.java index f0495cb12f31..b5f225801061 100644 --- a/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/LogCollectorGrpcServerConfig.java +++ b/log/log-collector/src/main/java/com/navercorp/pinpoint/log/collector/grpc/LogCollectorGrpcServerConfig.java @@ -15,12 +15,12 @@ */ package com.navercorp.pinpoint.log.collector.grpc; -import com.codahale.metrics.MetricRegistry; -import com.navercorp.pinpoint.collector.config.ExecutorProperties; -import com.navercorp.pinpoint.collector.receiver.ExecutorFactoryBean; +import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors; import com.navercorp.pinpoint.collector.receiver.grpc.GrpcReceiver; import com.navercorp.pinpoint.collector.receiver.grpc.SimpleServerCallExecutorSupplier; +import com.navercorp.pinpoint.common.server.thread.MonitoringExecutorProperties; import com.navercorp.pinpoint.common.server.util.AddressFilter; +import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.grpc.HeaderReader; import com.navercorp.pinpoint.grpc.log.LogGrpc; import com.navercorp.pinpoint.log.collector.grpc.context.LogAgentHeader; @@ -29,7 +29,7 @@ import com.navercorp.pinpoint.log.collector.service.LogProviderService; import com.navercorp.pinpoint.log.collector.service.LogServiceConfig; import io.grpc.ServerInterceptor; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; @@ -38,64 +38,35 @@ import java.util.List; import java.util.concurrent.Executor; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.ExecutorService; /** * @author youngjin.kim2 */ @Configuration -@Import({ GrpcLogReceiverPropertiesConfig.class, LogServiceConfig.class }) +@Import({GrpcLogReceiverPropertiesConfig.class, LogServiceConfig.class}) public class LogCollectorGrpcServerConfig { - @Bean("abortPolicy") - ThreadPoolExecutor.AbortPolicy abortPolicy() { - return new ThreadPoolExecutor.AbortPolicy(); - } @Bean("grpcLogServerExecutor") - ExecutorFactoryBean grpcLogServerExecutor( - ThreadPoolExecutor.AbortPolicy abortPolicy, - @Qualifier("grpcLogReceiverConfig") GrpcLogReceiverProperties receiverConfig - ) { - final ExecutorProperties config = receiverConfig.getServerExecutor(); - final ExecutorFactoryBean factory = new ExecutorFactoryBean(); - factory.setRejectedExecutionHandler(abortPolicy); - factory.setDaemon(true); - factory.setWaitForTasksToCompleteOnShutdown(true); - factory.setAwaitTerminationSeconds(10); - factory.setPrestartAllCoreThreads(true); - factory.setLogRate(100); - factory.setExecutorProperties(config); - factory.setThreadNamePrefix("Pinpoint-GrpcLog-Server-"); - return factory; + public FactoryBean grpcLogServerExecutor(MonitoringExecutors executors, + @Qualifier("grpcLogServerExecutorProperties") + MonitoringExecutorProperties properties) { + String beanName = CallerUtils.getCallerMethodName(); + return executors.newExecutorFactoryBean(properties, beanName); } @Bean("grpcLogServerCallExecutor") - ExecutorFactoryBean grpcLogServerCallExecutor( - ThreadPoolExecutor.AbortPolicy abortPolicy, - @Qualifier("grpcLogReceiverConfig") GrpcLogReceiverProperties receiverConfig, - @Autowired(required = false) MetricRegistry metricRegistry - ) { - final ExecutorProperties config = receiverConfig.getServerCallExecutor(); - final ExecutorFactoryBean factory = new ExecutorFactoryBean(); - factory.setRejectedExecutionHandler(abortPolicy); - factory.setDaemon(true); - factory.setWaitForTasksToCompleteOnShutdown(true); - factory.setAwaitTerminationSeconds(10); - factory.setPrestartAllCoreThreads(true); - factory.setExecutorProperties(config); - factory.setThreadNamePrefix("Pinpoint-GrpcLog-Server-"); - factory.setLogRate(1); - - if (metricRegistry != null) { - factory.setRegistry(metricRegistry); - } - - return factory; + public FactoryBean grpcLogServerCallExecutor(MonitoringExecutors executors, + @Qualifier("grpcLogServerCallExecutorProperties") + MonitoringExecutorProperties properties) { + String beanName = CallerUtils.getCallerMethodName(); + properties.setLogRate(1); + return executors.newExecutorFactoryBean(properties, beanName); } @Bean("logInterceptorList") - List logInterceptorList() { + public List logInterceptorList() { final HeaderReader headerReader = new LogAgentHeaderReader(); final ServerInterceptor interceptor = new LogHeaderPropagationInterceptor(headerReader); return List.of(interceptor); @@ -103,17 +74,17 @@ List logInterceptorList() { @Bean("addressFilter") @ConditionalOnMissingBean(name = "addressFilter") - AddressFilter allAddressFilter() { + public AddressFilter allAddressFilter() { return AddressFilter.ALL; } @Bean - LogGrpc.LogImplBase logService(LogProviderService service) { + public LogGrpc.LogImplBase logService(LogProviderService service) { return new LogGrpcService(service); } @Bean - GrpcReceiver grpcLogReceiver( + public GrpcReceiver grpcLogReceiver( @Qualifier("grpcLogReceiverConfig") GrpcLogReceiverProperties receiverConfig, @Qualifier("grpcLogServerExecutor") Executor serverExecutor, @Qualifier("grpcLogServerCallExecutor") Executor serverCallExecutor, diff --git a/log/log-collector/src/main/resources/log/profiles/local/pinpoint-collector-log-grpc.properties b/log/log-collector/src/main/resources/log/profiles/local/pinpoint-collector-log-grpc.properties index 040c6b2a3d15..714e34a7efc8 100644 --- a/log/log-collector/src/main/resources/log/profiles/local/pinpoint-collector-log-grpc.properties +++ b/log/log-collector/src/main/resources/log/profiles/local/pinpoint-collector-log-grpc.properties @@ -4,16 +4,19 @@ collector.receiver.grpc.log.enable=true collector.receiver.grpc.log.bindaddress.ip=0.0.0.0 collector.receiver.grpc.log.bindaddress.port=15600 # Executor of Server -collector.receiver.grpc.log.server.executor.thread_size=8 -collector.receiver.grpc.log.server.executor.queue_size=256 -collector.receiver.grpc.log.server.executor.monitor_enable=false +collector.receiver.grpc.log.server.executor.corePoolSize=8 +collector.receiver.grpc.log.server.executor.maxPoolSize=8 +collector.receiver.grpc.log.server.executor.queueCapacity=256 +collector.receiver.grpc.log.server.executor.monitor-enable=false # Call Executor of Server -collector.receiver.grpc.log.server-call.executor.thread_size=8 -collector.receiver.grpc.log.server-call.executor.queue_size=256 +collector.receiver.grpc.log.server-call.executor.corePoolSize=8 +collector.receiver.grpc.log.server-call.executor.maxPoolSize=8 +collector.receiver.grpc.log.server-call.executor.queueCapacity=256 collector.receiver.grpc.log.server-call.executor.monitor_enable=true # Executor of Worker -collector.receiver.grpc.log.worker.executor.thread_size=16 -collector.receiver.grpc.log.worker.executor.queue_size=1024 +collector.receiver.grpc.log.worker.executor.corePoolSize=16 +collector.receiver.grpc.log.worker.executor.maxPoolSize=16 +collector.receiver.grpc.log.worker.executor.queueCapacity=1024 collector.receiver.grpc.log.worker.executor.monitor_enable=true diff --git a/log/log-collector/src/main/resources/log/profiles/release/pinpoint-collector-log-grpc.properties b/log/log-collector/src/main/resources/log/profiles/release/pinpoint-collector-log-grpc.properties index 040c6b2a3d15..6739d540891f 100644 --- a/log/log-collector/src/main/resources/log/profiles/release/pinpoint-collector-log-grpc.properties +++ b/log/log-collector/src/main/resources/log/profiles/release/pinpoint-collector-log-grpc.properties @@ -4,17 +4,20 @@ collector.receiver.grpc.log.enable=true collector.receiver.grpc.log.bindaddress.ip=0.0.0.0 collector.receiver.grpc.log.bindaddress.port=15600 # Executor of Server -collector.receiver.grpc.log.server.executor.thread_size=8 -collector.receiver.grpc.log.server.executor.queue_size=256 -collector.receiver.grpc.log.server.executor.monitor_enable=false +collector.receiver.grpc.log.server.executor.corePoolSize=8 +collector.receiver.grpc.log.server.executor.maxPoolSize=8 +collector.receiver.grpc.log.server.executor.queueCapacity=256 +collector.receiver.grpc.log.server.executor.monitor-enable=false # Call Executor of Server -collector.receiver.grpc.log.server-call.executor.thread_size=8 -collector.receiver.grpc.log.server-call.executor.queue_size=256 -collector.receiver.grpc.log.server-call.executor.monitor_enable=true +collector.receiver.grpc.log.server-call.executor.corePoolSize=8 +collector.receiver.grpc.log.server-call.executor.maxPoolSize=8 +collector.receiver.grpc.log.server-call.executor.queueCapacity=256 +collector.receiver.grpc.log.server-call.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.log.worker.executor.thread_size=16 -collector.receiver.grpc.log.worker.executor.queue_size=1024 -collector.receiver.grpc.log.worker.executor.monitor_enable=true +collector.receiver.grpc.log.worker.executor.corePoolSize=16 +collector.receiver.grpc.log.worker.executor.maxPoolSize=16 +collector.receiver.grpc.log.worker.executor.queueCapacity=1024 +collector.receiver.grpc.log.worker.executor.monitor-enable=true ### For ssl config diff --git a/metric-module/collector-starter/src/main/resources/profiles/local/pinpoint-collector-grpc.properties b/metric-module/collector-starter/src/main/resources/profiles/local/pinpoint-collector-grpc.properties index 1f39fbafb847..84bb5bcadfd9 100644 --- a/metric-module/collector-starter/src/main/resources/profiles/local/pinpoint-collector-grpc.properties +++ b/metric-module/collector-starter/src/main/resources/profiles/local/pinpoint-collector-grpc.properties @@ -4,17 +4,20 @@ collector.receiver.grpc.agent.enable=true collector.receiver.grpc.agent.ip=0.0.0.0 collector.receiver.grpc.agent.port=9991 # Executor of Server -collector.receiver.grpc.agent.server.executor.thread.size=8 -collector.receiver.grpc.agent.server.executor.queue.size=256 -collector.receiver.grpc.agent.server.executor.monitor.enable=false +collector.receiver.grpc.agent.server.executor.corePoolSize=8 +collector.receiver.grpc.agent.server.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server.executor.queueCapacity=256 +collector.receiver.grpc.agent.server.executor.monitor-enable=false # Call Executor of Server -collector.receiver.grpc.agent.server-call.executor.thread.size=8 -collector.receiver.grpc.agent.server-call.executor.queue.size=256 -collector.receiver.grpc.agent.server-call.executor.monitor.enable=true +collector.receiver.grpc.agent.server-call.executor.corePoolSize=8 +collector.receiver.grpc.agent.server-call.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server-call.executor.queueCapacity=256 +collector.receiver.grpc.agent.server-call.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.agent.worker.executor.thread.size=16 -collector.receiver.grpc.agent.worker.executor.queue.size=1024 -collector.receiver.grpc.agent.worker.executor.monitor.enable=true +collector.receiver.grpc.agent.worker.executor.corePoolSize=16 +collector.receiver.grpc.agent.worker.executor.maxPoolSize=16 +collector.receiver.grpc.agent.worker.executor.queueCapacity=1024 +collector.receiver.grpc.agent.worker.executor.monitor-enable=true # Stat @@ -22,15 +25,18 @@ collector.receiver.grpc.stat.enable=true collector.receiver.grpc.stat.ip=0.0.0.0 collector.receiver.grpc.stat.port=9992 # Executor of Server -collector.receiver.grpc.stat.server.executor.thread.size=4 -collector.receiver.grpc.stat.server.executor.queue.size=256 -collector.receiver.grpc.stat.server.executor.monitor.enable=true +collector.receiver.grpc.stat.server.executor.corePoolSize=4 +collector.receiver.grpc.stat.server.executor.maxPoolSize=4 +collector.receiver.grpc.stat.server.executor.queueCapacity=256 +collector.receiver.grpc.stat.server.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.stat.worker.executor.thread.size=16 -collector.receiver.grpc.stat.worker.executor.queue.size=1024 -collector.receiver.grpc.stat.worker.executor.monitor.enable=true +collector.receiver.grpc.stat.worker.executor.corePoolSize=16 +collector.receiver.grpc.stat.worker.executor.maxPoolSize=16 +collector.receiver.grpc.stat.worker.executor.queueCapacity=1024 +collector.receiver.grpc.stat.worker.executor.monitor-enable=true # Stream scheduler for rejected execution -collector.receiver.grpc.stat.stream.scheduler.thread.size=1 +collector.receiver.grpc.stat.stream.scheduler.corePoolSize=1 +collector.receiver.grpc.stat.stream.scheduler.maxPoolSize=1 collector.receiver.grpc.stat.stream.scheduler.period.millis=1000 collector.receiver.grpc.stat.stream.call.init.request.count=100 collector.receiver.grpc.stat.stream.scheduler.recovery.message.count=100 @@ -41,16 +47,18 @@ collector.receiver.grpc.span.enable=true collector.receiver.grpc.span.ip=0.0.0.0 collector.receiver.grpc.span.port=9993 # Executor of Server -collector.receiver.grpc.span.server.executor.thread.size=4 -collector.receiver.grpc.span.server.executor.queue.size=256 -collector.receiver.grpc.span.server.executor.monitor.enable=true +collector.receiver.grpc.span.server.executor.corePoolSize=4 +collector.receiver.grpc.span.server.executor.maxPoolSize=4 +collector.receiver.grpc.span.server.executor.queueCapacity=256 +collector.receiver.grpc.span.server.executor.monitor-enable=true # Executor of Worker -collector.receiver.grpc.span.worker.executor.thread.size=32 -collector.receiver.grpc.span.worker.executor.queue.size=1024 -collector.receiver.grpc.span.worker.executor.monitor.enable=true +collector.receiver.grpc.span.worker.executor.corePoolSize=32 +collector.receiver.grpc.span.worker.executor.maxPoolSize=32 +collector.receiver.grpc.span.worker.executor.queueCapacity=1024 +collector.receiver.grpc.span.worker.executor.monitor-enable=true # Stream scheduler for rejected execution -collector.receiver.grpc.span.stream.scheduler.thread.size=1 +collector.receiver.grpc.span.stream.scheduler_thread_size=1 collector.receiver.grpc.span.stream.scheduler.period.millis=1000 collector.receiver.grpc.span.stream.call.init.request.count=100 collector.receiver.grpc.span.stream.scheduler.recovery.message.count=100 diff --git a/metric-module/collector-starter/src/main/resources/profiles/release/pinpoint-collector-grpc.properties b/metric-module/collector-starter/src/main/resources/profiles/release/pinpoint-collector-grpc.properties index 676b2a73379e..a42e0b3988f5 100644 --- a/metric-module/collector-starter/src/main/resources/profiles/release/pinpoint-collector-grpc.properties +++ b/metric-module/collector-starter/src/main/resources/profiles/release/pinpoint-collector-grpc.properties @@ -4,18 +4,21 @@ collector.receiver.grpc.agent.enable=true collector.receiver.grpc.agent.ip=0.0.0.0 collector.receiver.grpc.agent.port=9991 # Executor of Server -collector.receiver.grpc.agent.server.executor.thread.size=8 -collector.receiver.grpc.agent.server.executor.queue.size=256 -collector.receiver.grpc.agent.server.executor.monitor.enable=false +collector.receiver.grpc.agent.server.executor.corePoolSize=8 +collector.receiver.grpc.agent.server.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server.executor.queueCapacity=256 +collector.receiver.grpc.agent.server.executor.monitor-enable=false # Call Executor of Server -collector.receiver.grpc.agent.server-call.executor.thread.size=8 -collector.receiver.grpc.agent.server-call.executor.queue.size=256 -collector.receiver.grpc.agent.server-call.executor.monitor.enable=true +collector.receiver.grpc.agent.server-call.executor.corePoolSize=8 +collector.receiver.grpc.agent.server-call.executor.maxPoolSize=8 +collector.receiver.grpc.agent.server-call.executor.queueCapacity=256 +collector.receiver.grpc.agent.server-call.executor.monitor-enable=true collector.receiver.grpc.agent.server-call.executor.monitor.duration.enable=false # Executor of Worker -collector.receiver.grpc.agent.worker.executor.thread.size=256 -collector.receiver.grpc.agent.worker.executor.queue.size=5120 -collector.receiver.grpc.agent.worker.executor.monitor.enable=true +collector.receiver.grpc.agent.worker.executor.corePoolSize=256 +collector.receiver.grpc.agent.worker.executor.maxPoolSize=256 +collector.receiver.grpc.agent.worker.executor.queueCapacity=5120 +collector.receiver.grpc.agent.worker.executor.monitor-enable=true collector.receiver.grpc.agent.worker.executor.monitor.duration.enable=true @@ -24,17 +27,20 @@ collector.receiver.grpc.stat.enable=true collector.receiver.grpc.stat.ip=0.0.0.0 collector.receiver.grpc.stat.port=9992 # Executor of Server -collector.receiver.grpc.stat.server.executor.thread.size=4 -collector.receiver.grpc.stat.server.executor.queue.size=256 -collector.receiver.grpc.stat.server.executor.monitor.enable=true +collector.receiver.grpc.stat.server.executor.corePoolSize=4 +collector.receiver.grpc.stat.server.executor.maxPoolSize=4 +collector.receiver.grpc.stat.server.executor.queueCapacity=256 +collector.receiver.grpc.stat.server.executor.monitor-enable=true collector.receiver.grpc.stat.server.executor.monitor.duration.enable=false # Executor of Worker -collector.receiver.grpc.stat.worker.executor.thread.size=64 -collector.receiver.grpc.stat.worker.executor.queue.size=5120 -collector.receiver.grpc.stat.worker.executor.monitor.enable=true +collector.receiver.grpc.stat.worker.executor.corePoolSize=64 +collector.receiver.grpc.stat.worker.executor.maxPoolSize=64 +collector.receiver.grpc.stat.worker.executor.queueCapacity=5120 +collector.receiver.grpc.stat.worker.executor.monitor-enable=true collector.receiver.grpc.stat.worker.executor.monitor.duration.enable=true # Stream scheduler for rejected execution -collector.receiver.grpc.stat.stream.scheduler.thread.size=1 +collector.receiver.grpc.stat.stream.scheduler.corePoolSize=1 +collector.receiver.grpc.stat.stream.scheduler.maxPoolSize=1 collector.receiver.grpc.stat.stream.scheduler.period.millis=1000 collector.receiver.grpc.stat.stream.call.init.request.count=100 collector.receiver.grpc.stat.stream.scheduler.recovery.message.count=100 @@ -45,18 +51,20 @@ collector.receiver.grpc.span.enable=true collector.receiver.grpc.span.ip=0.0.0.0 collector.receiver.grpc.span.port=9993 # Executor of Server -collector.receiver.grpc.span.server.executor.thread.size=4 -collector.receiver.grpc.span.server.executor.queue.size=256 -collector.receiver.grpc.span.server.executor.monitor.enable=true +collector.receiver.grpc.span.server.executor.corePoolSize=4 +collector.receiver.grpc.span.server.executor.maxPoolSize=4 +collector.receiver.grpc.span.server.executor.queueCapacity=256 +collector.receiver.grpc.span.server.executor.monitor-enable=true collector.receiver.grpc.span.server.executor.monitor.duration.enable=false # Executor of Worker -collector.receiver.grpc.span.worker.executor.thread.size=512 -collector.receiver.grpc.span.worker.executor.queue.size=10240 -collector.receiver.grpc.span.worker.executor.monitor.enable=true +collector.receiver.grpc.span.worker.executor.corePoolSize=512 +collector.receiver.grpc.span.worker.executor.maxPoolSize=512 +collector.receiver.grpc.span.worker.executor.queueCapacity=10240 +collector.receiver.grpc.span.worker.executor.monitor-enable=true collector.receiver.grpc.span.worker.executor.monitor.duration.enable=true # Stream scheduler for rejected execution -collector.receiver.grpc.span.stream.scheduler.thread.size=1 +collector.receiver.grpc.span.stream.scheduler_thread_size=1 collector.receiver.grpc.span.stream.scheduler.period.millis=1000 collector.receiver.grpc.span.stream.call.init.request.count=100 collector.receiver.grpc.span.stream.scheduler.recovery.message.count=100 diff --git a/web/pom.xml b/web/pom.xml index bb8da4bd535e..6f0325d8b92a 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -395,6 +395,10 @@ 1.5.0 test + + com.navercorp.pinpoint + pinpoint-collector + diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ApplicationMapModule.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ApplicationMapModule.java index f426a1e6a9d1..7e5daf953eba 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ApplicationMapModule.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ApplicationMapModule.java @@ -17,6 +17,9 @@ package com.navercorp.pinpoint.web.applicationmap.config; +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import com.navercorp.pinpoint.common.config.executor.ExecutorProperties; +import com.navercorp.pinpoint.common.server.util.CallerUtils; import com.navercorp.pinpoint.web.applicationmap.ApplicationMapBuilderFactory; import com.navercorp.pinpoint.web.applicationmap.appender.histogram.NodeHistogramAppenderFactory; import com.navercorp.pinpoint.web.applicationmap.appender.server.ServerInfoAppenderFactory; @@ -37,6 +40,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.task.TaskDecorator; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.validation.annotation.Validated; import java.util.List; import java.util.Optional; @@ -85,6 +89,7 @@ public LinkSelectorFactory linkSelectorFactory(LinkDataMapService linkDataMapSer } @Bean + @Validated @ConfigurationProperties("web.servermap.creator.worker") public ExecutorProperties creatorExecutorProperties() { return new ExecutorProperties(); @@ -92,15 +97,18 @@ public ExecutorProperties creatorExecutorProperties() { @Bean public Executor applicationsMapCreateExecutor(@Qualifier("creatorExecutorProperties") ExecutorProperties executorProperties) { - ExecutorCustomizer customizer = executorCustomizer(); + ExecutorCustomizer customizer = executorCustomizer(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); customizer.customize(executor, executorProperties); - executor.setThreadNamePrefix("Pinpoint-Link-Selector-"); + + String beanName = CallerUtils.getCallerMethodName(); + executor.setThreadNamePrefix(beanName); return executor; } @Bean + @Validated @ConfigurationProperties("web.servermap.appender.worker") public ExecutorProperties appenderExecutorProperties() { return new ExecutorProperties(); @@ -108,21 +116,25 @@ public ExecutorProperties appenderExecutorProperties() { @Bean public Executor nodeHistogramAppendExecutor(@Qualifier("appenderExecutorProperties") ExecutorProperties executorProperties) { - ExecutorCustomizer customizer = executorCustomizer(); + ExecutorCustomizer customizer = executorCustomizer(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); customizer.customize(executor, executorProperties); - executor.setThreadNamePrefix("Pinpoint-Node-Histogram-Appender-"); + + String beanName = CallerUtils.getCallerMethodName(); + executor.setThreadNamePrefix(beanName); return executor; } @Bean public Executor serverInfoAppendExecutor(@Qualifier("appenderExecutorProperties") ExecutorProperties executorProperties) { - ExecutorCustomizer customizer = executorCustomizer(); + ExecutorCustomizer customizer = executorCustomizer(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); customizer.customize(executor, executorProperties); - executor.setThreadNamePrefix("Pinpoint-Server-Info-Appender-"); + + String beanName = CallerUtils.getCallerMethodName(); + executor.setThreadNamePrefix(beanName); return executor; } @@ -134,9 +146,9 @@ public TaskDecorator contextPropagatingTaskDecorator() { } @Bean - public ExecutorCustomizer executorCustomizer() { + public ExecutorCustomizer executorCustomizer() { TaskDecorator taskDecorator = contextPropagatingTaskDecorator(); - return new BasicExecutorCustomizer(taskDecorator); + return new TaskExecutorCustomizer(taskDecorator); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/BasicExecutorCustomizer.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/BasicExecutorCustomizer.java deleted file mode 100644 index d76f5bb6da7e..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/BasicExecutorCustomizer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2023 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.navercorp.pinpoint.web.applicationmap.config; - -import org.springframework.core.task.TaskDecorator; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -public class BasicExecutorCustomizer implements ExecutorCustomizer { - - private final TaskDecorator taskDecorator; - - public BasicExecutorCustomizer(TaskDecorator taskDecorator) { - this.taskDecorator = taskDecorator; - } - - public void applyDefaultConfiguration(ThreadPoolTaskExecutor executor) { - if (taskDecorator != null) { - executor.setTaskDecorator(taskDecorator); - } - executor.setDaemon(true); - executor.setWaitForTasksToCompleteOnShutdown(true); - executor.setAwaitTerminationSeconds(10); - } - - @Override - public void customize(ThreadPoolTaskExecutor executor, ExecutorProperties executorProperties) { - - applyDefaultConfiguration(executor); - - executor.setCorePoolSize(executorProperties.getThreadSize()); - executor.setMaxPoolSize(executorProperties.getThreadSize()); - executor.setQueueCapacity(executorProperties.getQueueSize()); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorCustomizer.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorCustomizer.java deleted file mode 100644 index 29be800a3fca..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorCustomizer.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2023 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.navercorp.pinpoint.web.applicationmap.config; - -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -public interface ExecutorCustomizer { - - void customize(ThreadPoolTaskExecutor executor, ExecutorProperties executorProperties); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorProperties.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorProperties.java deleted file mode 100644 index aa68f3b4f3d2..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/ExecutorProperties.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2023 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.navercorp.pinpoint.web.applicationmap.config; - -public class ExecutorProperties { - private int queueSize; - private int threadSize; - - public int getQueueSize() { - return queueSize; - } - - public void setQueueSize(int queueSize) { - this.queueSize = queueSize; - } - - public int getThreadSize() { - return threadSize; - } - - public void setThreadSize(int threadSize) { - this.threadSize = threadSize; - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/TaskExecutorCustomizer.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/TaskExecutorCustomizer.java new file mode 100644 index 000000000000..a6d4f5b232ea --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/config/TaskExecutorCustomizer.java @@ -0,0 +1,55 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.web.applicationmap.config; + +import com.navercorp.pinpoint.common.config.executor.ExecutorCustomizer; +import com.navercorp.pinpoint.common.config.executor.ExecutorProperties; +import org.springframework.core.task.TaskDecorator; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +public class TaskExecutorCustomizer implements ExecutorCustomizer { + + private final TaskDecorator taskDecorator; + + public TaskExecutorCustomizer(TaskDecorator taskDecorator) { + this.taskDecorator = taskDecorator; + } + + + @Override + public void customize(ThreadPoolTaskExecutor executor, ExecutorProperties properties) { + + if (taskDecorator != null) { + executor.setTaskDecorator(taskDecorator); + } + + executor.setCorePoolSize(properties.getCorePoolSize()); + executor.setMaxPoolSize(properties.getMaxPoolSize()); + executor.setQueueCapacity(properties.getQueueCapacity()); + + executor.setPrestartAllCoreThreads(properties.isPrestartAllCoreThreads()); + executor.setThreadNamePrefix(properties.getThreadNamePrefix()); + executor.setPrestartAllCoreThreads(properties.isPrestartAllCoreThreads()); + executor.setDaemon(properties.isDaemon()); + + executor.setKeepAliveSeconds(properties.getKeepAliveSeconds()); + executor.setWaitForTasksToCompleteOnShutdown(properties.isWaitForTasksToCompleteOnShutdown()); + executor.setAwaitTerminationSeconds(properties.getAwaitTerminationSeconds()); + + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/realtime/RealtimeConfig.java b/web/src/main/java/com/navercorp/pinpoint/web/realtime/RealtimeConfig.java index 09bdf826f3a2..983dcd768791 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/realtime/RealtimeConfig.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/realtime/RealtimeConfig.java @@ -93,7 +93,7 @@ ActiveThreadCountService activeThreadCountService( atcDao, agentLookupService, Objects.requireNonNullElseGet(timerTaskDecoratorFactory, - () -> new PinpointWebSocketTimerTaskDecoratorFactory()), + PinpointWebSocketTimerTaskDecoratorFactory::new), scheduledExecutor, atcPeriods.getPeriodEmit(), atcPeriods.getPeriodUpdate() diff --git a/web/src/main/resources/pinpoint-web-root.properties b/web/src/main/resources/pinpoint-web-root.properties index 5ed089db808e..83dd1e38eff4 100644 --- a/web/src/main/resources/pinpoint-web-root.properties +++ b/web/src/main/resources/pinpoint-web-root.properties @@ -61,13 +61,18 @@ web.hbase.mapper.cache.string.size=-1 web.activethread.activeAgent.duration.days=7 # number of server map link select worker threads -web.servermap.creator.worker.threadSize=32 +web.servermap.creator.worker.corePoolSize=32 +web.servermap.creator.worker.maxPoolSize=32 # capacity of server map link select worker queue -web.servermap.creator.worker.queueSize=1024 +web.servermap.creator.worker.queueCapacity=1024 + # number of server node appender worker threads -web.servermap.appender.worker.threadSize=32 +web.servermap.appender.worker.corePoolSize=32 +web.servermap.appender.worker.maxPoolSize=32 # capacity of server node appender worker queue -web.servermap.appender.worker.queueSize=1024 +web.servermap.appender.worker.queueCapacity=1024 + + # Limit number of link data # If -1, there is no limit.