From cfc6f73d96003643ede965bc11127694b7dca83d Mon Sep 17 00:00:00 2001 From: emeroad Date: Thu, 25 Jul 2024 14:35:13 +0900 Subject: [PATCH] [#11278] Cleanup --- .../grpc/config/GrpcAgentConfiguration.java | 6 +++++- .../grpc/config/GrpcComponentConfiguration.java | 11 +++++++++++ .../grpc/config/GrpcSpanReceiverConfiguration.java | 5 ++++- .../grpc/config/GrpcStatReceiverConfiguration.java | 5 ++++- .../collector/receiver/grpc/GrpcReceiver.java | 14 +++----------- .../collector/receiver/grpc/monitor/Monitor.java | 1 + 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentConfiguration.java index fff6e07ec4a3..c512cb485811 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcAgentConfiguration.java @@ -28,6 +28,7 @@ import com.navercorp.pinpoint.collector.receiver.grpc.ServerInterceptorFactory; import com.navercorp.pinpoint.collector.receiver.grpc.ShutdownEventListener; import com.navercorp.pinpoint.collector.receiver.grpc.SimpleServerCallExecutorSupplier; +import com.navercorp.pinpoint.collector.receiver.grpc.monitor.Monitor; import com.navercorp.pinpoint.collector.receiver.grpc.service.AgentLifecycleListener; import com.navercorp.pinpoint.collector.receiver.grpc.service.AgentService; import com.navercorp.pinpoint.collector.receiver.grpc.service.KeepAliveService; @@ -117,7 +118,8 @@ public GrpcReceiver grpcAgentReceiver(@Qualifier("grpcAgentReceiverProperties") @Qualifier("grpcAgentServerExecutor") Executor grpcSpanExecutor, @Qualifier("grpcAgentServerCallExecutorSupplier") - SimpleServerCallExecutorSupplier simpleServerCallExecutorSupplier) { + SimpleServerCallExecutorSupplier simpleServerCallExecutorSupplier, + Monitor monitor) { GrpcReceiver grpcReceiver = new GrpcReceiver(); grpcReceiver.setBindAddress(properties.getBindAddress()); grpcReceiver.setAddressFilter(addressFilter); @@ -129,6 +131,8 @@ public GrpcReceiver grpcAgentReceiver(@Qualifier("grpcAgentReceiverProperties") grpcReceiver.setServerOption(properties.getServerOption()); grpcReceiver.setServerCallExecutorSupplier(simpleServerCallExecutorSupplier); + + grpcReceiver.setMonitor(monitor); return grpcReceiver; } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcComponentConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcComponentConfiguration.java index 44f59bd27a38..e5856408a28b 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcComponentConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/config/GrpcComponentConfiguration.java @@ -16,12 +16,15 @@ package com.navercorp.pinpoint.collector.grpc.config; +import com.navercorp.pinpoint.collector.receiver.grpc.monitor.BasicMonitor; +import com.navercorp.pinpoint.collector.receiver.grpc.monitor.Monitor; import com.navercorp.pinpoint.collector.receiver.grpc.service.DefaultServerRequestFactory; import com.navercorp.pinpoint.collector.receiver.grpc.service.ServerRequestFactory; import com.navercorp.pinpoint.common.server.bo.filter.SpanEventFilter; import com.navercorp.pinpoint.common.server.bo.grpc.CollectorGrpcSpanFactory; import com.navercorp.pinpoint.common.server.bo.grpc.GrpcSpanBinder; import io.grpc.ServerTransportFilter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -54,4 +57,12 @@ public CollectorGrpcSpanFactory collectorGrpcSpanFactory(SpanEventFilter spanEve return new CollectorGrpcSpanFactory(grpcSpanBinder, spanEventFilter); } + @Bean + public Monitor grpcReceiverMonitor(@Value("${collector.receiver.grpc.monitor.enable:true}") boolean enable) { + if (enable) { + return new BasicMonitor("GrpcReceiverMonitor"); + } else { + return Monitor.NONE; + } + } } \ No newline at end of file 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 4cc30059cac9..15c5ee28b2ff 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 @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.collector.receiver.grpc.GrpcReceiver; import com.navercorp.pinpoint.collector.receiver.grpc.ServerInterceptorFactory; import com.navercorp.pinpoint.collector.receiver.grpc.flow.RateLimitClientStreamServerInterceptor; +import com.navercorp.pinpoint.collector.receiver.grpc.monitor.Monitor; import com.navercorp.pinpoint.collector.receiver.grpc.service.ServerRequestFactory; import com.navercorp.pinpoint.collector.receiver.grpc.service.SpanService; import com.navercorp.pinpoint.collector.receiver.grpc.service.StreamExecutorServerInterceptorFactory; @@ -140,7 +141,8 @@ public GrpcReceiver grpcSpanReceiver(@Qualifier("grpcSpanReceiverProperties") List serverTransportFilterList, ChannelzRegistry channelzRegistry, @Qualifier("grpcSpanServerExecutor") - Executor grpcSpanExecutor) { + Executor grpcSpanExecutor, + Monitor monitor) { GrpcReceiver grpcReceiver = new GrpcReceiver(); grpcReceiver.setBindAddress(properties.getBindAddress()); grpcReceiver.setAddressFilter(addressFilter); @@ -151,6 +153,7 @@ public GrpcReceiver grpcSpanReceiver(@Qualifier("grpcSpanReceiverProperties") grpcReceiver.setExecutor(grpcSpanExecutor); grpcReceiver.setEnable(properties.isEnable()); grpcReceiver.setServerOption(properties.getServerOption()); + grpcReceiver.setMonitor(monitor); return grpcReceiver; } 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 e59865e48720..7a2881cf70be 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 @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.collector.receiver.grpc.GrpcReceiver; import com.navercorp.pinpoint.collector.receiver.grpc.ServerInterceptorFactory; import com.navercorp.pinpoint.collector.receiver.grpc.flow.RateLimitClientStreamServerInterceptor; +import com.navercorp.pinpoint.collector.receiver.grpc.monitor.Monitor; import com.navercorp.pinpoint.collector.receiver.grpc.service.ServerRequestFactory; import com.navercorp.pinpoint.collector.receiver.grpc.service.StatService; import com.navercorp.pinpoint.collector.receiver.grpc.service.StreamExecutorServerInterceptorFactory; @@ -145,7 +146,8 @@ public GrpcReceiver grpcStatReceiver(@Qualifier("grpcStatReceiverProperties") List serverTransportFilterList, ChannelzRegistry channelzRegistry, @Qualifier("grpcStatServerExecutor") - Executor grpcSpanExecutor) { + Executor grpcSpanExecutor, + Monitor monitor) { GrpcReceiver grpcReceiver = new GrpcReceiver(); grpcReceiver.setBindAddress(properties.getBindAddress()); grpcReceiver.setAddressFilter(addressFilter); @@ -156,6 +158,7 @@ public GrpcReceiver grpcStatReceiver(@Qualifier("grpcStatReceiverProperties") grpcReceiver.setExecutor(grpcSpanExecutor); grpcReceiver.setEnable(properties.isEnable()); grpcReceiver.setServerOption(properties.getServerOption()); + grpcReceiver.setMonitor(monitor); return grpcReceiver; } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/GrpcReceiver.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/GrpcReceiver.java index 4cde7e0604ae..ac82e529c785 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/GrpcReceiver.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/GrpcReceiver.java @@ -17,8 +17,6 @@ package com.navercorp.pinpoint.collector.receiver.grpc; import com.navercorp.pinpoint.collector.receiver.BindAddress; -import com.navercorp.pinpoint.collector.receiver.grpc.monitor.BasicMonitor; -import com.navercorp.pinpoint.collector.receiver.grpc.monitor.EmptyMonitor; import com.navercorp.pinpoint.collector.receiver.grpc.monitor.Monitor; import com.navercorp.pinpoint.common.server.util.AddressFilter; import com.navercorp.pinpoint.common.util.Assert; @@ -83,8 +81,7 @@ public class GrpcReceiver implements InitializingBean, DisposableBean, BeanNameA private Server server; private ChannelzRegistry channelzRegistry; - private boolean enableMonitor = true; - private Monitor monitor; + private Monitor monitor = Monitor.NONE; @Override @@ -99,11 +96,6 @@ public void afterPropertiesSet() throws Exception { Objects.requireNonNull(this.addressFilter, "addressFilter"); Assert.isTrue(CollectionUtils.hasLength(this.serviceList), "serviceList must not be empty"); Objects.requireNonNull(this.serverOption, "serverOption"); - if (enableMonitor) { - this.monitor = new BasicMonitor(beanName + "-Monitor"); - } else { - this.monitor = new EmptyMonitor(); - } if (sslContext != null) { this.serverFactory = new ServerFactory(beanName, this.bindAddress.getIp(), this.bindAddress.getPort(), this.executor, this.serverCallExecutorSupplier, serverOption, sslContext); @@ -267,7 +259,7 @@ public void setChannelzRegistry(ChannelzRegistry channelzRegistry) { this.channelzRegistry = Objects.requireNonNull(channelzRegistry, "channelzRegistry"); } - public void setEnableMonitor(boolean enableMonitor) { - this.enableMonitor = enableMonitor; + public void setMonitor(Monitor monitor) { + this.monitor = Objects.requireNonNull(monitor, "monitor"); } } \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/monitor/Monitor.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/monitor/Monitor.java index 8470993543a9..6060a5980520 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/monitor/Monitor.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/monitor/Monitor.java @@ -3,6 +3,7 @@ import java.io.Closeable; public interface Monitor extends Closeable { + Monitor NONE = new EmptyMonitor(); void register(Runnable job);