From bfc3031d38e7d8c9d9521c0da91a1e1211f23727 Mon Sep 17 00:00:00 2001 From: emeroad Date: Thu, 11 Jul 2024 17:14:11 +0900 Subject: [PATCH] [#noissue] Refactor ChannelzConfiguration --- .../grpc/CollectorGrpcConfiguration.java | 5 ++++- .../grpc/channelz/ChannelzConfiguration.java | 19 +++++++++++++++++++ .../channelz/DefaultChannelzRegistry.java | 2 +- .../controller/ChannelzController.java | 14 +++++++------- .../channelz}/service/ChannelzService.java | 2 +- .../service/ChannelzSocketLookup.java | 2 +- .../service/DefaultChannelzService.java | 2 +- .../service/InternalChannelzSocketLookup.java | 2 +- .../channelz/util}/HTMLBuilder.java | 2 +- .../config/GrpcComponentConfiguration.java | 7 ------- .../channelz/DefaultChannelzRegistryTest.java | 2 +- .../channelz}/service/ChannelzTestUtils.java | 2 +- .../service/DefaultChannelzServiceTest.java | 12 ++++++------ .../service/InternalChannelzLookupTest.java | 10 +++++----- 14 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/ChannelzConfiguration.java rename collector/src/main/java/com/navercorp/pinpoint/collector/{receiver => }/grpc/channelz/DefaultChannelzRegistry.java (94%) rename collector/src/main/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/controller/ChannelzController.java (85%) rename collector/src/main/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/ChannelzService.java (93%) rename collector/src/main/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/ChannelzSocketLookup.java (97%) rename collector/src/main/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/DefaultChannelzService.java (98%) rename collector/src/main/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/InternalChannelzSocketLookup.java (98%) rename collector/src/main/java/com/navercorp/pinpoint/collector/{controller => grpc/channelz/util}/HTMLBuilder.java (97%) rename collector/src/test/java/com/navercorp/pinpoint/collector/{receiver => }/grpc/channelz/DefaultChannelzRegistryTest.java (95%) rename collector/src/test/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/ChannelzTestUtils.java (98%) rename collector/src/test/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/DefaultChannelzServiceTest.java (86%) rename collector/src/test/java/com/navercorp/pinpoint/collector/{ => grpc/channelz}/service/InternalChannelzLookupTest.java (82%) diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java index 2b864d471004..7de76b770fce 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/CollectorGrpcConfiguration.java @@ -18,6 +18,7 @@ package com.navercorp.pinpoint.collector.grpc; import com.codahale.metrics.MetricRegistry; +import com.navercorp.pinpoint.collector.grpc.channelz.ChannelzConfiguration; import com.navercorp.pinpoint.collector.grpc.config.GrpcAgentConfiguration; import com.navercorp.pinpoint.collector.grpc.config.GrpcAgentReceiverConfiguration; import com.navercorp.pinpoint.collector.grpc.config.GrpcComponentConfiguration; @@ -49,7 +50,9 @@ GrpcStatConfiguration.class, GrpcStatReceiverConfiguration.class, - GrpcKeepAliveScheduler.class + GrpcKeepAliveScheduler.class, + + ChannelzConfiguration.class }) @ComponentScan({ "com.navercorp.pinpoint.collector.receiver.grpc" diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/ChannelzConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/ChannelzConfiguration.java new file mode 100644 index 000000000000..d5e6bb4b6bf5 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/ChannelzConfiguration.java @@ -0,0 +1,19 @@ +package com.navercorp.pinpoint.collector.grpc.channelz; + +import com.navercorp.pinpoint.grpc.channelz.ChannelzRegistry; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan({ + "com.navercorp.pinpoint.collector.grpc.channelz.service", + "com.navercorp.pinpoint.collector.grpc.channelz.controller" +}) +public class ChannelzConfiguration { + + @Bean + public ChannelzRegistry channelzRegistry() { + return new DefaultChannelzRegistry(); + } +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/channelz/DefaultChannelzRegistry.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/DefaultChannelzRegistry.java similarity index 94% rename from collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/channelz/DefaultChannelzRegistry.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/DefaultChannelzRegistry.java index 34902162f705..6cd9b823ca55 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/channelz/DefaultChannelzRegistry.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/DefaultChannelzRegistry.java @@ -1,4 +1,4 @@ -package com.navercorp.pinpoint.collector.receiver.grpc.channelz; +package com.navercorp.pinpoint.collector.grpc.channelz; import com.navercorp.pinpoint.grpc.channelz.ChannelzRegistry; import org.apache.logging.log4j.LogManager; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ChannelzController.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/controller/ChannelzController.java similarity index 85% rename from collector/src/main/java/com/navercorp/pinpoint/collector/controller/ChannelzController.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/controller/ChannelzController.java index 073f4fa6d8cc..5051fc9d389d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ChannelzController.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/controller/ChannelzController.java @@ -1,10 +1,10 @@ -package com.navercorp.pinpoint.collector.controller; +package com.navercorp.pinpoint.collector.grpc.channelz.controller; -import com.navercorp.pinpoint.collector.service.ChannelzService; -import com.navercorp.pinpoint.collector.service.ChannelzService.ServerStatsWithId; -import com.navercorp.pinpoint.collector.service.ChannelzService.SocketStatsWithId; -import com.navercorp.pinpoint.collector.service.ChannelzSocketLookup; -import com.navercorp.pinpoint.collector.service.ChannelzSocketLookup.SocketEntry; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzService; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzService.ServerStatsWithId; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzService.SocketStatsWithId; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzSocketLookup; +import com.navercorp.pinpoint.collector.grpc.channelz.util.HTMLBuilder; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -39,7 +39,7 @@ public List findSocketStats( @RequestParam(required = false) Integer localPort ) { List ids = this.socketLookup.find(remoteAddress, localPort).stream() - .map(SocketEntry::getSocketId) + .map(ChannelzSocketLookup.SocketEntry::getSocketId) .toList(); return this.channelzService.getSocketStatsList(ids); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChannelzService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzService.java similarity index 93% rename from collector/src/main/java/com/navercorp/pinpoint/collector/service/ChannelzService.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzService.java index 6773b2e1a611..7007ba3bd21d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChannelzService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzService.java @@ -1,4 +1,4 @@ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; import io.grpc.InternalChannelz.ServerStats; import io.grpc.InternalChannelz.SocketStats; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChannelzSocketLookup.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzSocketLookup.java similarity index 97% rename from collector/src/main/java/com/navercorp/pinpoint/collector/service/ChannelzSocketLookup.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzSocketLookup.java index 5ca08372b960..c044bc37175d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChannelzSocketLookup.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzSocketLookup.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; import javax.annotation.Nullable; import java.util.Collection; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/DefaultChannelzService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/DefaultChannelzService.java similarity index 98% rename from collector/src/main/java/com/navercorp/pinpoint/collector/service/DefaultChannelzService.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/DefaultChannelzService.java index c8e753689f0c..aaccb0787f70 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/DefaultChannelzService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/DefaultChannelzService.java @@ -1,4 +1,4 @@ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/InternalChannelzSocketLookup.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/InternalChannelzSocketLookup.java similarity index 98% rename from collector/src/main/java/com/navercorp/pinpoint/collector/service/InternalChannelzSocketLookup.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/InternalChannelzSocketLookup.java index 913df7d572fc..a95ed740d085 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/InternalChannelzSocketLookup.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/service/InternalChannelzSocketLookup.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; import com.google.common.base.Suppliers; import com.google.common.util.concurrent.ListenableFuture; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/HTMLBuilder.java b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/util/HTMLBuilder.java similarity index 97% rename from collector/src/main/java/com/navercorp/pinpoint/collector/controller/HTMLBuilder.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/util/HTMLBuilder.java index bd2e0dcbd37c..c3f681c29cce 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/HTMLBuilder.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/grpc/channelz/util/HTMLBuilder.java @@ -1,4 +1,4 @@ -package com.navercorp.pinpoint.collector.controller; +package com.navercorp.pinpoint.collector.grpc.channelz.util; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; 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 446052d28f19..44f59bd27a38 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,13 +16,11 @@ package com.navercorp.pinpoint.collector.grpc.config; -import com.navercorp.pinpoint.collector.receiver.grpc.channelz.DefaultChannelzRegistry; 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 com.navercorp.pinpoint.grpc.channelz.ChannelzRegistry; import io.grpc.ServerTransportFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -49,11 +47,6 @@ public List serverTransportFilterList() { return List.of(); } - @Bean - public ChannelzRegistry channelzRegistry() { - return new DefaultChannelzRegistry(); - } - @Bean public CollectorGrpcSpanFactory collectorGrpcSpanFactory(SpanEventFilter spanEventFilter) { diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/channelz/DefaultChannelzRegistryTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/DefaultChannelzRegistryTest.java similarity index 95% rename from collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/channelz/DefaultChannelzRegistryTest.java rename to collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/DefaultChannelzRegistryTest.java index 6023bb72f5e6..b146ceb1765f 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/channelz/DefaultChannelzRegistryTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/DefaultChannelzRegistryTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.collector.receiver.grpc.channelz; +package com.navercorp.pinpoint.collector.grpc.channelz; import com.navercorp.pinpoint.grpc.channelz.ChannelzRegistry; import org.junit.jupiter.api.Test; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/service/ChannelzTestUtils.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzTestUtils.java similarity index 98% rename from collector/src/test/java/com/navercorp/pinpoint/collector/service/ChannelzTestUtils.java rename to collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzTestUtils.java index 12c8ff4ecd88..e2996b33209c 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/service/ChannelzTestUtils.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/ChannelzTestUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; import com.google.common.util.concurrent.ListenableFuture; import io.grpc.InternalChannelz.ServerStats; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/service/DefaultChannelzServiceTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/DefaultChannelzServiceTest.java similarity index 86% rename from collector/src/test/java/com/navercorp/pinpoint/collector/service/DefaultChannelzServiceTest.java rename to collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/DefaultChannelzServiceTest.java index c6346c7801ef..e0485568662c 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/service/DefaultChannelzServiceTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/DefaultChannelzServiceTest.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; -import com.navercorp.pinpoint.collector.service.ChannelzService.ServerStatsWithId; -import com.navercorp.pinpoint.collector.service.ChannelzService.SocketStatsWithId; -import com.navercorp.pinpoint.collector.service.ChannelzTestUtils.SimpleInternalInstrumented; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzService.ServerStatsWithId; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzService.SocketStatsWithId; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzTestUtils.SimpleInternalInstrumented; import com.navercorp.pinpoint.grpc.channelz.ChannelzRegistry; import io.grpc.InternalChannelz; import io.grpc.InternalChannelz.ServerStats; @@ -32,8 +32,8 @@ import java.util.List; -import static com.navercorp.pinpoint.collector.service.ChannelzTestUtils.mockServerStats; -import static com.navercorp.pinpoint.collector.service.ChannelzTestUtils.mockSocketStats; +import static com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzTestUtils.mockServerStats; +import static com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzTestUtils.mockSocketStats; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/service/InternalChannelzLookupTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/InternalChannelzLookupTest.java similarity index 82% rename from collector/src/test/java/com/navercorp/pinpoint/collector/service/InternalChannelzLookupTest.java rename to collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/InternalChannelzLookupTest.java index d1614fee4341..32ada62e9c55 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/service/InternalChannelzLookupTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/grpc/channelz/service/InternalChannelzLookupTest.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.navercorp.pinpoint.collector.service; +package com.navercorp.pinpoint.collector.grpc.channelz.service; -import com.navercorp.pinpoint.collector.service.ChannelzSocketLookup.SocketEntry; -import com.navercorp.pinpoint.collector.service.ChannelzTestUtils.SimpleInternalInstrumented; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzSocketLookup.SocketEntry; +import com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzTestUtils.SimpleInternalInstrumented; import io.grpc.InternalChannelz; import io.grpc.InternalChannelz.ServerStats; import io.grpc.InternalChannelz.SocketStats; @@ -29,8 +29,8 @@ import java.util.Collection; import java.util.List; -import static com.navercorp.pinpoint.collector.service.ChannelzTestUtils.mockServerStats; -import static com.navercorp.pinpoint.collector.service.ChannelzTestUtils.mockSocketStats; +import static com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzTestUtils.mockServerStats; +import static com.navercorp.pinpoint.collector.grpc.channelz.service.ChannelzTestUtils.mockSocketStats; import static org.assertj.core.api.Assertions.assertThat; /**