From ad5b46bfb58192cd26ed5acdc1d42a14f18738ca Mon Sep 17 00:00:00 2001 From: emeroad Date: Tue, 23 May 2023 11:18:30 +0900 Subject: [PATCH] [#9932] Remove thrift dependency of Agent module --- .../config/DefaultProfilerConfig.java | 2 +- .../bootstrap/config/TransportModule.java | 13 +- .../bootstrap/config/TransportModuleTest.java | 3 +- .../bootstrap/java9/module/ModuleSupport.java | 1 - collector/pom.xml | 4 + .../collector/cluster/ClusterPoint.java | 2 +- .../cluster/ClusterPointRepository.java | 3 +- .../cluster/GrpcAgentConnection.java | 6 +- .../cluster/ThriftAgentConnection.java | 2 +- .../flink/FlinkClusterConnectionManager.java | 2 +- .../cluster/flink/SenderContext.java | 2 +- .../flink/TcpDataSenderRepository.java | 2 +- .../CommandThriftToGrpcMessageConverter.java | 173 +++-- .../cluster/route/DefaultRouteHandler.java | 2 +- .../cluster/route/StreamRouteHandler.java | 5 +- .../controller/ClusterPointController.java | 2 +- .../receiver/grpc/PinpointGrpcServer.java | 4 +- .../collector/sender/FlinkTcpDataSender.java | 6 +- .../service/SendDataToFlinkService.java | 6 +- .../route/GrpcAgentConnectionTest.java | 82 --- .../receiver/DataReceiverGroupTest.java | 16 +- .../receiver/grpc/PinpointGrpcServerTest.java | 2 +- .../profiler/message/RouteResultTest.java | 26 + .../executor}/AsyncQueueingExecutor.java | 71 +- .../concurrent/executor/EmptyConsumer.java | 24 +- .../concurrent/executor/MultiConsumer.java | 12 +- .../concurrent/executor/SingleConsumer.java | 23 +- .../executor}/UnsafeArrayCollection.java | 3 +- .../message}/BypassMessageConverter.java | 2 +- .../common/profiler/message}/DataSender.java | 6 +- .../profiler/message}/EmptyDataSender.java | 13 +- .../profiler/message/EnhancedDataSender.java | 16 + .../profiler/message}/LoggingDataSender.java | 15 +- .../profiler/message}/MessageConverter.java | 2 +- .../profiler/message}/ResultResponse.java | 2 +- .../common/profiler/message/RouteResult.java | 27 + .../pinpoint/io}/DefaultResponseMessage.java | 2 +- .../pinpoint/io}/ResponseMessage.java | 2 +- .../navercorp/pinpoint/io/SpanVersion.java | 8 +- .../pinpoint/io}/SpanVersionTest.java | 3 +- pom.xml | 6 + profiler-test/pom.xml | 39 -- .../test/ApplicationContextHandler.java | 11 +- .../pinpoint/test/ListenableDataSender.java | 2 +- .../pinpoint/test/MockApiMetaDataService.java | 13 +- .../test/MockApiMetaDataServiceProvider.java | 9 +- .../test/MockTraceContextFactory.java | 11 +- .../pinpoint/test/OverrideModuleFactory.java | 7 +- .../test/PluginApplicationContextModule.java | 17 +- .../{TBaseRecorder.java => Recorder.java} | 2 +- ...orderAdaptor.java => RecorderAdaptor.java} | 16 +- .../pinpoint/test/TestSpanStorageFactory.java | 5 +- .../pinpoint/test/TestTcpDataSender.java | 6 +- .../test/junit4/BasePinpointTest.java | 28 +- .../pinpoint/test/rpc/MockRpcModule.java | 23 +- .../test/monitor/AgentStatMonitorTest.java | 16 +- profiler-thrift-datasender/pom.xml | 102 +++ .../pinpoint/thrift}/sender/ByteMessage.java | 2 +- .../sender/MaxBytesLengthPredicate.java | 33 + .../thrift}/sender/MessageSerializer.java | 2 +- .../sender/PortUnreachableHandler.java | 2 +- .../ReconnectEventListenerRegistry.java | 7 + .../thrift}/sender/RefreshStrategy.java | 6 +- .../thrift}/sender/RequestMessage.java | 10 +- .../thrift}/sender/RequestMessageFactory.java | 10 +- .../pinpoint/thrift}/sender/RetryMessage.java | 2 +- .../pinpoint/thrift}/sender/RetryQueue.java | 8 +- .../thrift}/sender/RetryRequestMessage.java | 27 +- .../thrift}/sender/TcpDataSender.java | 34 +- .../sender/ThriftMessageSerializer.java | 54 +- .../sender/ThriftUdpMessageSerializer.java | 67 ++ .../thrift}/sender/UdpDataSender.java | 18 +- .../thrift}/sender/UdpDataSenderFactory.java | 18 +- .../sender/UdpSocketAddressProvider.java | 2 +- .../sender/WriteFailFutureListener.java | 3 +- .../CommandGrpcToThriftMessageConverter.java | 353 +++++----- .../ThreadDumpThriftMessageConverter.java | 3 +- .../ThreadStateThriftMessageConverter.java | 3 +- .../thrift}/sender/RefreshStrategyTest.java | 2 +- .../thrift}/sender/RetryMessageTest.java | 2 +- .../thrift}/sender/RetryQueueTest.java | 2 +- .../sender/TcpDataSenderReconnectTest.java | 4 +- .../thrift}/sender/TcpDataSenderTest.java | 2 +- .../thrift}/sender/UdpDataSenderTest.java | 31 +- .../thrift}/sender/UdpSocketTest.java | 2 +- .../src/test/resources/log4j2-test.xml | 23 + profiler/pom.xml | 43 +- .../pinpoint/profiler/AgentInfoSender.java | 14 +- .../pinpoint/profiler/DefaultAgent.java | 14 +- .../context/TraceDataFormatVersion.java | 1 + .../context/annotation/BooleanAnnotation.java | 10 +- .../context/annotation/ByteAnnotation.java | 10 +- .../context/annotation/BytesAnnotation.java | 10 +- .../annotation/DataTypeAnnotation.java | 61 +- .../context/annotation/DoubleAnnotation.java | 9 +- .../context/annotation/IntAnnotation.java | 9 +- .../context/annotation/LongAnnotation.java | 9 +- .../context/annotation/NullAnnotation.java | 9 +- .../context/annotation/ObjectAnnotation.java | 9 +- .../context/annotation/ShortAnnotation.java | 9 +- .../context/annotation/StringAnnotation.java | 10 +- .../context/compress/SpanProcessorV1.java | 110 --- .../grpc/GrpcAgentInfoMessageConverter.java | 2 +- .../GrpcCustomMetricMessageConverter.java | 2 +- .../grpc/GrpcJvmGcTypeMessageConverter.java | 2 +- .../grpc/GrpcMessageToResultConverter.java | 6 +- .../GrpcMessageToResultConverterProvider.java | 4 +- .../grpc/GrpcMetadataMessageConverter.java | 2 +- .../GrpcMetadataMessageConverterProvider.java | 2 +- .../grpc/GrpcSpanMessageConverter.java | 2 +- .../GrpcSpanMessageConverterProvider.java | 2 +- .../grpc/GrpcStatMessageConverter.java | 5 +- .../GrpcStatMessageConverterProvider.java | 2 +- .../grpc/GrpcThreadDumpMessageConverter.java | 2 +- .../grpc/GrpcThreadStateMessageConverter.java | 2 +- .../grpc/GrpcUriStatMessageConverter.java | 2 +- .../context/grpc/MessageConverterGroup.java | 2 +- .../ApplicationContextModuleFactory.java | 10 +- .../module/DefaultApplicationContext.java | 4 +- .../profiler/context/module/GrpcModule.java | 15 +- .../context/module/GrpcModuleLifeCycle.java | 17 +- .../profiler/context/module/ThriftModule.java | 176 ----- .../context/module/ThriftModuleLifeCycle.java | 183 ----- .../context/module/ThriftStatsModule.java | 45 +- .../provider/AgentInfoSenderProvider.java | 13 +- .../provider/CommandDispatcherProvider.java | 58 -- .../provider/StorageFactoryProvider.java | 4 +- .../TraceDataFormatVersionProvider.java | 11 +- .../grpc/AgentGrpcDataSenderProvider.java | 11 +- .../grpc/MetadataGrpcDataSenderProvider.java | 9 +- .../grpc/SpanGrpcDataSenderProvider.java | 4 +- .../grpc/StatGrpcDataSenderProvider.java | 4 +- .../metadata/ApiMetaDataServiceProvider.java | 11 +- .../metadata/SimpleCacheFactoryProvider.java | 7 +- .../metadata/SqlMetadataServiceProvider.java | 9 +- .../StringMetadataServiceProvider.java | 9 +- .../thrift/AbstractClientFactoryProvider.java | 47 -- .../ConnectionFactoryProviderProvider.java | 39 -- .../thrift/HeaderTBaseSerializerProvider.java | 40 -- .../MetadataMessageConverterProvider.java | 53 -- .../thrift/PinpointClientFactoryProvider.java | 103 --- .../thrift/SpanClientFactoryProvider.java | 70 -- .../thrift/SpanDataSenderProvider.java | 105 --- .../thrift/SpanProcessorProvider.java | 49 -- .../SpanStatChannelFactoryProvider.java | 64 -- .../thrift/SpanStatConnectTimerProvider.java | 56 -- .../thrift/StatClientFactoryProvider.java | 70 -- .../thrift/StatDataSenderProvider.java | 107 --- .../thrift/TcpDataSenderProvider.java | 66 -- .../storage/AsyncQueueingUriStatStorage.java | 30 +- .../context/storage/BufferedStorage.java | 13 +- .../storage/BufferedStorageFactory.java | 5 +- .../thrift/AnnotationValueThriftMapper.java | 38 - .../thrift/DefaultTransactionIdEncoder.java | 140 ---- .../JvmGcTypeThriftMessageConverter.java | 52 -- .../thrift/MetadataMessageConverter.java | 148 ---- .../thrift/SpanThriftMessageConverter.java | 276 -------- .../SpanThriftMessageConverterProvider.java | 64 -- .../thrift/StatThriftMessageConverter.java | 296 -------- .../StatThriftMessageConverterProvider.java | 37 - .../thrift/ThriftAnnotationSerializable.java | 28 - .../ThriftMessageToResultConverter.java | 61 -- ...hriftMessageToResultConverterProvider.java | 35 - .../config/DefaultThriftTransportConfig.java | 342 --------- .../thrift/config/ThriftTransportConfig.java | 96 --- .../metadata/DefaultApiMetaDataService.java | 11 +- .../metadata/DefaultSqlMetaDataService.java | 13 +- .../DefaultStringMetaDataService.java | 11 +- .../pinpoint/profiler/monitor/CollectJob.java | 4 +- .../monitor/CustomMetricCollectingJob.java | 8 +- .../monitor/DefaultAgentStatMonitor.java | 6 +- .../monitor/UriStatCollectingJob.java | 5 +- .../profiler/receiver/CommandDispatcher.java | 154 ----- .../DefaultProfilerCommandServiceLocator.java | 33 - .../ProfilerCommandServiceLocator.java | 6 - .../ProfilerRequestCommandService.java | 26 - .../ProfilerSimpleCommandService.java | 26 - .../ProfilerStreamCommandService.java | 26 - .../GrpcActiveThreadLightDumpService.java | 7 +- .../receiver/grpc/GrpcCommandDispatcher.java | 11 +- .../receiver/grpc/GrpcCommandService.java | 10 +- .../service/ActiveThreadCountService.java | 187 ----- .../service/ActiveThreadDumpService.java | 112 --- .../service/ActiveThreadLightDumpService.java | 121 ---- .../receiver/service/ActiveThreadService.java | 62 -- .../receiver/service/EchoService.java | 46 -- .../receiver/service/ThreadDumpRequest.java | 28 +- .../receiver/service/ThreadDumpService.java | 188 ----- .../profiler/sender/EnhancedDataSender.java | 36 - .../sender/ThriftUdpMessageSerializer.java | 95 --- .../profiler/sender/UdpDataSenderType.java | 28 - .../sender/grpc/AgentGrpcDataSender.java | 15 +- .../profiler/sender/grpc/GrpcDataSender.java | 12 +- .../sender/grpc/MetadataGrpcDataSender.java | 8 +- .../sender/grpc/PingStreamContext.java | 6 +- .../sender/grpc/SpanGrpcDataSender.java | 2 +- .../sender/grpc/StatGrpcDataSender.java | 2 +- .../profiler/sender/grpc/StreamUtils.java | 12 +- .../profiler/AgentInfoSenderTest.java | 650 ------------------ .../MockApplicationContextFactory.java | 2 +- .../context/MockTraceContextFactory.java | 4 +- .../profiler/context/SpanEventTest.java | 83 --- .../compress/GrpcSpanProcessorV2Test.java | 4 - .../compress/SpanPostProcessorTest.java | 92 --- .../provider/ClientFactoryProviderTest.java | 55 -- .../DefaultTransactionIdEncoderTest.java | 114 --- .../SpanThriftMessageConverterTest.java | 192 ------ .../DefaultThriftTransportConfigTest.java | 76 -- .../DefaultApiMetaDataServiceTest.java | 5 +- .../DefaultSqlMetaDataServiceTest.java | 5 +- .../DefaultStringMetaDataServiceTest.java | 8 +- .../profiler/monitor/CollectJobTest.java | 2 +- .../ProfilerCommandServiceLocatorTest.java | 169 ----- .../service/ActiveThreadDumpServiceTest.java | 243 ------- .../ActiveThreadLightDumpServiceTest.java | 246 ------- .../service/ActiveThreadServiceTest.java | 98 --- .../receiver/service/LimitedListTest.java | 118 ---- .../service/ThreadDumpRequestTest.java | 111 --- .../profiler/receiver/service/WaitingJob.java | 45 -- .../service/WaitingJobListFactory.java | 53 -- .../profiler/sender/CountingDataSender.java | 5 +- .../grpc/AgentGrpcDataSenderTestMain.java | 4 +- .../profiler/util/ThreadDumpUtilsTest.java | 57 -- .../service/ClusterAgentCommandService.java | 2 +- .../pinpoint/rpc/ClassPreLoader.java | 94 --- .../pinpoint/rpc/PinpointSocket.java | 1 + .../rpc/client/DefaultPinpointClient.java | 2 +- .../client/DefaultPinpointClientHandler.java | 2 +- .../rpc/client/PinpointClientHandler.java | 2 +- .../client/ReconnectStateClientHandler.java | 2 +- .../pinpoint/rpc/client/RequestManager.java | 2 +- .../rpc/server/DefaultPinpointServer.java | 2 +- .../pinpoint/rpc/ClassPreLoaderTest.java | 29 - .../rpc/client/PinpointClientFactoryTest.java | 2 +- .../pinpoint/rpc/client/ReconnectTest.java | 2 +- .../rpc/client/RequestManagerTest.java | 2 +- .../rpc/util/PinpointRPCTestUtils.java | 2 +- .../cluster/FailedPinpointRouteResponse.java | 11 +- .../web/service/AgentServiceImpl.java | 10 +- ...entActiveThreadDumpListSerializerTest.java | 2 +- .../AgentActiveThreadDumpListTest.java | 4 +- 241 files changed, 1190 insertions(+), 7889 deletions(-) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/context => collector/src/main/java/com/navercorp/pinpoint/collector/cluster}/grpc/CommandThriftToGrpcMessageConverter.java (94%) delete mode 100644 collector/src/test/java/com/navercorp/pinpoint/collector/cluster/route/GrpcAgentConnectionTest.java create mode 100644 collector/src/test/java/com/navercorp/pinpoint/common/profiler/message/RouteResultTest.java rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/sender => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor}/AsyncQueueingExecutor.java (75%) rename profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyAsyncQueueingExecutorListener.java => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/EmptyConsumer.java (66%) rename profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutorListener.java => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/MultiConsumer.java (78%) rename profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DefaultAsyncQueueingExecutorListener.java => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/SingleConsumer.java (71%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/sender => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor}/UnsafeArrayCollection.java (96%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message}/BypassMessageConverter.java (93%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/sender => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message}/DataSender.java (84%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/sender => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message}/EmptyDataSender.java (74%) create mode 100644 commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EnhancedDataSender.java rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/sender => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message}/LoggingDataSender.java (78%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message}/MessageConverter.java (92%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/sender => commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message}/ResultResponse.java (92%) create mode 100644 commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/RouteResult.java rename {rpc/src/main/java/com/navercorp/pinpoint/rpc => commons-profiler/src/main/java/com/navercorp/pinpoint/io}/DefaultResponseMessage.java (96%) rename {rpc/src/main/java/com/navercorp/pinpoint/rpc => commons-profiler/src/main/java/com/navercorp/pinpoint/io}/ResponseMessage.java (95%) rename {thrift => commons-profiler}/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java (80%) rename {thrift/src/test/java/com/navercorp/pinpoint/thrift/dto => commons-profiler/src/test/java/com/navercorp/pinpoint/io}/SpanVersionTest.java (92%) rename profiler-test/src/main/java/com/navercorp/pinpoint/test/{TBaseRecorder.java => Recorder.java} (96%) rename profiler-test/src/main/java/com/navercorp/pinpoint/test/{TBaseRecorderAdaptor.java => RecorderAdaptor.java} (69%) create mode 100644 profiler-thrift-datasender/pom.xml rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/ByteMessage.java (96%) create mode 100644 profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MaxBytesLengthPredicate.java rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/MessageSerializer.java (93%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/PortUnreachableHandler.java (93%) create mode 100644 profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ReconnectEventListenerRegistry.java rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/RefreshStrategy.java (98%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/RequestMessage.java (76%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/RequestMessageFactory.java (69%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/RetryMessage.java (98%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/RetryQueue.java (98%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/RetryRequestMessage.java (54%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/TcpDataSender.java (90%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/ThriftMessageSerializer.java (60%) create mode 100644 profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftUdpMessageSerializer.java rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/UdpDataSender.java (92%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/UdpDataSenderFactory.java (85%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/UdpSocketAddressProvider.java (94%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift}/sender/WriteFailFutureListener.java (96%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message}/CommandGrpcToThriftMessageConverter.java (97%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message}/ThreadDumpThriftMessageConverter.java (96%) rename {profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift => profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message}/ThreadStateThriftMessageConverter.java (93%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/RefreshStrategyTest.java (98%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/RetryMessageTest.java (98%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/RetryQueueTest.java (98%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/TcpDataSenderReconnectTest.java (96%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/TcpDataSenderTest.java (98%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/UdpDataSenderTest.java (87%) rename {profiler/src/test/java/com/navercorp/pinpoint/profiler => profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift}/sender/UdpSocketTest.java (99%) create mode 100644 profiler-thrift-datasender/src/test/resources/log4j2-test.xml delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/compress/SpanProcessorV1.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModule.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModuleLifeCycle.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/CommandDispatcherProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/AbstractClientFactoryProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/ConnectionFactoryProviderProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/HeaderTBaseSerializerProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/MetadataMessageConverterProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/PinpointClientFactoryProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanClientFactoryProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanDataSenderProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanProcessorProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatChannelFactoryProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatConnectTimerProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatClientFactoryProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatDataSenderProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/TcpDataSenderProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/AnnotationValueThriftMapper.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoder.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/JvmGcTypeThriftMessageConverter.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MetadataMessageConverter.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverter.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverter.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverterProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftAnnotationSerializable.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverter.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverterProvider.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfig.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/ThriftTransportConfig.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EnhancedDataSender.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftUdpMessageSerializer.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderType.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/AgentInfoSenderTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/context/SpanEventTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/SpanPostProcessorTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/context/provider/ClientFactoryProviderTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoderTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfigTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpServiceTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpServiceTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadServiceTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/LimitedListTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequestTest.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJob.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJobListFactory.java delete mode 100644 profiler/src/test/java/com/navercorp/pinpoint/profiler/util/ThreadDumpUtilsTest.java delete mode 100644 rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java delete mode 100644 rpc/src/test/java/com/navercorp/pinpoint/rpc/ClassPreLoaderTest.java diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java index 0430056145cf..fe746937f473 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java @@ -47,7 +47,7 @@ public class DefaultProfilerConfig implements ProfilerConfig { private final Properties properties; - private static final TransportModule DEFAULT_TRANSPORT_MODULE = TransportModule.THRIFT; + private static final TransportModule DEFAULT_TRANSPORT_MODULE = TransportModule.GRPC; @Value("${profiler.enable:true}") private boolean profileEnable = false; diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/TransportModule.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/TransportModule.java index 8b809a768770..df99b45c59c5 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/TransportModule.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/TransportModule.java @@ -22,24 +22,19 @@ * @author Woonduk Kang(emeroad) */ public enum TransportModule { - THRIFT, GRPC; public static TransportModule parse(String transportModule) { Objects.requireNonNull(transportModule, "transportModule"); - if (isEquals(THRIFT, transportModule)) { - return THRIFT; - } - if (isEquals(GRPC, transportModule)) { + if (equalsIgnoreCase(TransportModule.GRPC.name(), transportModule)) { return GRPC; } - return null; + return GRPC; } - private static boolean isEquals(TransportModule transportModule, String transportModuleString) { - final String transportModuleName = transportModule.name(); - return transportModuleName.equalsIgnoreCase(transportModuleString); + private static boolean equalsIgnoreCase(String str1, String str2) { + return str1.equalsIgnoreCase(str2); } public static TransportModule parse(String transportModule, TransportModule defaultModule) { diff --git a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/TransportModuleTest.java b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/TransportModuleTest.java index 5458928e50d7..a304166ebd24 100644 --- a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/TransportModuleTest.java +++ b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/TransportModuleTest.java @@ -27,9 +27,8 @@ public class TransportModuleTest { @Test public void parse() { Assertions.assertEquals(TransportModule.parse("GRPC"), TransportModule.GRPC); - Assertions.assertEquals(TransportModule.parse("THRIFT"), TransportModule.THRIFT); - Assertions.assertNull(TransportModule.parse("ERROR")); + Assertions.assertEquals(TransportModule.parse("ERROR"), TransportModule.GRPC); } @Test diff --git a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java index a955d16f3f90..5cb4dca45949 100644 --- a/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java +++ b/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/ModuleSupport.java @@ -81,7 +81,6 @@ private void addPermissionToValueAnnotation(JavaModule agentModule) { agentModule.addOpens("com.navercorp.pinpoint.profiler.plugin.config", bootstrapModule); agentModule.addOpens("com.navercorp.pinpoint.profiler.context.monitor.config", bootstrapModule); - agentModule.addOpens("com.navercorp.pinpoint.profiler.context.thrift.config", bootstrapModule); agentModule.addOpens("com.navercorp.pinpoint.profiler.context.grpc.config", bootstrapModule); agentModule.addOpens("com.navercorp.pinpoint.grpc.client.config", bootstrapModule); } diff --git a/collector/pom.xml b/collector/pom.xml index 77ee9191a8e2..1a07458bd33f 100644 --- a/collector/pom.xml +++ b/collector/pom.xml @@ -70,6 +70,10 @@ com.navercorp.pinpoint pinpoint-thrift + + com.navercorp.pinpoint + thrift-datasender + com.navercorp.pinpoint pinpoint-grpc diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java index 2cb501b649fb..795155e65444 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java @@ -17,7 +17,7 @@ package com.navercorp.pinpoint.collector.cluster; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import org.apache.thrift.TBase; import java.util.concurrent.CompletableFuture; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java index 7df962822230..d2803a0e9cf0 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java @@ -20,9 +20,8 @@ import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.rpc.common.SocketStateCode; import com.navercorp.pinpoint.rpc.server.PinpointServer; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.HashMap; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java index cd5a1294d626..06ab2177ab11 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java @@ -17,11 +17,11 @@ package com.navercorp.pinpoint.collector.cluster; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.collector.cluster.grpc.CommandThriftToGrpcMessageConverter; import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; -import com.navercorp.pinpoint.profiler.context.grpc.CommandThriftToGrpcMessageConverter; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannel; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannelEventHandler; @@ -117,4 +117,4 @@ public String toString() { return String.format("GrpcAgentConnection {clusterKey: %s}", pinpointGrpcServer.getClusterKey()); } -} +} \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java index f92f361c167f..156b70d05f71 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java @@ -17,7 +17,7 @@ package com.navercorp.pinpoint.collector.cluster; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.server.ChannelProperties; import com.navercorp.pinpoint.rpc.server.PinpointServer; import com.navercorp.pinpoint.thrift.io.TCommandType; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/FlinkClusterConnectionManager.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/FlinkClusterConnectionManager.java index 272b9403697e..7ff9bee17d6e 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/FlinkClusterConnectionManager.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/FlinkClusterConnectionManager.java @@ -19,11 +19,11 @@ import com.navercorp.pinpoint.collector.sender.FlinkRequestFactory; import com.navercorp.pinpoint.collector.sender.FlinkTcpDataSender; import com.navercorp.pinpoint.collector.util.Address; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; import com.navercorp.pinpoint.thrift.io.SerializerFactory; +import com.navercorp.pinpoint.thrift.sender.TcpDataSender; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TBase; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/SenderContext.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/SenderContext.java index cf975ae14539..ff80fc12e790 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/SenderContext.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/SenderContext.java @@ -15,7 +15,7 @@ */ package com.navercorp.pinpoint.collector.cluster.flink; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; +import com.navercorp.pinpoint.thrift.sender.TcpDataSender; import org.apache.thrift.TBase; import java.util.Objects; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/TcpDataSenderRepository.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/TcpDataSenderRepository.java index 859915eb4125..bbac3e163936 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/TcpDataSenderRepository.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/flink/TcpDataSenderRepository.java @@ -17,7 +17,7 @@ import com.navercorp.pinpoint.collector.service.SendDataToFlinkService; import com.navercorp.pinpoint.collector.util.Address; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; +import com.navercorp.pinpoint.thrift.sender.TcpDataSender; import org.apache.thrift.TBase; import java.util.ArrayList; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/CommandThriftToGrpcMessageConverter.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/grpc/CommandThriftToGrpcMessageConverter.java similarity index 94% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/CommandThriftToGrpcMessageConverter.java rename to collector/src/main/java/com/navercorp/pinpoint/collector/cluster/grpc/CommandThriftToGrpcMessageConverter.java index 25031c4e9431..a766ec11e3bf 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/CommandThriftToGrpcMessageConverter.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/grpc/CommandThriftToGrpcMessageConverter.java @@ -1,87 +1,86 @@ -/* - * Copyright 2019 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.profiler.context.grpc; - -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadCount; -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDump; -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDump; -import com.navercorp.pinpoint.grpc.trace.PCmdEcho; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCount; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; - -import com.google.protobuf.GeneratedMessageV3; - -/** - * @author Taejin Koo - */ -public class CommandThriftToGrpcMessageConverter implements MessageConverter { - - @Override - public GeneratedMessageV3 toMessage(Object message) { - if (message instanceof TCommandEcho) { - return buildPCommandEcho((TCommandEcho) message); - } else if (message instanceof TCmdActiveThreadCount) { - return buildPCmdActiveThreadCount((TCmdActiveThreadCount) message); - } else if (message instanceof TCmdActiveThreadDump) { - return buildPCmdActiveThreadDump((TCmdActiveThreadDump) message); - } else if (message instanceof TCmdActiveThreadLightDump) { - return buildPCmdActiveThreadLightDump((TCmdActiveThreadLightDump) message); - } - return null; - } - - private PCmdEcho buildPCommandEcho(TCommandEcho tCommandEcho) { - PCmdEcho.Builder builder = PCmdEcho.newBuilder(); - builder.setMessage(tCommandEcho.getMessage()); - return builder.build(); - } - - private PCmdActiveThreadCount buildPCmdActiveThreadCount(TCmdActiveThreadCount tCmdActiveThreadCount) { - PCmdActiveThreadCount.Builder builder = PCmdActiveThreadCount.newBuilder(); - return builder.build(); - } - - private PCmdActiveThreadDump buildPCmdActiveThreadDump(TCmdActiveThreadDump tCmdActiveThreadDump) { - PCmdActiveThreadDump.Builder builder = PCmdActiveThreadDump.newBuilder(); - builder.setLimit(tCmdActiveThreadDump.getLimit()); - if (tCmdActiveThreadDump.isSetLocalTraceIdList()) { - builder.addAllLocalTraceId(tCmdActiveThreadDump.getLocalTraceIdList()); - } - if (tCmdActiveThreadDump.isSetThreadNameList()) { - builder.addAllThreadName(tCmdActiveThreadDump.getThreadNameList()); - } - - return builder.build(); - } - - private PCmdActiveThreadLightDump buildPCmdActiveThreadLightDump(TCmdActiveThreadLightDump tCmdActiveThreadLightDump) { - PCmdActiveThreadLightDump.Builder builder = PCmdActiveThreadLightDump.newBuilder(); - builder.setLimit(tCmdActiveThreadLightDump.getLimit()); - if (tCmdActiveThreadLightDump.isSetLocalTraceIdList()) { - builder.addAllLocalTraceId(tCmdActiveThreadLightDump.getLocalTraceIdList()); - } - if (tCmdActiveThreadLightDump.isSetThreadNameList()) { - builder.addAllThreadName(tCmdActiveThreadLightDump.getThreadNameList()); - } - - return builder.build(); - } - -} +/* + * Copyright 2019 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.cluster.grpc; + +import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadCount; +import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDump; +import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDump; +import com.navercorp.pinpoint.grpc.trace.PCmdEcho; +import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCount; +import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDump; +import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDump; +import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; + +/** + * @author Taejin Koo + */ +public class CommandThriftToGrpcMessageConverter implements MessageConverter { + + @Override + public GeneratedMessageV3 toMessage(Object message) { + if (message instanceof TCommandEcho) { + return buildPCommandEcho((TCommandEcho) message); + } else if (message instanceof TCmdActiveThreadCount) { + return buildPCmdActiveThreadCount((TCmdActiveThreadCount) message); + } else if (message instanceof TCmdActiveThreadDump) { + return buildPCmdActiveThreadDump((TCmdActiveThreadDump) message); + } else if (message instanceof TCmdActiveThreadLightDump) { + return buildPCmdActiveThreadLightDump((TCmdActiveThreadLightDump) message); + } + return null; + } + + private PCmdEcho buildPCommandEcho(TCommandEcho tCommandEcho) { + PCmdEcho.Builder builder = PCmdEcho.newBuilder(); + builder.setMessage(tCommandEcho.getMessage()); + return builder.build(); + } + + private PCmdActiveThreadCount buildPCmdActiveThreadCount(TCmdActiveThreadCount tCmdActiveThreadCount) { + PCmdActiveThreadCount.Builder builder = PCmdActiveThreadCount.newBuilder(); + return builder.build(); + } + + private PCmdActiveThreadDump buildPCmdActiveThreadDump(TCmdActiveThreadDump tCmdActiveThreadDump) { + PCmdActiveThreadDump.Builder builder = PCmdActiveThreadDump.newBuilder(); + builder.setLimit(tCmdActiveThreadDump.getLimit()); + if (tCmdActiveThreadDump.isSetLocalTraceIdList()) { + builder.addAllLocalTraceId(tCmdActiveThreadDump.getLocalTraceIdList()); + } + if (tCmdActiveThreadDump.isSetThreadNameList()) { + builder.addAllThreadName(tCmdActiveThreadDump.getThreadNameList()); + } + + return builder.build(); + } + + private PCmdActiveThreadLightDump buildPCmdActiveThreadLightDump(TCmdActiveThreadLightDump tCmdActiveThreadLightDump) { + PCmdActiveThreadLightDump.Builder builder = PCmdActiveThreadLightDump.newBuilder(); + builder.setLimit(tCmdActiveThreadLightDump.getLimit()); + if (tCmdActiveThreadLightDump.isSetLocalTraceIdList()) { + builder.addAllLocalTraceId(tCmdActiveThreadLightDump.getLocalTraceIdList()); + } + if (tCmdActiveThreadLightDump.isSetThreadNameList()) { + builder.addAllThreadName(tCmdActiveThreadLightDump.getThreadNameList()); + } + + return builder.build(); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/DefaultRouteHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/DefaultRouteHandler.java index 413e656f52c5..9028f97e8c3d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/DefaultRouteHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/DefaultRouteHandler.java @@ -21,7 +21,7 @@ import com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection; import com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection; import com.navercorp.pinpoint.collector.cluster.route.filter.RouteFilter; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse; import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; import org.apache.commons.lang3.ArrayUtils; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/StreamRouteHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/StreamRouteHandler.java index e3726c4b93c8..c830a1b7899c 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/StreamRouteHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/StreamRouteHandler.java @@ -35,10 +35,9 @@ import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; import com.navercorp.pinpoint.thrift.io.SerializerFactory; import com.navercorp.pinpoint.thrift.util.SerializationUtils; - -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.thrift.TBase; import org.springframework.beans.factory.annotation.Qualifier; import java.util.Objects; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java b/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java index 30d7d596c1aa..bb17dce98f92 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java @@ -25,9 +25,9 @@ import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.common.util.StringUtils; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.common.SocketStateCode; import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseDeserializerFactory; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java index 4b44458063eb..0e9bf70bd3f3 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java @@ -28,9 +28,8 @@ import com.navercorp.pinpoint.grpc.trace.PCmdEcho; import com.navercorp.pinpoint.grpc.trace.PCmdRequest; import com.navercorp.pinpoint.grpc.trace.PCmdResponse; -import com.navercorp.pinpoint.profiler.context.thrift.CommandGrpcToThriftMessageConverter; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.client.RequestManager; import com.navercorp.pinpoint.rpc.common.SocketState; import com.navercorp.pinpoint.rpc.common.SocketStateChangeResult; @@ -45,6 +44,7 @@ import com.navercorp.pinpoint.rpc.stream.StreamException; import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseSerializerFactory; +import com.navercorp.pinpoint.thrift.sender.message.CommandGrpcToThriftMessageConverter; import com.navercorp.pinpoint.thrift.util.SerializationUtils; import io.grpc.Status; import io.grpc.StatusException; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/sender/FlinkTcpDataSender.java b/collector/src/main/java/com/navercorp/pinpoint/collector/sender/FlinkTcpDataSender.java index 58f4b11f6a23..9dc42733a3b9 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/sender/FlinkTcpDataSender.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/sender/FlinkTcpDataSender.java @@ -16,12 +16,12 @@ package com.navercorp.pinpoint.collector.sender; import com.navercorp.pinpoint.io.request.FlinkRequest; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; import com.navercorp.pinpoint.thrift.io.TBaseSerializer; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; +import com.navercorp.pinpoint.thrift.sender.TcpDataSender; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.thrift.TBase; import org.springframework.util.Assert; import java.util.HashMap; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/SendDataToFlinkService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/SendDataToFlinkService.java index fb8c641dfa4e..9b9ef1b69588 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/SendDataToFlinkService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/SendDataToFlinkService.java @@ -15,10 +15,10 @@ */ package com.navercorp.pinpoint.collector.service; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; +import com.navercorp.pinpoint.thrift.sender.TcpDataSender; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.thrift.TBase; import java.util.ArrayList; import java.util.List; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/cluster/route/GrpcAgentConnectionTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/cluster/route/GrpcAgentConnectionTest.java deleted file mode 100644 index 911dae72fd10..000000000000 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/cluster/route/GrpcAgentConnectionTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2019 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.cluster.route; - -import com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection; -import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer; -import com.navercorp.pinpoint.rpc.ResponseMessage; -import com.navercorp.pinpoint.thrift.dto.TResult; -import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; -import org.mockito.Mockito; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -/** - * @author Taejin Koo - */ -public class GrpcAgentConnectionTest { - - @Test - public void requestTest() { - PinpointGrpcServer mockGrpcServer = Mockito.mock(PinpointGrpcServer.class); - - List supportCommandList = List.of(Short.toUnsignedInt(TCommandType.ECHO.getCode())); - GrpcAgentConnection grpcAgentConnection = new GrpcAgentConnection(mockGrpcServer, supportCommandList); - - boolean supportCommand = grpcAgentConnection.isSupportCommand(TCommandType.TRANSFER.getBodyFactory().getObject()); - Assertions.assertFalse(supportCommand); - - supportCommand = grpcAgentConnection.isSupportCommand(TCommandType.RESULT.getBodyFactory().getObject()); - Assertions.assertFalse(supportCommand); - - supportCommand = grpcAgentConnection.isSupportCommand(TCommandType.ECHO.getBodyFactory().getObject()); - Assertions.assertTrue(supportCommand); - - final CompletableFuture future = grpcAgentConnection.request(new TResult()); - - Assertions.assertThrows(Exception.class, new Executable() { - @Override - public void execute() throws Throwable { - future.get(3000, TimeUnit.MILLISECONDS); - } - }); - TCommandEcho commandEcho = new TCommandEcho("hello"); - // check to pass validation - final CompletableFuture future2 = grpcAgentConnection.request(commandEcho); - Assertions.assertNull(future2); - } - - @Test - public void equalsTest() { - PinpointGrpcServer mockGrpcServer1 = Mockito.mock(PinpointGrpcServer.class); - - List supportCommandList = List.of(Short.toUnsignedInt(TCommandType.ECHO.getCode())); - GrpcAgentConnection grpcAgentConnection = new GrpcAgentConnection(mockGrpcServer1, supportCommandList); - - Assertions.assertEquals(grpcAgentConnection, new GrpcAgentConnection(mockGrpcServer1, supportCommandList)); - - PinpointGrpcServer mockGrpcServer2 = Mockito.mock(PinpointGrpcServer.class); - Assertions.assertNotEquals(grpcAgentConnection, new GrpcAgentConnection(mockGrpcServer2, supportCommandList)); - } - -} diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DataReceiverGroupTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DataReceiverGroupTest.java index fe161b6f2410..155119d1513b 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DataReceiverGroupTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DataReceiverGroupTest.java @@ -21,23 +21,23 @@ import com.navercorp.pinpoint.collector.receiver.thrift.TCPReceiverBean; import com.navercorp.pinpoint.collector.receiver.thrift.UDPReceiverBean; import com.navercorp.pinpoint.collector.thrift.config.DataReceiverGroupProperties; +import com.navercorp.pinpoint.common.profiler.message.BypassMessageConverter; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.server.util.AddressFilter; import com.navercorp.pinpoint.io.request.ServerRequest; import com.navercorp.pinpoint.io.request.ServerResponse; -import com.navercorp.pinpoint.profiler.context.thrift.BypassMessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.sender.ByteMessage; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.MessageSerializer; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; -import com.navercorp.pinpoint.profiler.sender.ThriftUdpMessageSerializer; -import com.navercorp.pinpoint.profiler.sender.UdpDataSender; import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; import com.navercorp.pinpoint.thrift.dto.TResult; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; import com.navercorp.pinpoint.thrift.io.SerializerFactory; +import com.navercorp.pinpoint.thrift.sender.ByteMessage; +import com.navercorp.pinpoint.thrift.sender.MessageSerializer; +import com.navercorp.pinpoint.thrift.sender.TcpDataSender; +import com.navercorp.pinpoint.thrift.sender.ThriftUdpMessageSerializer; +import com.navercorp.pinpoint.thrift.sender.UdpDataSender; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TBase; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java index 74512e7c9e1d..649b7bd1cd82 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java @@ -23,7 +23,7 @@ import com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse; import com.navercorp.pinpoint.grpc.trace.PCmdRequest; import com.navercorp.pinpoint.grpc.trace.PCmdResponse; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.client.RequestManager; import com.navercorp.pinpoint.rpc.common.SocketStateCode; import com.navercorp.pinpoint.rpc.util.TimerFactory; diff --git a/collector/src/test/java/com/navercorp/pinpoint/common/profiler/message/RouteResultTest.java b/collector/src/test/java/com/navercorp/pinpoint/common/profiler/message/RouteResultTest.java new file mode 100644 index 000000000000..18bbf452cf54 --- /dev/null +++ b/collector/src/test/java/com/navercorp/pinpoint/common/profiler/message/RouteResultTest.java @@ -0,0 +1,26 @@ +package com.navercorp.pinpoint.common.profiler.message; + +import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class RouteResultTest { + + @Test + public void compatibility() { + Assertions.assertThat(RouteResult.values()) + .hasSize(TRouteResult.values().length); + + List thriftCodes = Stream.of(TRouteResult.values()) + .map(TRouteResult::getValue) + .collect(Collectors.toList()); + + Assertions.assertThat(RouteResult.values()) + .extracting(RouteResult::code) + .containsAll(thriftCodes); + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutor.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/AsyncQueueingExecutor.java similarity index 75% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutor.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/AsyncQueueingExecutor.java index 38e90acb84f9..7e5acc06c78e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutor.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/AsyncQueueingExecutor.java @@ -14,26 +14,26 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.concurrent.executor; -import java.util.Objects; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collection; +import java.util.Objects; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; /** * @author emeroad */ -public class AsyncQueueingExecutor implements Runnable { +public class AsyncQueueingExecutor { private final Logger logger; - private final boolean isWarn; private final LinkedBlockingQueue queue; private final AtomicBoolean isRun = new AtomicBoolean(true); @@ -44,40 +44,36 @@ public class AsyncQueueingExecutor implements Runnable { // Caution. single thread only. this Collection is simpler than ArrayList. private final Collection drain; - private final AsyncQueueingExecutorListener listener; + private final MultiConsumer consumer; + public AsyncQueueingExecutor(int queueSize, String executorName, Consumer consumer) { + this(queueSize, executorName, new SingleConsumer<>(consumer)); + } - public AsyncQueueingExecutor(int queueSize, String executorName, AsyncQueueingExecutorListener listener) { + public AsyncQueueingExecutor(int queueSize, String executorName, MultiConsumer consumer) { Objects.requireNonNull(executorName, "executorName"); this.logger = LogManager.getLogger(this.getClass().getName() + "@" + executorName); - this.isWarn = logger.isWarnEnabled(); // BEFORE executeThread start this.maxDrainSize = 10; - this.drain = new UnsafeArrayCollection(maxDrainSize); - this.queue = new LinkedBlockingQueue(queueSize); + this.drain = new UnsafeArrayCollection<>(maxDrainSize); + this.queue = new LinkedBlockingQueue<>(queueSize); this.executeThread = this.createExecuteThread(executorName); this.executorName = executeThread.getName(); - this.listener = Objects.requireNonNull(listener, "listener"); + this.consumer = Objects.requireNonNull(consumer, "consumer"); } private Thread createExecuteThread(String executorName) { final ThreadFactory threadFactory = new PinpointThreadFactory(executorName, true); - Thread thread = threadFactory.newThread(this); + Thread thread = threadFactory.newThread(this::doAccept); thread.start(); return thread; } - @Override - public void run() { - logger.info("{} started.", executorName); - doExecute(); - } - - private void doExecute() { + private void doAccept() { long timeout = 2000; drainStartEntry: while (isRun()) { @@ -85,14 +81,14 @@ private void doExecute() { final Collection dtoList = getDrainQueue(); final int drainSize = takeN(dtoList, this.maxDrainSize); if (drainSize > 0) { - doExecute(dtoList); + doAccept(dtoList); continue; } while (isRun()) { final T dto = takeOne(timeout); if (dto != null) { - doExecute(dto); + doAccept(dto); continue drainStartEntry; } else { pollTimeout(timeout); @@ -110,16 +106,16 @@ private void flushQueue() { if (debugEnabled) { logger.debug("Loop is stop."); } - while(true) { - final Collection dtoList = getDrainQueue(); - int drainSize = takeN(dtoList, this.maxDrainSize); + while (true) { + final Collection elementList = getDrainQueue(); + int drainSize = takeN(elementList, this.maxDrainSize); if (drainSize == 0) { break; } if (debugEnabled) { logger.debug("flushData size {}", drainSize); } - doExecute(dtoList); + doAccept(elementList); } } @@ -142,33 +138,31 @@ protected void pollTimeout(long timeout) { public boolean execute(T data) { if (data == null) { - if (isWarn) { - logger.warn("execute(). data is null"); - } + logger.warn("execute(). data is null"); return false; } if (!isRun.get()) { - if (isWarn) { - logger.warn("{} is shutdown. discard data:{}", executorName, data); - } + logger.warn("{} is shutdown. discard data:{}", executorName, data); return false; } boolean offer = queue.offer(data); if (!offer) { - if (isWarn) { - logger.warn("{} Drop data. queue is full. size:{}", executorName, queue.size()); - } + logger.warn("{} Drop data. queue is full. size:{}", executorName, queue.size()); } return offer; } - private void doExecute(Collection dtoList) { - this.listener.execute(dtoList); + private void doAccept(Collection elements) { + try { + this.consumer.acceptN(elements); + } finally { + elements.clear(); + } } - private void doExecute(T dto) { - this.listener.execute(dto); + private void doAccept(T element) { + this.consumer.accept(element); } public boolean isEmpty() { @@ -197,7 +191,6 @@ public void stop() { } Collection getDrainQueue() { - this.drain.clear(); return drain; } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyAsyncQueueingExecutorListener.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/EmptyConsumer.java similarity index 66% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyAsyncQueueingExecutorListener.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/EmptyConsumer.java index d0ab79601940..94628996654b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyAsyncQueueingExecutorListener.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/EmptyConsumer.java @@ -14,33 +14,27 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.concurrent.executor; -import java.util.Collection; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Collection; /** * @author emeroad */ -public class EmptyAsyncQueueingExecutorListener implements AsyncQueueingExecutorListener { +public class EmptyConsumer implements MultiConsumer { private final Logger logger = LogManager.getLogger(this.getClass()); - private final boolean isDebug = logger.isDebugEnabled(); - @Override - public void execute(Collection dtoList) { - if (isDebug) { - logger.debug("execute()"); - } + public void acceptN(Collection dtoList) { + logger.debug("execute(N)"); } @Override - public void execute(T dto) { - if (isDebug) { - logger.debug("execute()"); - } + public void accept(T dto) { + logger.debug("execute()"); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutorListener.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/MultiConsumer.java similarity index 78% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutorListener.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/MultiConsumer.java index 34bf4e351e94..579178888228 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/AsyncQueueingExecutorListener.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/MultiConsumer.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.concurrent.executor; import java.util.Collection; /** * @author emeroad */ -public interface AsyncQueueingExecutorListener { +public interface MultiConsumer { - void execute(Collection messageList); + void acceptN(Collection messageList); - void execute(T message); - -} + void accept(T message); + +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DefaultAsyncQueueingExecutorListener.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/SingleConsumer.java similarity index 71% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DefaultAsyncQueueingExecutorListener.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/SingleConsumer.java index d2597f3ff921..53085759ad6c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DefaultAsyncQueueingExecutorListener.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/SingleConsumer.java @@ -14,22 +14,30 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.concurrent.executor; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collection; +import java.util.Objects; +import java.util.function.Consumer; /** * @author Woonduk Kang(emeroad) */ -public abstract class DefaultAsyncQueueingExecutorListener implements AsyncQueueingExecutorListener { +public class SingleConsumer implements MultiConsumer { private final Logger logger = LogManager.getLogger(this.getClass()); + private final Consumer consumer; + + public SingleConsumer(Consumer consumer) { + this.consumer = Objects.requireNonNull(consumer, "consumer"); + } + @Override - public void execute(Collection messageList) { + public void acceptN(Collection messageList) { // Cannot use toArray(T[] array) because passed messageList doesn't implement it properly. Object[] dataList = messageList.toArray(); @@ -39,14 +47,15 @@ public void execute(Collection messageList) { final int size = messageList.size(); for (int i = 0; i < size; i++) { try { - execute((T) dataList[i]); + this.accept((T) dataList[i]); } catch (Throwable th) { logger.warn("Unexpected Error. Cause:{}", th.getMessage(), th); } } } - - public abstract void execute(T message); + public void accept(T message) { + this.consumer.accept(message); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UnsafeArrayCollection.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/UnsafeArrayCollection.java similarity index 96% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UnsafeArrayCollection.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/UnsafeArrayCollection.java index 1cb5fbf62ba3..c480c1ad73df 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UnsafeArrayCollection.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/executor/UnsafeArrayCollection.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.concurrent.executor; import java.util.AbstractCollection; import java.util.Iterator; @@ -31,7 +31,6 @@ public UnsafeArrayCollection(int maxSize) { this.array = new Object[maxSize]; } - @Override public boolean add(E o) { if (array.length < size) { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/BypassMessageConverter.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/BypassMessageConverter.java similarity index 93% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/BypassMessageConverter.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/BypassMessageConverter.java index 2b5a5b09deca..6efcb63a8ec5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/BypassMessageConverter.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/BypassMessageConverter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.context.thrift; +package com.navercorp.pinpoint.common.profiler.message; /** * @author Woonduk Kang(emeroad) diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DataSender.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/DataSender.java similarity index 84% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DataSender.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/DataSender.java index 2cefd7747d59..8f2bcf5d12d5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/DataSender.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/DataSender.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.message; /** * @author emeroad * @author netspider */ -public interface DataSender { +public interface DataSender { - boolean send(T data); + boolean send(REQ data); void stop(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyDataSender.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EmptyDataSender.java similarity index 74% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyDataSender.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EmptyDataSender.java index 46d74feb7c55..89c9d4dff426 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EmptyDataSender.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EmptyDataSender.java @@ -14,9 +14,8 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.message; -import com.navercorp.pinpoint.rpc.ResponseMessage; import java.util.function.BiConsumer; @@ -24,7 +23,7 @@ /** * @author Woonduk Kang(emeroad) */ -public class EmptyDataSender implements EnhancedDataSender { +public class EmptyDataSender implements EnhancedDataSender { private static final DataSender INSTANCE = new EmptyDataSender<>(); @@ -34,7 +33,7 @@ public static DataSender instance() { } @Override - public boolean send(T data) { + public boolean send(REQ data) { return true; } @@ -44,18 +43,18 @@ public void stop() { } @Override - public boolean request(T data) { + public boolean request(REQ data) { return true; } @Override - public boolean request(T data, int retry) { + public boolean request(REQ data, int retry) { return false; } @Override - public boolean request(T data, BiConsumer listener) { + public boolean request(REQ data, BiConsumer listener) { return false; } diff --git a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EnhancedDataSender.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EnhancedDataSender.java new file mode 100644 index 000000000000..3120e2e4abf8 --- /dev/null +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/EnhancedDataSender.java @@ -0,0 +1,16 @@ +package com.navercorp.pinpoint.common.profiler.message; + +import java.util.function.BiConsumer; + +/** + * @author emeroad + */ +public interface EnhancedDataSender extends DataSender { + + boolean request(REQ data); + + boolean request(REQ data, int retry); + + boolean request(REQ data, BiConsumer listener); + +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/LoggingDataSender.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/LoggingDataSender.java similarity index 78% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/LoggingDataSender.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/LoggingDataSender.java index ae8e03db52b0..d493397e0863 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/LoggingDataSender.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/LoggingDataSender.java @@ -14,9 +14,8 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.message; -import com.navercorp.pinpoint.rpc.ResponseMessage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -27,12 +26,12 @@ * @author emeroad * @author netspider */ -public class LoggingDataSender implements EnhancedDataSender { +public class LoggingDataSender implements EnhancedDataSender { private final Logger logger = LogManager.getLogger(this.getClass()); @Override - public boolean send(T data) { + public boolean send(REQ data) { logger.info("send tBase:{}", data); return true; } @@ -44,22 +43,22 @@ public void stop() { } @Override - public boolean request(T data) { + public boolean request(REQ data) { logger.info("request tBase:{}", data); return true; } @Override - public boolean request(T data, int retry) { + public boolean request(REQ data, int retry) { logger.info("request tBase:{} retry:{}", data, retry); return false; } @Override - public boolean request(T data, BiConsumer listener) { + public boolean request(REQ data, BiConsumer listener) { logger.info("request tBase:{} FutureListener:{}", data, listener); return false; } -} +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MessageConverter.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/MessageConverter.java similarity index 92% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MessageConverter.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/MessageConverter.java index ec87d77f1a7c..5e881cd860e8 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MessageConverter.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/MessageConverter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.context.thrift; +package com.navercorp.pinpoint.common.profiler.message; /** * @author Woonduk Kang(emeroad) diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ResultResponse.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/ResultResponse.java similarity index 92% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ResultResponse.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/ResultResponse.java index 5ddfd7f63fea..f5dcfa46c868 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ResultResponse.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/ResultResponse.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.common.profiler.message; public interface ResultResponse { boolean isSuccess(); diff --git a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/RouteResult.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/RouteResult.java new file mode 100644 index 000000000000..55d3305fa300 --- /dev/null +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/message/RouteResult.java @@ -0,0 +1,27 @@ +package com.navercorp.pinpoint.common.profiler.message; + +public enum RouteResult { + OK(0), + BAD_REQUEST(200), + EMPTY_REQUEST(201), + NOT_SUPPORTED_REQUEST(202), + BAD_RESPONSE(210), + EMPTY_RESPONSE(211), + NOT_SUPPORTED_RESPONSE(212), + TIMEOUT(220), + NOT_FOUND(230), + NOT_ACCEPTABLE(240), + NOT_SUPPORTED_SERVICE(241), + STREAM_CREATE_ERROR(250), + UNKNOWN(-1); + + private final int code; + + RouteResult(int code) { + this.code = code; + } + + public int code() { + return code; + } +} diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/DefaultResponseMessage.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/io/DefaultResponseMessage.java similarity index 96% rename from rpc/src/main/java/com/navercorp/pinpoint/rpc/DefaultResponseMessage.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/io/DefaultResponseMessage.java index 853ad55ca5a6..5fed54bb05f4 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/DefaultResponseMessage.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/io/DefaultResponseMessage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.rpc; +package com.navercorp.pinpoint.io; import java.util.Objects; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/ResponseMessage.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/io/ResponseMessage.java similarity index 95% rename from rpc/src/main/java/com/navercorp/pinpoint/rpc/ResponseMessage.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/io/ResponseMessage.java index 4bd363ea4b61..ec4489a6cb2c 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/ResponseMessage.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/io/ResponseMessage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.rpc; +package com.navercorp.pinpoint.io; /** * @author emeroad diff --git a/thrift/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java similarity index 80% rename from thrift/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java rename to commons-profiler/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java index d7867846f496..79ddb789d7ea 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/io/SpanVersion.java @@ -16,15 +16,15 @@ package com.navercorp.pinpoint.io; -import com.navercorp.pinpoint.thrift.dto.TraceConstants; - /** * @author Woonduk Kang(emeroad) */ public class SpanVersion { - public static final byte TRACE_V1 = TraceConstants.TRACE_V1; +// public static final byte TRACE_V1 = TraceConstants.TRACE_V1; +// public static final byte TRACE_V2 = TraceConstants.TRACE_V2; - public static final byte TRACE_V2 = TraceConstants.TRACE_V2; + public static final byte TRACE_V1 = 0; + public static final byte TRACE_V2 = 1; public static boolean supportedVersionRange(byte version) { if (version >= TRACE_V1 && version <= TRACE_V2) { diff --git a/thrift/src/test/java/com/navercorp/pinpoint/thrift/dto/SpanVersionTest.java b/commons-profiler/src/test/java/com/navercorp/pinpoint/io/SpanVersionTest.java similarity index 92% rename from thrift/src/test/java/com/navercorp/pinpoint/thrift/dto/SpanVersionTest.java rename to commons-profiler/src/test/java/com/navercorp/pinpoint/io/SpanVersionTest.java index 290685220331..bd6b2829de15 100644 --- a/thrift/src/test/java/com/navercorp/pinpoint/thrift/dto/SpanVersionTest.java +++ b/commons-profiler/src/test/java/com/navercorp/pinpoint/io/SpanVersionTest.java @@ -14,9 +14,8 @@ * limitations under the License. */ -package com.navercorp.pinpoint.thrift.dto; +package com.navercorp.pinpoint.io; -import com.navercorp.pinpoint.io.SpanVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/pom.xml b/pom.xml index 59cf796742eb..df84d17141af 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,7 @@ plugins plugins-loader profiler + profiler-thrift-datasender profiler-logging profiler-optional profiler-test @@ -408,6 +409,11 @@ pinpoint-profiler ${project.version} + + com.navercorp.pinpoint + thrift-datasender + ${project.version} + com.navercorp.pinpoint pinpoint-profiler-logging diff --git a/profiler-test/pom.xml b/profiler-test/pom.xml index a3f5a9f050a8..4bab1c3407f5 100644 --- a/profiler-test/pom.xml +++ b/profiler-test/pom.xml @@ -43,16 +43,6 @@ - - com.navercorp.pinpoint - pinpoint-thrift - - - org.apache.thrift - libthrift - - - com.navercorp.pinpoint pinpoint-bootstrap-core @@ -61,10 +51,6 @@ com.navercorp.pinpoint pinpoint-bootstrap - - com.navercorp.pinpoint - pinpoint-rpc - org.apache.commons @@ -90,31 +76,6 @@ asm-tree - - - org.apache.thrift - libthrift - - - httpclient - org.apache.httpcomponents - - - httpcore - org.apache.httpcomponents - - - slf4j-api - org.slf4j - - - org.apache.commons - commons-lang3 - - - - - org.slf4j diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/ApplicationContextHandler.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/ApplicationContextHandler.java index 8fbdbfb74991..d1b21802a3b3 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/ApplicationContextHandler.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/ApplicationContextHandler.java @@ -19,6 +19,9 @@ import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.TypeLiteral; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.loader.service.AnnotationKeyRegistryService; import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService; @@ -29,8 +32,6 @@ import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.SpanDataSender; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import java.util.ArrayList; import java.util.List; @@ -71,10 +72,10 @@ private OrderedSpanRecorder findRecorder(Injector injector) { } private TestTcpDataSender findTestTcpDataSender(Injector injector) { - TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() { + TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() { }; - Key> dataSenderKey = Key.get(dataSenderTypeLiteral); - EnhancedDataSender dataSender = injector.getInstance(dataSenderKey); + Key> dataSenderKey = Key.get(dataSenderTypeLiteral); + EnhancedDataSender dataSender = injector.getInstance(dataSenderKey); if (dataSender instanceof TestTcpDataSender) { return (TestTcpDataSender) dataSender; } diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/ListenableDataSender.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/ListenableDataSender.java index 0fb82982d34e..2b2f0876e341 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/ListenableDataSender.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/ListenableDataSender.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.test; -import com.navercorp.pinpoint.profiler.sender.DataSender; +import com.navercorp.pinpoint.common.profiler.message.DataSender; /** * @author emeroad diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataService.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataService.java index 7bbeb121705d..1f194d5f04ef 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataService.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataService.java @@ -17,13 +17,14 @@ package com.navercorp.pinpoint.test; import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; +import com.navercorp.pinpoint.profiler.cache.IdAllocator; +import com.navercorp.pinpoint.profiler.cache.Result; +import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.metadata.ApiMetaData; import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.cache.Result; -import com.navercorp.pinpoint.profiler.cache.IdAllocator; -import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import java.util.Objects; @@ -34,9 +35,9 @@ public class MockApiMetaDataService implements ApiMetaDataService { private final SimpleCache apiCache = new SimpleCache<>(new IdAllocator.ZigZagAllocator()); - private final EnhancedDataSender enhancedDataSender; + private final EnhancedDataSender enhancedDataSender; - public MockApiMetaDataService(EnhancedDataSender enhancedDataSender) { + public MockApiMetaDataService(EnhancedDataSender enhancedDataSender) { this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender"); } diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataServiceProvider.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataServiceProvider.java index 773375abb8e4..d1cc404e3b5b 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataServiceProvider.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApiMetaDataServiceProvider.java @@ -18,9 +18,10 @@ import com.google.inject.Inject; import com.google.inject.Provider; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import java.util.Objects; @@ -29,16 +30,16 @@ */ public class MockApiMetaDataServiceProvider implements Provider { - private final Provider> enhancedDataSenderProvider; + private final Provider> enhancedDataSenderProvider; @Inject - public MockApiMetaDataServiceProvider(Provider> enhancedDataSenderProvider) { + public MockApiMetaDataServiceProvider(Provider> enhancedDataSenderProvider) { this.enhancedDataSenderProvider = Objects.requireNonNull(enhancedDataSenderProvider, "enhancedDataSenderProvider"); } @Override public ApiMetaDataService get() { - final EnhancedDataSender enhancedDataSender = this.enhancedDataSenderProvider.get(); + final EnhancedDataSender enhancedDataSender = this.enhancedDataSenderProvider.get(); return new MockApiMetaDataService(enhancedDataSender); } diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockTraceContextFactory.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockTraceContextFactory.java index 9ac179ab9964..0d92b3a5966e 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockTraceContextFactory.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockTraceContextFactory.java @@ -16,21 +16,20 @@ package com.navercorp.pinpoint.test; +import com.google.inject.AbstractModule; +import com.google.inject.Module; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistryAdaptor; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.LoggingDataSender; import com.navercorp.pinpoint.profiler.AgentInformation; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.ModuleFactory; import com.navercorp.pinpoint.profiler.context.storage.LogStorageFactory; import com.navercorp.pinpoint.profiler.context.storage.StorageFactory; import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.LoggingDataSender; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java index 731257a3c488..d9e9b26c598e 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java @@ -21,12 +21,13 @@ import com.navercorp.pinpoint.bootstrap.AgentOption; import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.TransportModule; -import java.util.Objects; import com.navercorp.pinpoint.profiler.context.module.ApplicationContextModuleFactory; import com.navercorp.pinpoint.profiler.context.module.ModuleFactory; import com.navercorp.pinpoint.test.rpc.MockRpcModule; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Objects; /** * @author Woonduk Kang(emeroad) @@ -44,7 +45,7 @@ public OverrideModuleFactory(Module... overrideModule) { public Module newModule(AgentOption agentOption) { DefaultProfilerConfig profilerConfig = (DefaultProfilerConfig) agentOption.getProfilerConfig(); - profilerConfig.setTransportModule(TransportModule.THRIFT.name()); + profilerConfig.setTransportModule(TransportModule.GRPC.name()); ModuleFactory moduleFactory = new ApplicationContextModuleFactory() { @Override diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/PluginApplicationContextModule.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/PluginApplicationContextModule.java index 901a3bde9511..0fe55f4979b3 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/PluginApplicationContextModule.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/PluginApplicationContextModule.java @@ -20,7 +20,9 @@ import com.google.inject.Key; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; -import com.google.inject.util.Providers; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataRegistryService; import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService; import com.navercorp.pinpoint.profiler.context.SpanType; @@ -30,12 +32,9 @@ import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List; @@ -67,11 +66,9 @@ protected void configure() { bind(StorageFactory.class).to(TestSpanStorageFactory.class); - bind(PinpointClientFactory.class).toProvider(Providers.of(null)); - - EnhancedDataSender enhancedDataSender = newTcpDataSender(); + EnhancedDataSender enhancedDataSender = newTcpDataSender(); logger.debug("enhancedDataSender:{}", enhancedDataSender); - TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() {}; + TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() {}; bind(dataSenderTypeLiteral).toInstance(enhancedDataSender); ServerMetaDataRegistryService serverMetaDataRegistryService = newServerMetaDataRegistryService(); @@ -92,7 +89,7 @@ private DataSender newUdpSpanDataSender() { return sender; } - private EnhancedDataSender newTcpDataSender() { + private EnhancedDataSender newTcpDataSender() { return new TestTcpDataSender(); } diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TBaseRecorder.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/Recorder.java similarity index 96% rename from profiler-test/src/main/java/com/navercorp/pinpoint/test/TBaseRecorder.java rename to profiler-test/src/main/java/com/navercorp/pinpoint/test/Recorder.java index 7e31ace1032d..6664c1a86887 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TBaseRecorder.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/Recorder.java @@ -23,7 +23,7 @@ /** * @author hyungil.jeong */ -public class TBaseRecorder implements Iterable { +public class Recorder implements Iterable { private final Queue queue = new ConcurrentLinkedQueue(); diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TBaseRecorderAdaptor.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/RecorderAdaptor.java similarity index 69% rename from profiler-test/src/main/java/com/navercorp/pinpoint/test/TBaseRecorderAdaptor.java rename to profiler-test/src/main/java/com/navercorp/pinpoint/test/RecorderAdaptor.java index 74e728850b26..b6e501ff445d 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TBaseRecorderAdaptor.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/RecorderAdaptor.java @@ -16,19 +16,17 @@ package com.navercorp.pinpoint.test; +import java.util.Objects; + /** * @author emeroad */ -public class TBaseRecorderAdaptor implements ListenableDataSender.Listener { - - private final TBaseRecorder recorder; +public class RecorderAdaptor implements ListenableDataSender.Listener { - public TBaseRecorderAdaptor() { - this.recorder = new TBaseRecorder(); - } + private final Recorder recorder; - public TBaseRecorderAdaptor(TBaseRecorder recorder) { - this.recorder = recorder; + public RecorderAdaptor(Recorder recorder) { + this.recorder = Objects.requireNonNull(recorder, "recorder"); } @Override @@ -36,7 +34,7 @@ public boolean handleSend(T data) { return recorder.add(data); } - public TBaseRecorder getRecorder() { + public Recorder getRecorder() { return recorder; } } diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestSpanStorageFactory.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestSpanStorageFactory.java index 5b339b68c1e9..c5245bc47ede 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestSpanStorageFactory.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestSpanStorageFactory.java @@ -17,14 +17,15 @@ package com.navercorp.pinpoint.test; import com.google.inject.Inject; -import java.util.Objects; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.SpanChunkFactory; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.module.SpanDataSender; import com.navercorp.pinpoint.profiler.context.storage.BufferedStorage; import com.navercorp.pinpoint.profiler.context.storage.Storage; import com.navercorp.pinpoint.profiler.context.storage.StorageFactory; -import com.navercorp.pinpoint.profiler.sender.DataSender; + +import java.util.Objects; /** diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestTcpDataSender.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestTcpDataSender.java index 3129cf0a4276..bddedd05ffe1 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestTcpDataSender.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/TestTcpDataSender.java @@ -15,12 +15,12 @@ */ package com.navercorp.pinpoint.test; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.metadata.ApiMetaData; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.metadata.SqlMetaData; import com.navercorp.pinpoint.profiler.metadata.StringMetaData; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.test.util.BiHashMap; import com.navercorp.pinpoint.test.util.Pair; @@ -37,7 +37,7 @@ * @author Jongho Moon * @author jaehong.kim */ -public class TestTcpDataSender implements EnhancedDataSender { +public class TestTcpDataSender implements EnhancedDataSender { private final List datas = Collections.synchronizedList(new ArrayList<>()); diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/junit4/BasePinpointTest.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/junit4/BasePinpointTest.java index 0e1d65cf218b..2d57965e38ae 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/junit4/BasePinpointTest.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/junit4/BasePinpointTest.java @@ -16,22 +16,20 @@ package com.navercorp.pinpoint.test.junit4; -import java.util.ArrayList; -import java.util.List; - +import com.navercorp.pinpoint.bootstrap.context.ServerMetaData; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService; +import com.navercorp.pinpoint.profiler.context.Span; import com.navercorp.pinpoint.profiler.context.SpanChunk; +import com.navercorp.pinpoint.profiler.context.SpanEvent; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; -import com.navercorp.pinpoint.profiler.sender.DataSender; import com.navercorp.pinpoint.test.ListenableDataSender; - +import com.navercorp.pinpoint.test.Recorder; import org.junit.runner.RunWith; -import com.navercorp.pinpoint.bootstrap.context.ServerMetaData; -import com.navercorp.pinpoint.profiler.context.Span; -import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.test.TBaseRecorder; +import java.util.ArrayList; +import java.util.List; /** * @author hyungil.jeong @@ -39,12 +37,12 @@ @RunWith(value = PinpointJUnit4ClassRunner.class) public abstract class BasePinpointTest { - private volatile TBaseRecorder tBaseRecorder; + private volatile Recorder recorder; private volatile ServerMetaDataRegistryService serverMetaDataRegistryService; protected List getCurrentSpanEvents() { List spanEvents = new ArrayList<>(); - for (SpanType value : this.tBaseRecorder) { + for (SpanType value : this.recorder) { if (value instanceof SpanChunk) { final SpanChunk spanChunk = (SpanChunk) value; for (SpanEvent tSpanEvent : spanChunk.getSpanEventList()) { @@ -58,7 +56,7 @@ protected List getCurrentSpanEvents() { protected List getCurrentRootSpans() { List rootSpans = new ArrayList<>(); - for (Object value : this.tBaseRecorder) { + for (Object value : this.recorder) { if (value instanceof Span) { Span span = (Span) value; rootSpans.add(span); @@ -71,8 +69,8 @@ protected ServerMetaData getServerMetaData() { return this.serverMetaDataRegistryService.getServerMetaData(); } - private void setTBaseRecorder(TBaseRecorder tBaseRecorder) { - this.tBaseRecorder = tBaseRecorder; + private void setTBaseRecorder(Recorder recorder) { + this.recorder = recorder; } private void setServerMetaDataRegistryService(ServerMetaDataRegistryService serverMetaDataRegistryService) { @@ -86,7 +84,7 @@ public void setup(TestContext testContext) { if (spanDataSender instanceof ListenableDataSender) { ListenableDataSender listenableDataSender = (ListenableDataSender) spanDataSender; - final TBaseRecorder tBaseRecord = new TBaseRecorder<>(); + final Recorder tBaseRecord = new Recorder<>(); listenableDataSender.setListener(new ListenableDataSender.Listener() { @Override diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/rpc/MockRpcModule.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/rpc/MockRpcModule.java index 83752f87a63f..c7ed09730825 100644 --- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/rpc/MockRpcModule.java +++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/rpc/MockRpcModule.java @@ -21,24 +21,25 @@ import com.google.inject.Scopes; import com.google.inject.TypeLiteral; import com.google.inject.name.Names; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.ResultResponse; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.SpanType; +import com.navercorp.pinpoint.profiler.context.grpc.GrpcMessageToResultConverterProvider; import com.navercorp.pinpoint.profiler.context.module.AgentDataSender; import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; import com.navercorp.pinpoint.profiler.context.module.ModuleLifeCycle; import com.navercorp.pinpoint.profiler.context.module.ResultConverter; import com.navercorp.pinpoint.profiler.context.module.SpanDataSender; import com.navercorp.pinpoint.profiler.context.module.StatDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftMessageToResultConverterProvider; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; import com.navercorp.pinpoint.test.ListenableDataSender; import com.navercorp.pinpoint.test.TestTcpDataSender; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * @author Woonduk Kang(emeroad) @@ -69,25 +70,25 @@ protected void configure() { bind(statDataSenderKey).toInstance(statDataSender); expose(statDataSenderKey); - EnhancedDataSender enhancedDataSender = new TestTcpDataSender(); + EnhancedDataSender enhancedDataSender = new TestTcpDataSender(); logger.debug("enhancedDataSender:{}", enhancedDataSender); - TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() { + TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() { }; bind(dataSenderTypeLiteral).toInstance(enhancedDataSender); expose(dataSenderTypeLiteral); - Key> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class); + Key> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class); bind(agentDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON); expose(agentDataSender); - Key> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class); + Key> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class); bind(metadataDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON); expose(metadataDataSender); TypeLiteral> resultMessageConverter = new TypeLiteral>() {}; Key> resultMessageConverterKey = Key.get(resultMessageConverter, ResultConverter.class); - bind(resultMessageConverterKey).toProvider(ThriftMessageToResultConverterProvider.class ).in(Scopes.SINGLETON); + bind(resultMessageConverterKey).toProvider(GrpcMessageToResultConverterProvider.class).in(Scopes.SINGLETON); expose(resultMessageConverterKey); diff --git a/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java b/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java index 6039ef2c0bdf..426041db416b 100644 --- a/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java +++ b/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.test.monitor; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig; import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor; import com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor; @@ -24,10 +25,9 @@ import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshotBatch; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; import com.navercorp.pinpoint.test.ListenableDataSender; -import com.navercorp.pinpoint.test.TBaseRecorder; -import com.navercorp.pinpoint.test.TBaseRecorderAdaptor; +import com.navercorp.pinpoint.test.Recorder; +import com.navercorp.pinpoint.test.RecorderAdaptor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeEach; @@ -48,7 +48,7 @@ public class AgentStatMonitorTest { private final Logger logger = LogManager.getLogger(this.getClass()); - private TBaseRecorder tBaseRecorder; + private Recorder recorder; private DataSender dataSender; @Mock @@ -58,8 +58,8 @@ public class AgentStatMonitorTest { public void beforeEach() { when(agentStatCollector.collect()).thenReturn(new AgentStatMetricSnapshot()); - this.tBaseRecorder = new TBaseRecorder<>(); - ListenableDataSender.Listener recorderAdaptor = new TBaseRecorderAdaptor<>(tBaseRecorder); + this.recorder = new Recorder<>(); + ListenableDataSender.Listener recorderAdaptor = new RecorderAdaptor<>(recorder); ListenableDataSender listenableDataSender = new ListenableDataSender<>("testDataSender"); listenableDataSender.setListener((ListenableDataSender.Listener) recorderAdaptor); @@ -88,8 +88,8 @@ public void testAgentStatMonitor() throws InterruptedException { Thread.sleep(totalTestDurationMs); monitor.stop(); // Then - assertTrue(tBaseRecorder.size() >= minNumBatchToTest); - for (AgentStatMetricSnapshotBatch agentStatBatch : tBaseRecorder) { + assertTrue(recorder.size() >= minNumBatchToTest); + for (AgentStatMetricSnapshotBatch agentStatBatch : recorder) { logger.debug("agentStatBatch:{}", agentStatBatch); assertTrue(agentStatBatch.getAgentStats().size() <= numCollectionsPerBatch); } diff --git a/profiler-thrift-datasender/pom.xml b/profiler-thrift-datasender/pom.xml new file mode 100644 index 000000000000..9c899cae4a07 --- /dev/null +++ b/profiler-thrift-datasender/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + com.navercorp.pinpoint + pinpoint + 2.6.0-SNAPSHOT + + + thrift-datasender + jar + pinpoint profiler thrift(deprecated) + + + 1.8 + ${env.JAVA_8_HOME} + + + + + com.navercorp.pinpoint + pinpoint-annotations + + + com.navercorp.pinpoint + pinpoint-commons + + + com.navercorp.pinpoint + pinpoint-rpc + + + com.navercorp.pinpoint + pinpoint-grpc + + + com.navercorp.pinpoint + pinpoint-commons-profiler + + + com.navercorp.pinpoint + pinpoint-profiler + + + com.navercorp.pinpoint + pinpoint-thrift + + + org.apache.thrift + libthrift + + + + + org.apache.logging.log4j + log4j-slf4j-impl + compile + + + org.apache.logging.log4j + log4j-core + compile + + + org.apache.logging.log4j + log4j-api + compile + + + + com.navercorp.pinpoint + pinpoint-rpc + ${project.version} + test-jar + test + + + com.navercorp.pinpoint + pinpoint-profiler-logging + test + + + com.navercorp.pinpoint + pinpoint-testcase + test + + + org.awaitility + awaitility + test + + + + + + + + + + \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ByteMessage.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ByteMessage.java similarity index 96% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ByteMessage.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ByteMessage.java index 4512b894dc4b..09e48a599bfc 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ByteMessage.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ByteMessage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import java.util.Objects; diff --git a/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MaxBytesLengthPredicate.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MaxBytesLengthPredicate.java new file mode 100644 index 000000000000..8d577295ccd4 --- /dev/null +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MaxBytesLengthPredicate.java @@ -0,0 +1,33 @@ +package com.navercorp.pinpoint.thrift.sender; + +import org.apache.logging.log4j.Logger; + +import java.util.Objects; +import java.util.function.BiPredicate; + +public class MaxBytesLengthPredicate implements BiPredicate { + + private final Logger logger; + private final int maxPacketLength; + + public MaxBytesLengthPredicate(Logger logger, int maxPacketLength) { + this.logger = Objects.requireNonNull(logger, "logger"); + this.maxPacketLength = maxPacketLength; + } + + @Override + public boolean test(byte[] bytes, M message) { + // do not copy bytes because it's single threaded + if (isLimit(bytes.length)) { + // When packet size is greater than UDP packet size limit, it's better to discard packet than let the socket API fails. + logger.info("discard packet. Caused:too large message. size:{}, {}", bytes.length, message); + return false; + } + return true; + } + + + private boolean isLimit(int interBufferSize) { + return interBufferSize > maxPacketLength; + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/MessageSerializer.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MessageSerializer.java similarity index 93% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/MessageSerializer.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MessageSerializer.java index 43742cfcc57b..25c799571740 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/MessageSerializer.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/MessageSerializer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; /** * @author Woonduk Kang(emeroad) diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/PortUnreachableHandler.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/PortUnreachableHandler.java similarity index 93% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/PortUnreachableHandler.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/PortUnreachableHandler.java index 84c2ff7fe8b3..6e7c133db763 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/PortUnreachableHandler.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/PortUnreachableHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; /** * @author Woonduk Kang(emeroad) diff --git a/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ReconnectEventListenerRegistry.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ReconnectEventListenerRegistry.java new file mode 100644 index 000000000000..962d49dd47ed --- /dev/null +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ReconnectEventListenerRegistry.java @@ -0,0 +1,7 @@ +package com.navercorp.pinpoint.thrift.sender; + +import java.util.function.Consumer; + +public interface ReconnectEventListenerRegistry { + boolean addEventListener(Consumer eventListener); +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RefreshStrategy.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RefreshStrategy.java similarity index 98% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RefreshStrategy.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RefreshStrategy.java index 84f59ac7f50d..224403b58cec 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RefreshStrategy.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RefreshStrategy.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import java.util.Objects; import com.navercorp.pinpoint.rpc.client.SocketAddressProvider; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.net.InetSocketAddress; +import java.util.Objects; import java.util.concurrent.TimeUnit; /** diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RequestMessage.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RequestMessage.java similarity index 76% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RequestMessage.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RequestMessage.java index e85921edbb31..9fe0b31e6d62 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RequestMessage.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RequestMessage.java @@ -14,21 +14,19 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; - -import com.navercorp.pinpoint.rpc.ResponseMessage; +package com.navercorp.pinpoint.thrift.sender; import java.util.function.BiConsumer; /** * @author Woonduk Kang(emeroad) */ -public interface RequestMessage { +public interface RequestMessage { - M getMessage(); + REQ getMessage(); int getRetryCount(); - BiConsumer getFutureListener(); + BiConsumer getFutureListener(); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RequestMessageFactory.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RequestMessageFactory.java similarity index 69% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RequestMessageFactory.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RequestMessageFactory.java index 5fbf36df0143..514574ee1b45 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RequestMessageFactory.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RequestMessageFactory.java @@ -14,11 +14,9 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; -import com.navercorp.pinpoint.rpc.ResponseMessage; - import java.util.function.BiConsumer; /** @@ -29,11 +27,11 @@ public final class RequestMessageFactory { private RequestMessageFactory() { } - public static RequestMessage request(T message, int retryCount) { - return new RetryRequestMessage<>(message, retryCount, null); + public static RequestMessage request(T message, int retryCount) { + return new RetryRequestMessage<>(message, retryCount); } - public static RequestMessage request(T message, int retryCount, BiConsumer futureListener) { + public static RequestMessage request(T message, int retryCount, BiConsumer futureListener) { return new RetryRequestMessage<>(message, retryCount, futureListener); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryMessage.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryMessage.java similarity index 98% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryMessage.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryMessage.java index 62a7c328cb85..fa9fadb07676 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryMessage.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryMessage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.common.util.ArrayUtils; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryQueue.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryQueue.java similarity index 98% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryQueue.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryQueue.java index c1d01bafabf9..bbfbc09472ff 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryQueue.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryQueue.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - /** * @author emeroad */ diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryRequestMessage.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryRequestMessage.java similarity index 54% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryRequestMessage.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryRequestMessage.java index 73a9ff73d120..675586a8d5fe 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/RetryRequestMessage.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/RetryRequestMessage.java @@ -14,30 +14,35 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; - -import com.navercorp.pinpoint.rpc.ResponseMessage; +package com.navercorp.pinpoint.thrift.sender; +import java.util.Objects; import java.util.function.BiConsumer; /** * @author Woonduk Kang(emeroad) */ -class RetryRequestMessage implements RequestMessage { - private final T message; +class RetryRequestMessage implements RequestMessage { + private final REQ message; private final int retryCount; - private final BiConsumer futureListener; + private final BiConsumer futureListener; + + RetryRequestMessage(REQ message, int retryCount) { + this.message = Objects.requireNonNull(message, "message"); + this.retryCount = retryCount; + this.futureListener = null; + } - RetryRequestMessage(T message, int retryCount, BiConsumer futureListener) { - this.message = message; + RetryRequestMessage(REQ message, int retryCount, BiConsumer futureListener) { + this.message = Objects.requireNonNull(message, "message"); this.retryCount = retryCount; - this.futureListener = futureListener; + this.futureListener = Objects.requireNonNull(futureListener, "futureListener"); } @Override - public T getMessage() { + public REQ getMessage() { return message; } @@ -47,7 +52,7 @@ public int getRetryCount() { } @Override - public BiConsumer getFutureListener() { + public BiConsumer getFutureListener() { return futureListener; } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/TcpDataSender.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/TcpDataSender.java similarity index 90% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/TcpDataSender.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/TcpDataSender.java index fb75170117d4..34316d55565f 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/TcpDataSender.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/TcpDataSender.java @@ -14,15 +14,17 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; +import com.navercorp.pinpoint.common.profiler.concurrent.executor.AsyncQueueingExecutor; +import com.navercorp.pinpoint.common.profiler.message.BypassMessageConverter; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.common.util.StringUtils; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.io.request.Message; -import com.navercorp.pinpoint.profiler.context.thrift.BypassMessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.client.PinpointClient; import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; import com.navercorp.pinpoint.rpc.util.ClientFactoryUtils; @@ -46,14 +48,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; -import java.util.function.Consumer; /** * @author emeroad * @author koo.taejin * @author netspider */ -public class TcpDataSender implements EnhancedDataSender, ReconnectEventListenerRegistry { +public class TcpDataSender implements EnhancedDataSender, ReconnectEventListenerRegistry { private static final int DEFAULT_QUEUE_SIZE = 1024 * 5; @@ -116,14 +117,7 @@ private TcpDataSender(String name, ClientFactoryUtils.PinpointClientProvider cli } private AsyncQueueingExecutor createAsyncQueueingExecutor(int queueSize, String executorName) { - AsyncQueueingExecutorListener listener = new DefaultAsyncQueueingExecutorListener() { - @Override - public void execute(Object message) { - TcpDataSender.this.sendPacket(message); - } - }; - final AsyncQueueingExecutor executor = new AsyncQueueingExecutor<>(queueSize, executorName, listener); - return executor; + return new AsyncQueueingExecutor<>(queueSize, executorName, this::sendPacket); } private Logger newLogger(String name) { @@ -170,13 +164,13 @@ public boolean request(T data) { @Override public boolean request(T data, int retryCount) { - final RequestMessage message = RequestMessageFactory.request(data, retryCount); + final RequestMessage message = RequestMessageFactory.request(data, retryCount); return executor.execute(message); } @Override public boolean request(T data, BiConsumer listener) { - final RequestMessage message = RequestMessageFactory.request(data, 3, listener); + final RequestMessage message = RequestMessageFactory.request(data, 3, listener); return executor.execute(message); } @@ -185,7 +179,7 @@ public boolean isConnected() { } @Override - public boolean addEventListener(Consumer eventListener) { + public boolean addEventListener(java.util.function.Consumer eventListener) { return this.client.addPinpointClientReconnectEventListener(eventListener); } @@ -206,8 +200,8 @@ public void stop() { protected void sendPacket(Object message) { try { - if (message instanceof RequestMessage) { - final RequestMessage requestMessage = (RequestMessage) message; + if (message instanceof RequestMessage) { + final RequestMessage requestMessage = (RequestMessage) message; if (doRequest(requestMessage)) { return; } @@ -224,7 +218,7 @@ protected void sendPacket(Object message) { } } - private boolean doRequest(RequestMessage requestMessage) { + private boolean doRequest(RequestMessage requestMessage) { final T message = requestMessage.getMessage(); final byte[] copy = messageSerializer.serializer(message); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftMessageSerializer.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftMessageSerializer.java similarity index 60% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftMessageSerializer.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftMessageSerializer.java index 0b383c8a2e93..ec91fccfd591 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftMessageSerializer.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftMessageSerializer.java @@ -14,16 +14,18 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; -import java.util.Objects; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; import com.navercorp.pinpoint.thrift.io.TBaseSerializer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.thrift.TBase; import org.apache.thrift.TException; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; + +import java.util.Objects; +import java.util.function.BiPredicate; /** * @author Woonduk Kang(emeroad) @@ -38,6 +40,8 @@ public class ThriftMessageSerializer implements MessageSerializer private final TBaseSerializer serializer; private final MessageConverter> messageConverter; + private final BiPredicate> filter; + public ThriftMessageSerializer(MessageConverter> messageConverter) { this(messageConverter, HeaderTBaseSerializerFactory.DEFAULT_FACTORY.createSerializer()); } @@ -45,31 +49,47 @@ public ThriftMessageSerializer(MessageConverter> messageConverter public ThriftMessageSerializer(MessageConverter> messageConverter, TBaseSerializer serializer) { this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter"); this.serializer = Objects.requireNonNull(serializer, "serializer"); + this.filter = null; + } + public ThriftMessageSerializer(MessageConverter> messageConverter, TBaseSerializer serializer, BiPredicate> filter) { + this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter"); + this.serializer = Objects.requireNonNull(serializer, "serializer"); + this.filter = filter; } // single thread only @Override public byte[] serializer(T message) { - if (message instanceof TBase) { - final TBase tBase = (TBase) message; - return serialize(serializer, tBase); + if (message == null) { + return null; + } + final TBase tBase = toTBase(message); + if (tBase == null) { + return null; } + return serialize(tBase); + } - final TBase tBase = messageConverter.toMessage(message); - if (tBase != null) { - return serialize(serializer, tBase); + public TBase toTBase(T message) { + if (message instanceof TBase) { + return (TBase) message; } - return null; + return messageConverter.toMessage(message); } - private byte[] serialize(TBaseSerializer serializer, TBase tBase) { + public byte[] serialize(TBase tBase) { try { - return serializer.serialize(tBase); - } catch (TException e) { - if (logger.isWarnEnabled()) { - logger.warn("Serialize {} failed. Error:{}", tBase, e.getMessage(), e); + final byte[] bytes = serializer.serialize(tBase); + if (filter == null) { + return bytes; } + if (filter.test(bytes, tBase)) { + return bytes; + } + return null; + } catch (TException e) { + logger.warn("Serialize {} failed. Error:{}", tBase, e.getMessage(), e); } return null; } diff --git a/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftUdpMessageSerializer.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftUdpMessageSerializer.java new file mode 100644 index 000000000000..8cc9c69f68cf --- /dev/null +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/ThriftUdpMessageSerializer.java @@ -0,0 +1,67 @@ +/* + * Copyright 2018 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.thrift.sender; + +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.thrift.TBase; + +import java.util.function.BiPredicate; + + +/** + * not thread safe + * @author Woonduk Kang(emeroad) + */ +public class ThriftUdpMessageSerializer implements MessageSerializer { + + public static final int UDP_MAX_PACKET_LENGTH = 65507; + + private final Logger logger = LogManager.getLogger(this.getClass()); + + // Caution. not thread safe + private final MessageSerializer messageSerializer; + + private final BiPredicate> filter; + + public ThriftUdpMessageSerializer(MessageConverter> messageConverter, HeaderTBaseSerializer serializer) { + this.filter = new MaxBytesLengthPredicate<>(logger, ThriftUdpMessageSerializer.UDP_MAX_PACKET_LENGTH); + this.messageSerializer = new ThriftMessageSerializer<>(messageConverter, serializer, filter); + } + + public ThriftUdpMessageSerializer(MessageConverter> messageConverter, HeaderTBaseSerializer serializer, + BiPredicate> filter) { + this.filter = filter; + this.messageSerializer = new ThriftMessageSerializer<>(messageConverter, serializer, filter); + } + + // single thread only + @Override + public ByteMessage serializer(T message) { + if (message == null) { + return null; + } + byte[] bytes = messageSerializer.serializer(message); + if (bytes == null) { + return null; + } + + return ByteMessage.wrap(bytes); + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSender.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpDataSender.java similarity index 92% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSender.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpDataSender.java index 96d9a6498961..9cc547dd1e11 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSender.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpDataSender.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.common.plugin.util.HostAndPort; -import java.util.Objects; - +import com.navercorp.pinpoint.common.profiler.concurrent.executor.AsyncQueueingExecutor; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.rpc.client.DnsSocketAddressProvider; import com.navercorp.pinpoint.rpc.client.SocketAddressProvider; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.net.DatagramPacket; @@ -31,6 +31,7 @@ import java.net.InetSocketAddress; import java.net.PortUnreachableException; import java.net.SocketException; +import java.util.Objects; /** * @author netspider @@ -85,14 +86,7 @@ public boolean send(T data) { } private AsyncQueueingExecutor createAsyncQueueingExecutor(int queueSize, String executorName) { - AsyncQueueingExecutorListener listener = new DefaultAsyncQueueingExecutorListener() { - @Override - public void execute(T message) { - UdpDataSender.this.sendPacket(message); - } - }; - final AsyncQueueingExecutor executor = new AsyncQueueingExecutor<>(queueSize, executorName, listener); - return executor; + return new AsyncQueueingExecutor<>(queueSize, executorName, this::sendPacket); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderFactory.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpDataSenderFactory.java similarity index 85% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderFactory.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpDataSenderFactory.java index 9892dabfc2ed..f73ec1e6dd75 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderFactory.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpDataSenderFactory.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; -import java.util.Objects; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; import com.navercorp.pinpoint.thrift.io.SerializerFactory; @@ -25,6 +25,8 @@ import org.apache.logging.log4j.Logger; import org.apache.thrift.TBase; +import java.util.Objects; + /** * @author Taejin Koo */ @@ -52,15 +54,7 @@ public UdpDataSenderFactory(String host, int port, String threadName, int queueS this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter"); } - public DataSender create(String typeName) { - return create(UdpDataSenderType.valueOf(typeName)); - } - - public DataSender create(UdpDataSenderType type) { - if (type == UdpDataSenderType.NIO) { - logger.warn("NIO UdpDataSenderType is deprecated"); - } - + public DataSender create() { SerializerFactory serializerFactory = new HeaderTBaseSerializerFactory( ThriftUdpMessageSerializer.UDP_MAX_PACKET_LENGTH, HeaderTBaseSerializerFactory.DEFAULT_TBASE_LOCATOR); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpSocketAddressProvider.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpSocketAddressProvider.java similarity index 94% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpSocketAddressProvider.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpSocketAddressProvider.java index a81ba1ddf4f3..f1dee5bf5cca 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpSocketAddressProvider.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/UdpSocketAddressProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.rpc.client.SocketAddressProvider; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/WriteFailFutureListener.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/WriteFailFutureListener.java similarity index 96% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/WriteFailFutureListener.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/WriteFailFutureListener.java index acc6715885e3..ba74406279c5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/WriteFailFutureListener.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/WriteFailFutureListener.java @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import org.apache.logging.log4j.Logger; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/CommandGrpcToThriftMessageConverter.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/CommandGrpcToThriftMessageConverter.java similarity index 97% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/CommandGrpcToThriftMessageConverter.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/CommandGrpcToThriftMessageConverter.java index a6b69824e25b..ef16943605cb 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/CommandGrpcToThriftMessageConverter.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/CommandGrpcToThriftMessageConverter.java @@ -1,176 +1,177 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.grpc.trace.PActiveThreadDump; -import com.navercorp.pinpoint.grpc.trace.PActiveThreadLightDump; -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadCountRes; -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDumpRes; -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDumpRes; -import com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse; -import com.navercorp.pinpoint.grpc.trace.PMonitorInfo; -import com.navercorp.pinpoint.grpc.trace.PThreadDump; -import com.navercorp.pinpoint.grpc.trace.PThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDumpRes; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDumpRes; -import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; -import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo; -import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TThreadState; -import org.apache.thrift.TBase; - -import java.util.List; - -/** - * @author Taejin Koo - */ -public class CommandGrpcToThriftMessageConverter implements MessageConverter> { - - @Override - public TBase toMessage(Object message) { - if (message instanceof PCmdEchoResponse) { - return buildTCommandEcho((PCmdEchoResponse) message); - } else if (message instanceof PCmdActiveThreadCountRes) { - return buildTCmdActiveThreadCountRes((PCmdActiveThreadCountRes) message); - } else if (message instanceof PCmdActiveThreadDumpRes) { - return buildTCmdActiveThreadDumpRes((PCmdActiveThreadDumpRes) message); - } else if (message instanceof PCmdActiveThreadLightDumpRes) { - return buildTCmdActiveThreadLightDumpRes((PCmdActiveThreadLightDumpRes) message); - } - return null; - } - - private TCommandEcho buildTCommandEcho(PCmdEchoResponse echoMessage) { - String message = echoMessage.getMessage(); - return new TCommandEcho(message); - } - - private TCmdActiveThreadCountRes buildTCmdActiveThreadCountRes(PCmdActiveThreadCountRes activeThreadCountRes) { - int histogramSchemaType = activeThreadCountRes.getHistogramSchemaType(); - List activeThreadCountList = activeThreadCountRes.getActiveThreadCountList(); - long timeStamp = activeThreadCountRes.getTimeStamp(); - - TCmdActiveThreadCountRes result = new TCmdActiveThreadCountRes(histogramSchemaType, activeThreadCountList); - result.setTimeStamp(timeStamp); - - return result; - } - - private TCmdActiveThreadDumpRes buildTCmdActiveThreadDumpRes(PCmdActiveThreadDumpRes pCmdActiveThreadDumpRes) { - TCmdActiveThreadDumpRes tCmdActiveThreadDumpRes = new TCmdActiveThreadDumpRes(); - tCmdActiveThreadDumpRes.setVersion(pCmdActiveThreadDumpRes.getVersion()); - tCmdActiveThreadDumpRes.setType(pCmdActiveThreadDumpRes.getType()); - tCmdActiveThreadDumpRes.setSubType(pCmdActiveThreadDumpRes.getSubType()); - - for (PActiveThreadDump pActiveThreadDump : pCmdActiveThreadDumpRes.getThreadDumpList()) { - tCmdActiveThreadDumpRes.addToThreadDumps(buildTActiveThreadDump(pActiveThreadDump)); - } - - return tCmdActiveThreadDumpRes; - } - - private TActiveThreadDump buildTActiveThreadDump(PActiveThreadDump pActiveThreadDump) { - TActiveThreadDump tActiveThreadDump = new TActiveThreadDump(); - tActiveThreadDump.setStartTime(pActiveThreadDump.getStartTime()); - tActiveThreadDump.setSampled(pActiveThreadDump.getSampled()); - - if (pActiveThreadDump.getSampled()) { - tActiveThreadDump.setLocalTraceId(pActiveThreadDump.getLocalTraceId()); - tActiveThreadDump.setTransactionId(pActiveThreadDump.getTransactionId()); - tActiveThreadDump.setEntryPoint(pActiveThreadDump.getEntryPoint()); - } - - tActiveThreadDump.setThreadDump(buildTThreadDump(pActiveThreadDump.getThreadDump())); - return tActiveThreadDump; - } - - private TThreadDump buildTThreadDump(PThreadDump pThreadDump) { - TThreadDump tThreadDump = new TThreadDump(); - tThreadDump.setThreadName(pThreadDump.getThreadName()); - tThreadDump.setThreadId(pThreadDump.getThreadId()); - tThreadDump.setBlockedTime(pThreadDump.getBlockedTime()); - tThreadDump.setBlockedCount(pThreadDump.getBlockedCount()); - tThreadDump.setWaitedTime(pThreadDump.getWaitedTime()); - tThreadDump.setWaitedCount(pThreadDump.getWaitedCount()); - - tThreadDump.setInNative(pThreadDump.getInNative()); - tThreadDump.setSuspended(pThreadDump.getSuspended()); - tThreadDump.setThreadState(TThreadState.findByValue(pThreadDump.getThreadStateValue())); - - for (String stackTrace : pThreadDump.getStackTraceList()) { - tThreadDump.addToStackTrace(stackTrace); - } - - for (PMonitorInfo pMonitorInfo : pThreadDump.getLockedMonitorList()) { - final TMonitorInfo tMonitorInfo = new TMonitorInfo(); - tMonitorInfo.setStackDepth(pMonitorInfo.getStackDepth()); - tMonitorInfo.setStackFrame(pMonitorInfo.getStackFrame()); - tThreadDump.addToLockedMonitors(tMonitorInfo); - } - - - tThreadDump.setLockName(pThreadDump.getLockName()); - tThreadDump.setLockOwnerId(pThreadDump.getLockOwnerId()); - tThreadDump.setLockOwnerName(pThreadDump.getLockOwnerName()); - for (String lockedSynchronizer : pThreadDump.getLockedSynchronizerList()) { - tThreadDump.addToLockedSynchronizers(lockedSynchronizer); - } - - return tThreadDump; - } - - private TCmdActiveThreadLightDumpRes buildTCmdActiveThreadLightDumpRes(PCmdActiveThreadLightDumpRes pCmdActiveThreadLightDumpRes) { - TCmdActiveThreadLightDumpRes tCmdActiveThreadLightDumpRes = new TCmdActiveThreadLightDumpRes(); - tCmdActiveThreadLightDumpRes.setVersion(pCmdActiveThreadLightDumpRes.getVersion()); - tCmdActiveThreadLightDumpRes.setType(pCmdActiveThreadLightDumpRes.getType()); - tCmdActiveThreadLightDumpRes.setSubType(pCmdActiveThreadLightDumpRes.getSubType()); - - for (PActiveThreadLightDump pActiveThreadLightDump : pCmdActiveThreadLightDumpRes.getThreadDumpList()) { - tCmdActiveThreadLightDumpRes.addToThreadDumps(buildTActiveThreadLightDump(pActiveThreadLightDump)); - } - - return tCmdActiveThreadLightDumpRes; - } - - private TActiveThreadLightDump buildTActiveThreadLightDump(PActiveThreadLightDump pActiveThreadLightDump) { - TActiveThreadLightDump tActiveThreadLightDump = new TActiveThreadLightDump(); - tActiveThreadLightDump.setStartTime(pActiveThreadLightDump.getStartTime()); - tActiveThreadLightDump.setSampled(pActiveThreadLightDump.getSampled()); - - if (pActiveThreadLightDump.getSampled()) { - tActiveThreadLightDump.setLocalTraceId(pActiveThreadLightDump.getLocalTraceId()); - tActiveThreadLightDump.setTransactionId(pActiveThreadLightDump.getTransactionId()); - tActiveThreadLightDump.setEntryPoint(pActiveThreadLightDump.getEntryPoint()); - } - - tActiveThreadLightDump.setThreadDump(buildTThreadLightDump(pActiveThreadLightDump.getThreadDump())); - return tActiveThreadLightDump; - } - - private TThreadLightDump buildTThreadLightDump(PThreadLightDump pThreadDump) { - TThreadLightDump tThreadLightDump = new TThreadLightDump(); - tThreadLightDump.setThreadId(pThreadDump.getThreadId()); - tThreadLightDump.setThreadName(pThreadDump.getThreadName()); - tThreadLightDump.setThreadState(TThreadState.findByValue(pThreadDump.getThreadStateValue())); - return tThreadLightDump; - } - -} +/* + * Copyright 2019 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.thrift.sender.message; + +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.grpc.trace.PActiveThreadDump; +import com.navercorp.pinpoint.grpc.trace.PActiveThreadLightDump; +import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadCountRes; +import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDumpRes; +import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDumpRes; +import com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse; +import com.navercorp.pinpoint.grpc.trace.PMonitorInfo; +import com.navercorp.pinpoint.grpc.trace.PThreadDump; +import com.navercorp.pinpoint.grpc.trace.PThreadLightDump; +import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; +import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadLightDump; +import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes; +import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDumpRes; +import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDumpRes; +import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; +import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo; +import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; +import com.navercorp.pinpoint.thrift.dto.command.TThreadLightDump; +import com.navercorp.pinpoint.thrift.dto.command.TThreadState; +import org.apache.thrift.TBase; + +import java.util.List; + +/** + * @author Taejin Koo + */ +public class CommandGrpcToThriftMessageConverter implements MessageConverter> { + + @Override + public TBase toMessage(Object message) { + if (message instanceof PCmdEchoResponse) { + return buildTCommandEcho((PCmdEchoResponse) message); + } else if (message instanceof PCmdActiveThreadCountRes) { + return buildTCmdActiveThreadCountRes((PCmdActiveThreadCountRes) message); + } else if (message instanceof PCmdActiveThreadDumpRes) { + return buildTCmdActiveThreadDumpRes((PCmdActiveThreadDumpRes) message); + } else if (message instanceof PCmdActiveThreadLightDumpRes) { + return buildTCmdActiveThreadLightDumpRes((PCmdActiveThreadLightDumpRes) message); + } + return null; + } + + private TCommandEcho buildTCommandEcho(PCmdEchoResponse echoMessage) { + String message = echoMessage.getMessage(); + return new TCommandEcho(message); + } + + private TCmdActiveThreadCountRes buildTCmdActiveThreadCountRes(PCmdActiveThreadCountRes activeThreadCountRes) { + int histogramSchemaType = activeThreadCountRes.getHistogramSchemaType(); + List activeThreadCountList = activeThreadCountRes.getActiveThreadCountList(); + long timeStamp = activeThreadCountRes.getTimeStamp(); + + TCmdActiveThreadCountRes result = new TCmdActiveThreadCountRes(histogramSchemaType, activeThreadCountList); + result.setTimeStamp(timeStamp); + + return result; + } + + private TCmdActiveThreadDumpRes buildTCmdActiveThreadDumpRes(PCmdActiveThreadDumpRes pCmdActiveThreadDumpRes) { + TCmdActiveThreadDumpRes tCmdActiveThreadDumpRes = new TCmdActiveThreadDumpRes(); + tCmdActiveThreadDumpRes.setVersion(pCmdActiveThreadDumpRes.getVersion()); + tCmdActiveThreadDumpRes.setType(pCmdActiveThreadDumpRes.getType()); + tCmdActiveThreadDumpRes.setSubType(pCmdActiveThreadDumpRes.getSubType()); + + for (PActiveThreadDump pActiveThreadDump : pCmdActiveThreadDumpRes.getThreadDumpList()) { + tCmdActiveThreadDumpRes.addToThreadDumps(buildTActiveThreadDump(pActiveThreadDump)); + } + + return tCmdActiveThreadDumpRes; + } + + private TActiveThreadDump buildTActiveThreadDump(PActiveThreadDump pActiveThreadDump) { + TActiveThreadDump tActiveThreadDump = new TActiveThreadDump(); + tActiveThreadDump.setStartTime(pActiveThreadDump.getStartTime()); + tActiveThreadDump.setSampled(pActiveThreadDump.getSampled()); + + if (pActiveThreadDump.getSampled()) { + tActiveThreadDump.setLocalTraceId(pActiveThreadDump.getLocalTraceId()); + tActiveThreadDump.setTransactionId(pActiveThreadDump.getTransactionId()); + tActiveThreadDump.setEntryPoint(pActiveThreadDump.getEntryPoint()); + } + + tActiveThreadDump.setThreadDump(buildTThreadDump(pActiveThreadDump.getThreadDump())); + return tActiveThreadDump; + } + + private TThreadDump buildTThreadDump(PThreadDump pThreadDump) { + TThreadDump tThreadDump = new TThreadDump(); + tThreadDump.setThreadName(pThreadDump.getThreadName()); + tThreadDump.setThreadId(pThreadDump.getThreadId()); + tThreadDump.setBlockedTime(pThreadDump.getBlockedTime()); + tThreadDump.setBlockedCount(pThreadDump.getBlockedCount()); + tThreadDump.setWaitedTime(pThreadDump.getWaitedTime()); + tThreadDump.setWaitedCount(pThreadDump.getWaitedCount()); + + tThreadDump.setInNative(pThreadDump.getInNative()); + tThreadDump.setSuspended(pThreadDump.getSuspended()); + tThreadDump.setThreadState(TThreadState.findByValue(pThreadDump.getThreadStateValue())); + + for (String stackTrace : pThreadDump.getStackTraceList()) { + tThreadDump.addToStackTrace(stackTrace); + } + + for (PMonitorInfo pMonitorInfo : pThreadDump.getLockedMonitorList()) { + final TMonitorInfo tMonitorInfo = new TMonitorInfo(); + tMonitorInfo.setStackDepth(pMonitorInfo.getStackDepth()); + tMonitorInfo.setStackFrame(pMonitorInfo.getStackFrame()); + tThreadDump.addToLockedMonitors(tMonitorInfo); + } + + + tThreadDump.setLockName(pThreadDump.getLockName()); + tThreadDump.setLockOwnerId(pThreadDump.getLockOwnerId()); + tThreadDump.setLockOwnerName(pThreadDump.getLockOwnerName()); + for (String lockedSynchronizer : pThreadDump.getLockedSynchronizerList()) { + tThreadDump.addToLockedSynchronizers(lockedSynchronizer); + } + + return tThreadDump; + } + + private TCmdActiveThreadLightDumpRes buildTCmdActiveThreadLightDumpRes(PCmdActiveThreadLightDumpRes pCmdActiveThreadLightDumpRes) { + TCmdActiveThreadLightDumpRes tCmdActiveThreadLightDumpRes = new TCmdActiveThreadLightDumpRes(); + tCmdActiveThreadLightDumpRes.setVersion(pCmdActiveThreadLightDumpRes.getVersion()); + tCmdActiveThreadLightDumpRes.setType(pCmdActiveThreadLightDumpRes.getType()); + tCmdActiveThreadLightDumpRes.setSubType(pCmdActiveThreadLightDumpRes.getSubType()); + + for (PActiveThreadLightDump pActiveThreadLightDump : pCmdActiveThreadLightDumpRes.getThreadDumpList()) { + tCmdActiveThreadLightDumpRes.addToThreadDumps(buildTActiveThreadLightDump(pActiveThreadLightDump)); + } + + return tCmdActiveThreadLightDumpRes; + } + + private TActiveThreadLightDump buildTActiveThreadLightDump(PActiveThreadLightDump pActiveThreadLightDump) { + TActiveThreadLightDump tActiveThreadLightDump = new TActiveThreadLightDump(); + tActiveThreadLightDump.setStartTime(pActiveThreadLightDump.getStartTime()); + tActiveThreadLightDump.setSampled(pActiveThreadLightDump.getSampled()); + + if (pActiveThreadLightDump.getSampled()) { + tActiveThreadLightDump.setLocalTraceId(pActiveThreadLightDump.getLocalTraceId()); + tActiveThreadLightDump.setTransactionId(pActiveThreadLightDump.getTransactionId()); + tActiveThreadLightDump.setEntryPoint(pActiveThreadLightDump.getEntryPoint()); + } + + tActiveThreadLightDump.setThreadDump(buildTThreadLightDump(pActiveThreadLightDump.getThreadDump())); + return tActiveThreadLightDump; + } + + private TThreadLightDump buildTThreadLightDump(PThreadLightDump pThreadDump) { + TThreadLightDump tThreadLightDump = new TThreadLightDump(); + tThreadLightDump.setThreadId(pThreadDump.getThreadId()); + tThreadLightDump.setThreadName(pThreadDump.getThreadName()); + tThreadLightDump.setThreadState(TThreadState.findByValue(pThreadDump.getThreadStateValue())); + return tThreadLightDump; + } + +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThreadDumpThriftMessageConverter.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/ThreadDumpThriftMessageConverter.java similarity index 96% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThreadDumpThriftMessageConverter.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/ThreadDumpThriftMessageConverter.java index 8e60cd606f60..2b07c4e159d6 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThreadDumpThriftMessageConverter.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/ThreadDumpThriftMessageConverter.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.context.thrift; +package com.navercorp.pinpoint.thrift.sender.message; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.ThreadDumpMetricSnapshot; import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThreadStateThriftMessageConverter.java b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/ThreadStateThriftMessageConverter.java similarity index 93% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThreadStateThriftMessageConverter.java rename to profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/ThreadStateThriftMessageConverter.java index 1513d8941f35..bad60fabfb31 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThreadStateThriftMessageConverter.java +++ b/profiler-thrift-datasender/src/main/java/com/navercorp/pinpoint/thrift/sender/message/ThreadStateThriftMessageConverter.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.context.thrift; +package com.navercorp.pinpoint.thrift.sender.message; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.thrift.dto.command.TThreadState; /** diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RefreshStrategyTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RefreshStrategyTest.java similarity index 98% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RefreshStrategyTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RefreshStrategyTest.java index b38f2ed67ad2..b8df33ce7a6f 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RefreshStrategyTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RefreshStrategyTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.rpc.client.SocketAddressProvider; import org.junit.jupiter.api.BeforeEach; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RetryMessageTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RetryMessageTest.java similarity index 98% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RetryMessageTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RetryMessageTest.java index 6f21e87965cf..85172b113dd7 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RetryMessageTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RetryMessageTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RetryQueueTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RetryQueueTest.java similarity index 98% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RetryQueueTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RetryQueueTest.java index 43db5dcd00d8..aa3174e31961 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/RetryQueueTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/RetryQueueTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/TcpDataSenderReconnectTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/TcpDataSenderReconnectTest.java similarity index 96% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/TcpDataSenderReconnectTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/TcpDataSenderReconnectTest.java index 9bad8649581d..07b3a721c82e 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/TcpDataSenderReconnectTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/TcpDataSenderReconnectTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; @@ -78,7 +78,7 @@ private PinpointClientFactory createPinpointClientFactory() { PinpointClientFactory clientFactory = new DefaultPinpointClientFactory(); clientFactory.setWriteTimeoutMillis(1000 * 3); clientFactory.setRequestTimeoutMillis(1000 * 5); - clientFactory.setProperties(Collections.emptyMap()); + clientFactory.setProperties(Collections.emptyMap()); return clientFactory; } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/TcpDataSenderTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/TcpDataSenderTest.java similarity index 98% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/TcpDataSenderTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/TcpDataSenderTest.java index 04e6d9424947..42afc6b7e472 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/TcpDataSenderTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/TcpDataSenderTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/UdpDataSenderTest.java similarity index 87% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/UdpDataSenderTest.java index c24652c5985f..6de8adf7b911 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/UdpDataSenderTest.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; +import com.navercorp.pinpoint.common.profiler.message.BypassMessageConverter; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.profiler.context.thrift.BypassMessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.logging.Log4j2LoggerBinderInitializer; import com.navercorp.pinpoint.testcase.util.SocketUtils; import com.navercorp.pinpoint.thrift.dto.TAgentInfo; @@ -26,6 +26,8 @@ import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; import com.navercorp.pinpoint.thrift.io.SerializerFactory; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.thrift.TBase; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -35,12 +37,15 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiPredicate; /** * @author emeroad */ public class UdpDataSenderTest { + + private final Logger logger = LogManager.getLogger(this.getClass()); + private static final String APP_NAME = "appName"; private static final String AGENT_ID = "agentid"; private static final int AGENT_START_TIME = 0; @@ -48,6 +53,8 @@ public class UdpDataSenderTest { private final int PORT = SocketUtils.findAvailableUdpPort(9009); + private final BiPredicate> maxBytesLengthPredicate = new MaxBytesLengthPredicate<>(logger, ThriftUdpMessageSerializer.UDP_MAX_PACKET_LENGTH); + @BeforeAll public static void before() { Log4j2LoggerBinderInitializer.beforeClass(); @@ -127,16 +134,16 @@ private boolean sendMessage_getLimit(TBase tbase, long waitTimeMillis) thr SerializerFactory serializerFactory = new HeaderTBaseSerializerFactory( ThriftUdpMessageSerializer.UDP_MAX_PACKET_LENGTH, HeaderTBaseSerializerFactory.DEFAULT_TBASE_LOCATOR); - final MessageSerializer serializer = new ThriftUdpMessageSerializer(messageConverter, serializerFactory.createSerializer()) { - @Override - protected boolean isLimit(int interBufferSize) { - final boolean limit = super.isLimit(interBufferSize); - limitCounter.set(limit); - latch.countDown(); - return limit; - } + + BiPredicate> filter = (bytes, tBase) -> { + boolean limit = !maxBytesLengthPredicate.test(bytes, tBase); + limitCounter.set(limit); + latch.countDown(); + return limit; }; + final MessageSerializer serializer = new ThriftUdpMessageSerializer(messageConverter, serializerFactory.createSerializer(), filter); + UdpDataSender sender = new UdpDataSender<>("localhost", PORT, "test", 128, 1000, 1024 * 64 * 100, serializer); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/UdpSocketTest.java similarity index 99% rename from profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java rename to profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/UdpSocketTest.java index ed567ab4db00..d9f095fe519e 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java +++ b/profiler-thrift-datasender/src/test/java/com/navercorp/pinpoint/thrift/sender/UdpSocketTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.sender; +package com.navercorp.pinpoint.thrift.sender; import com.navercorp.pinpoint.common.util.IOUtils; import com.navercorp.pinpoint.testcase.util.SocketUtils; diff --git a/profiler-thrift-datasender/src/test/resources/log4j2-test.xml b/profiler-thrift-datasender/src/test/resources/log4j2-test.xml new file mode 100644 index 000000000000..b31290b79e85 --- /dev/null +++ b/profiler-thrift-datasender/src/test/resources/log4j2-test.xml @@ -0,0 +1,23 @@ + + + + %d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan}:%3L -- %msg{nolookups}%n + %d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.}:%3L -- %msg{nolookups}%n + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/profiler/pom.xml b/profiler/pom.xml index 66e0f71141d3..aa12f47820cd 100644 --- a/profiler/pom.xml +++ b/profiler/pom.xml @@ -50,17 +50,7 @@ com.navercorp.pinpoint pinpoint-commons-profiler - - com.navercorp.pinpoint - pinpoint-thrift - - - org.apache.thrift - libthrift - - - - + com.navercorp.pinpoint pinpoint-grpc @@ -72,10 +62,6 @@ com.navercorp.pinpoint pinpoint-bootstrap - - com.navercorp.pinpoint - pinpoint-rpc - com.navercorp.pinpoint pinpoint-plugins-loader @@ -105,17 +91,9 @@ commons-lang3 test - - com.navercorp.pinpoint - pinpoint-rpc - ${project.version} - test-jar - test - com.navercorp.pinpoint pinpoint-testcase - ${project.version} test @@ -153,25 +131,6 @@ asm-analysis - - org.apache.thrift - libthrift - - - httpclient - org.apache.httpcomponents - - - httpcore - org.apache.httpcomponents - - - org.apache.commons - commons-lang3 - - - - diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java index 064335e27408..a826a129a618 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java @@ -16,13 +16,13 @@ package com.navercorp.pinpoint.profiler; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.ResultResponse; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.metadata.AgentInfo; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; import com.navercorp.pinpoint.profiler.util.AgentInfoFactory; -import com.navercorp.pinpoint.rpc.ResponseMessage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -49,7 +49,7 @@ public class AgentInfoSender { private final Logger logger = LogManager.getLogger(this.getClass()); - private final EnhancedDataSender dataSender; + private final EnhancedDataSender dataSender; private final AgentInfoFactory agentInfoFactory; private final long refreshIntervalMs; private final long sendIntervalMs; @@ -207,14 +207,14 @@ private void logError(Throwable cause) { } public static class Builder { - private final EnhancedDataSender dataSender; + private final EnhancedDataSender dataSender; private final AgentInfoFactory agentInfoFactory; private long refreshIntervalMs = DEFAULT_AGENT_INFO_REFRESH_INTERVAL_MS; private long sendIntervalMs = DEFAULT_AGENT_INFO_SEND_INTERVAL_MS; private int maxTryPerAttempt = DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT; private MessageConverter messageConverter; - public Builder(EnhancedDataSender dataSender, AgentInfoFactory agentInfoFactory) { + public Builder(EnhancedDataSender dataSender, AgentInfoFactory agentInfoFactory) { this.dataSender = Objects.requireNonNull(dataSender, "dataSender"); this.agentInfoFactory = Objects.requireNonNull(agentInfoFactory, "agentInfoFactory"); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java index 63e34b4c631e..d81676395eb5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java @@ -23,10 +23,6 @@ import com.navercorp.pinpoint.bootstrap.config.Profiles; import com.navercorp.pinpoint.bootstrap.plugin.util.SocketAddressUtils; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Objects; import com.navercorp.pinpoint.profiler.context.module.ApplicationContext; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.DefaultModuleFactoryResolver; @@ -36,11 +32,13 @@ import com.navercorp.pinpoint.profiler.logging.Log4j2LoggingSystem; import com.navercorp.pinpoint.profiler.logging.LoggingSystem; import com.navercorp.pinpoint.profiler.util.SystemPropertyDumper; -import com.navercorp.pinpoint.rpc.ClassPreLoader; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Map; +import java.util.Objects; import java.util.Properties; @@ -81,10 +79,6 @@ public DefaultAgent(AgentOption agentOption) { changeStatus(AgentStatus.INITIALIZING); - if (Boolean.valueOf(System.getProperty("pinpoint.profiler.ClassPreLoader", "false"))) { - // Preload classes related to pinpoint-rpc module. - ClassPreLoader.preload(); - } preloadOnStartup(); this.applicationContext = newApplicationContext(agentOption); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/TraceDataFormatVersion.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/TraceDataFormatVersion.java index 0f28e5740101..90acb3573f23 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/TraceDataFormatVersion.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/TraceDataFormatVersion.java @@ -26,6 +26,7 @@ public enum TraceDataFormatVersion { V1(SpanVersion.TRACE_V1), V2(SpanVersion.TRACE_V2); + @Deprecated public static final String THRIFT_TRACE_VERSION_KEY = "profiler.transport.thrift.trace.dataformat.version"; public static final String GRPC_TRACE_VERSION_KEY = "profiler.transport.grpc.trace.dataformat.version"; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BooleanAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BooleanAnnotation.java index f8c716d51220..bdd034a00fd6 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BooleanAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BooleanAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class BooleanAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final boolean value; @@ -55,11 +52,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.boolValue(this.value); - } - @Override public String toString() { return "BooleanAnnotation{" + diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ByteAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ByteAnnotation.java index c51e09e7bec0..57c13f843908 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ByteAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ByteAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class ByteAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final byte value; @@ -54,11 +51,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.byteValue(this.value); - } - @Override public String toString() { return "ByteAnnotation{" + diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BytesAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BytesAnnotation.java index 23feb1357391..06882add7dea 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BytesAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/BytesAnnotation.java @@ -21,9 +21,6 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; import java.util.Objects; @@ -31,7 +28,7 @@ * @author emeroad */ public class BytesAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final byte[] value; @@ -57,11 +54,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.binaryValue(this.value); - } - @Override public String toString() { return "BytesAnnotation{" + diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DataTypeAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DataTypeAnnotation.java index 46f411c9c0c2..bcf5e58e377c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DataTypeAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DataTypeAnnotation.java @@ -31,20 +31,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; -import com.navercorp.pinpoint.thrift.dto.TIntBooleanIntBooleanValue; -import com.navercorp.pinpoint.thrift.dto.TIntStringStringValue; -import com.navercorp.pinpoint.thrift.dto.TIntStringValue; -import com.navercorp.pinpoint.thrift.dto.TLongIntIntByteByteStringValue; -import com.navercorp.pinpoint.thrift.dto.TStringStringValue; /** * @author emeroad */ public class DataTypeAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final DataType value; @@ -99,57 +91,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { throw new UnsupportedOperationException("unsupported type:" + dataType); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - final DataType dataType = this.value; - if (dataType instanceof IntStringValue) { - final IntStringValue v = (IntStringValue) dataType; - final TIntStringValue tIntStringValue = new TIntStringValue(v.getIntValue()); - if (v.getStringValue() != null) { - tIntStringValue.setStringValue(v.getStringValue()); - } - return TAnnotationValue.intStringValue(tIntStringValue); - } else if (dataType instanceof StringStringValue) { - final StringStringValue v = (StringStringValue) dataType; - final TStringStringValue tStringStringValue = new TStringStringValue(v.getStringValue1()); - if (v.getStringValue2() != null) { - tStringStringValue.setStringValue2(v.getStringValue2()); - } - return TAnnotationValue.stringStringValue(tStringStringValue); - } else if (dataType instanceof IntStringStringValue) { - final IntStringStringValue v = (IntStringStringValue) dataType; - final TIntStringStringValue tIntStringStringValue = new TIntStringStringValue(v.getIntValue()); - if (v.getStringValue1() != null) { - tIntStringStringValue.setStringValue1(v.getStringValue1()); - } - if (v.getStringValue2() != null) { - tIntStringStringValue.setStringValue2(v.getStringValue2()); - } - return TAnnotationValue.intStringStringValue(tIntStringStringValue); - } else if (dataType instanceof LongIntIntByteByteStringValue) { - final LongIntIntByteByteStringValue v = (LongIntIntByteByteStringValue) dataType; - final TLongIntIntByteByteStringValue tvalue = new TLongIntIntByteByteStringValue(v.getLongValue(), v.getIntValue1()); - if (v.getIntValue2() != -1) { - tvalue.setIntValue2(v.getIntValue2()); - } - if (v.getByteValue1() != -1) { - tvalue.setByteValue1(v.getByteValue1()); - } - if (v.getByteValue2() != -1) { - tvalue.setByteValue2(v.getByteValue2()); - } - if (v.getStringValue() != null) { - tvalue.setStringValue(v.getStringValue()); - } - return TAnnotationValue.longIntIntByteByteStringValue(tvalue); - } else if (dataType instanceof IntBooleanIntBooleanValue) { - final IntBooleanIntBooleanValue v = (IntBooleanIntBooleanValue) dataType; - final TIntBooleanIntBooleanValue tvalue = new TIntBooleanIntBooleanValue(v.getIntValue1(), v.isBooleanValue1(), v.getIntValue2(), v.isBooleanValue2()); - return TAnnotationValue.intBooleanIntBooleanValue(tvalue); - } - throw new UnsupportedOperationException("unsupported type:" + dataType); - } - @Override public String toString() { return "DataTypeAnnotation{" + diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DoubleAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DoubleAnnotation.java index fe658bab633b..f52df8a5e7c3 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DoubleAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/DoubleAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class DoubleAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final double value; @@ -54,10 +51,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.doubleValue(this.value); - } @Override public String toString() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/IntAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/IntAnnotation.java index 49684bc7c3ac..20a6bff6b479 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/IntAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/IntAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class IntAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final int value; @@ -55,10 +52,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.intValue(this.value); - } @Override public String toString() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/LongAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/LongAnnotation.java index 498cdde8ecd2..bccc3200d58c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/LongAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/LongAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class LongAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final long value; @@ -55,10 +52,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.longValue(this.value); - } @Override public String toString() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/NullAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/NullAnnotation.java index 151c16573cb4..a8e2f1ab6ad1 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/NullAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/NullAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class NullAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; @@ -52,10 +49,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return null; } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return null; - } @Override public String toString() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ObjectAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ObjectAnnotation.java index a37c591b2a61..3b4ba198a0d0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ObjectAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ObjectAnnotation.java @@ -21,15 +21,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class ObjectAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final String value; @@ -61,10 +58,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.stringValue(this.value); - } @Override public String toString() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ShortAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ShortAnnotation.java index ded798f385a4..ea8874446a3c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ShortAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/ShortAnnotation.java @@ -20,15 +20,12 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; /** * @author emeroad */ public class ShortAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final short value; @@ -55,10 +52,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.shortValue(this.value); - } @Override public String toString() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/StringAnnotation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/StringAnnotation.java index 47aa27911e70..385b6b0aa63e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/StringAnnotation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/annotation/StringAnnotation.java @@ -20,9 +20,6 @@ import com.navercorp.pinpoint.profiler.context.Annotation; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationSerializable; import com.navercorp.pinpoint.profiler.context.grpc.GrpcAnnotationValueMapper; -import com.navercorp.pinpoint.profiler.context.thrift.AnnotationValueThriftMapper; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftAnnotationSerializable; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; import java.util.Objects; @@ -30,7 +27,7 @@ * @author emeroad */ public class StringAnnotation implements Annotation, - GrpcAnnotationSerializable, ThriftAnnotationSerializable { + GrpcAnnotationSerializable { private final int key; private final String value; @@ -58,11 +55,6 @@ public PAnnotationValue apply(GrpcAnnotationValueMapper context) { return builder.build(); } - @Override - public TAnnotationValue apply(AnnotationValueThriftMapper context) { - return TAnnotationValue.stringValue(this.value); - } - @Override public String toString() { return "StringAnnotation{" + diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/compress/SpanProcessorV1.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/compress/SpanProcessorV1.java deleted file mode 100644 index 4d0beb57dca6..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/compress/SpanProcessorV1.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.compress; - -import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import com.navercorp.pinpoint.common.util.CollectionUtils; -import com.navercorp.pinpoint.profiler.context.Span; -import com.navercorp.pinpoint.profiler.context.SpanChunk; -import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.profiler.context.TraceDataFormatVersion; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import com.navercorp.pinpoint.thrift.dto.TSpanEvent; - -import java.util.Collections; -import java.util.List; -import java.util.RandomAccess; - -/** - * @author Woonduk Kang(emeroad) - */ -public class SpanProcessorV1 implements SpanProcessor { - - private static final byte V1 = TraceDataFormatVersion.V1.getVersion(); - - @Override - public void preProcess(Span span, TSpan tSpan) { - if (tSpan.getVersion() != V1) { - tSpan.setVersion(V1); - } - } - - @Override - public void preProcess(SpanChunk spanChunk, TSpanChunk tSpanChunk) { - if (tSpanChunk.getVersion() != V1) { - tSpanChunk.setVersion(V1); - } - } - - @Override - public void postProcess(Span span, TSpan tSpan) { - final TraceRoot traceRoot = span.getTraceRoot(); - final long keyTime = traceRoot.getTraceStartTime(); - - List spanEventList = span.getSpanEventList(); - if (spanEventList == null) { - spanEventList = Collections.emptyList(); - } - - List tSpanEventList = tSpan.getSpanEventList(); - if (tSpanEventList == null) { - tSpanEventList = Collections.emptyList(); - } - - postEventProcess(spanEventList, tSpanEventList, keyTime); - } - - @Override - public void postProcess(SpanChunk spanChunk, TSpanChunk tSpanChunk) { - final TraceRoot traceRoot = spanChunk.getTraceRoot(); - final long keyTime = traceRoot.getTraceStartTime(); - - final List spanEventList = spanChunk.getSpanEventList(); - if (CollectionUtils.isEmpty(spanEventList)) { - throw new IllegalStateException("SpanChunk.spanEventList is empty"); - } - final List tSpanEventList = tSpanChunk.getSpanEventList(); - if (CollectionUtils.isEmpty(tSpanEventList)) { - throw new IllegalStateException("TSpanChunk.spanEventList is empty"); - } - postEventProcess(spanEventList, tSpanEventList, keyTime); - } - - @VisibleForTesting - public void postEventProcess(List spanEventList, List tSpanEventList, long keyTime) { - if (CollectionUtils.isEmpty(spanEventList)) { - return; - } - if (!(CollectionUtils.nullSafeSize(spanEventList) == CollectionUtils.nullSafeSize(tSpanEventList))) { - throw new IllegalStateException("list size not same, spanEventList=" + CollectionUtils.nullSafeSize(spanEventList) + ", tSpanEventList=" + CollectionUtils.nullSafeSize(tSpanEventList)); - } - // check list type - assert spanEventList instanceof RandomAccess; - - final int listSize = spanEventList.size(); - for (int i = 0; i < listSize; i++) { - final SpanEvent spanEvent = spanEventList.get(i); - final TSpanEvent tSpanEvent = tSpanEventList.get(i); - - final long startTime = spanEvent.getStartTime(); - final long startElapsedTime = startTime - keyTime; - tSpanEvent.setStartElapsed((int) startElapsedTime); - } - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcAgentInfoMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcAgentInfoMessageConverter.java index 412b9fd5164f..bd2680703d4b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcAgentInfoMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcAgentInfoMessageConverter.java @@ -20,6 +20,7 @@ import com.navercorp.pinpoint.bootstrap.context.ServerMetaData; import com.navercorp.pinpoint.bootstrap.context.ServiceInfo; import com.navercorp.pinpoint.common.Version; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PAgentInfo; import com.navercorp.pinpoint.grpc.trace.PJvmGcType; import com.navercorp.pinpoint.grpc.trace.PJvmInfo; @@ -27,7 +28,6 @@ import com.navercorp.pinpoint.grpc.trace.PServiceInfo; import com.navercorp.pinpoint.profiler.AgentInformation; import com.navercorp.pinpoint.profiler.JvmInformation; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.AgentInfo; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcCustomMetricMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcCustomMetricMessageConverter.java index 9491ac5fed30..7f5edb4d4c50 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcCustomMetricMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcCustomMetricMessageConverter.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PCustomMetric; import com.navercorp.pinpoint.grpc.trace.PCustomMetricMessage; import com.navercorp.pinpoint.grpc.trace.PDoubleValue; @@ -26,7 +27,6 @@ import com.navercorp.pinpoint.grpc.trace.PLongCountMetric; import com.navercorp.pinpoint.grpc.trace.PLongGaugeMetric; import com.navercorp.pinpoint.grpc.trace.PLongValue; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.AgentCustomMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.AgentCustomMetricSnapshotBatch; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcJvmGcTypeMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcJvmGcTypeMessageConverter.java index 41fb5a42897b..106566c98d5e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcJvmGcTypeMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcJvmGcTypeMessageConverter.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PJvmGcType; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.gc.JvmGcType; /** diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverter.java index b91138c89ca6..9f82e45f102d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverter.java @@ -17,10 +17,10 @@ package com.navercorp.pinpoint.profiler.context.grpc; import com.google.protobuf.InvalidProtocolBufferException; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.ResultResponse; import com.navercorp.pinpoint.grpc.trace.PResult; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; /** * @author jaehong.kim diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverterProvider.java index a43034df7f5f..f284fde5ac05 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverterProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMessageToResultConverterProvider.java @@ -18,8 +18,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.ResultResponse; /** * @author jaehong.kim diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverter.java index 34f74053c2c2..c03383b5328a 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverter.java @@ -17,10 +17,10 @@ package com.navercorp.pinpoint.profiler.context.grpc; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PApiMetaData; import com.navercorp.pinpoint.grpc.trace.PSqlMetaData; import com.navercorp.pinpoint.grpc.trace.PStringMetaData; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.ApiMetaData; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.metadata.SqlMetaData; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverterProvider.java index e57234fbcf7b..297fb359372c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverterProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcMetadataMessageConverterProvider.java @@ -19,7 +19,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import java.util.Arrays; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java index e49911d49c77..53e05b86515c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.common.util.IntStringValue; import com.navercorp.pinpoint.common.util.StringUtils; @@ -48,7 +49,6 @@ import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; import com.navercorp.pinpoint.profiler.context.id.Shared; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java index 3d2ebeafe488..290042d7c54d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.context.grpc; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; @@ -24,7 +25,6 @@ import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; import com.navercorp.pinpoint.profiler.context.module.AgentId; import com.navercorp.pinpoint.profiler.context.module.ApplicationServerType; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import javax.inject.Inject; import javax.inject.Provider; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverter.java index b7eaf90d1d45..b3960b305b4b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverter.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PActiveTrace; import com.navercorp.pinpoint.grpc.trace.PActiveTraceHistogram; import com.navercorp.pinpoint.grpc.trace.PAgentStat; @@ -38,7 +40,6 @@ import com.navercorp.pinpoint.grpc.trace.PTransaction; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogram; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogramUtils; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.AgentCustomMetricSnapshotBatch; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshotBatch; @@ -58,8 +59,6 @@ import com.navercorp.pinpoint.profiler.monitor.metric.transaction.TransactionMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; -import com.google.protobuf.GeneratedMessageV3; - import java.util.List; /** diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverterProvider.java index e211d69aa127..5c023f854a20 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverterProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcStatMessageConverterProvider.java @@ -19,7 +19,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; /** diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadDumpMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadDumpMessageConverter.java index a8d79914da1a..3b69c7a8d1b8 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadDumpMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadDumpMessageConverter.java @@ -16,10 +16,10 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PMonitorInfo; import com.navercorp.pinpoint.grpc.trace.PThreadDump; import com.navercorp.pinpoint.grpc.trace.PThreadState; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.ThreadDumpMetricSnapshot; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadStateMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadStateMessageConverter.java index 87b6209f056f..9b9ea5b45498 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadStateMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcThreadStateMessageConverter.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PThreadState; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; /** * @author jaehong.kim diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java index 6496c141ebdc..0bd3a40ad08a 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java @@ -16,11 +16,11 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.trace.UriStatHistogramBucket; import com.navercorp.pinpoint.grpc.trace.PAgentUriStat; import com.navercorp.pinpoint.grpc.trace.PEachUriStat; import com.navercorp.pinpoint.grpc.trace.PUriHistogram; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; import com.navercorp.pinpoint.profiler.monitor.metric.uri.EachUriStatData; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/MessageConverterGroup.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/MessageConverterGroup.java index e37596422d23..3179cf0fc9b2 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/MessageConverterGroup.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/MessageConverterGroup.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.profiler.context.grpc; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import java.util.List; import java.util.Objects; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java index 8b9c0bd9de9e..1f349fe684cc 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java @@ -22,8 +22,8 @@ import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.TransportModule; import com.navercorp.pinpoint.profiler.context.module.config.ConfigModule; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * @author Woonduk Kang(emeroad) @@ -50,11 +50,7 @@ protected Module newRpcModule(AgentOption agentOption) { logger.info("load GrpcModule"); return new GrpcModule(profilerConfig); } - if (TransportModule.THRIFT == transportModule) { - logger.info("load ThriftModule"); - return new ThriftModule(profilerConfig); - } - logger.info("load ThriftModule"); - return new ThriftModule(profilerConfig); + logger.info("load GrpcModule"); + return new GrpcModule(profilerConfig); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java index 5102657347d0..e4a0b99f4a7b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java @@ -29,6 +29,7 @@ import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger; import com.navercorp.pinpoint.bootstrap.module.ClassFileTransformModuleAdaptor; import com.navercorp.pinpoint.bootstrap.module.JavaModuleFactory; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.common.util.JvmUtils; import com.navercorp.pinpoint.common.util.JvmVersion; import com.navercorp.pinpoint.profiler.AgentInfoSender; @@ -45,9 +46,8 @@ import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder; import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor; import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModule.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModule.java index 8ccb516ff4d6..989cd2198162 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModule.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModule.java @@ -23,9 +23,14 @@ import com.google.inject.name.Names; import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.ResultResponse; import com.navercorp.pinpoint.grpc.client.HeaderFactory; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; import com.navercorp.pinpoint.profiler.context.grpc.GrpcMessageToResultConverterProvider; @@ -44,12 +49,8 @@ import com.navercorp.pinpoint.profiler.context.provider.grpc.SSLContextProvider; import com.navercorp.pinpoint.profiler.context.provider.grpc.SpanGrpcDataSenderProvider; import com.navercorp.pinpoint.profiler.context.provider.grpc.StatGrpcDataSenderProvider; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; import com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor; import com.navercorp.pinpoint.profiler.sender.grpc.SubconnectionExpiringLoadBalancerProvider; import com.navercorp.pinpoint.profiler.sender.grpc.metric.ChannelzScheduledReporter; @@ -130,12 +131,12 @@ private void bindAgentDataSender() { bind(resultMessageConverterKey).toProvider(GrpcMessageToResultConverterProvider.class ).in(Scopes.SINGLETON); expose(resultMessageConverterKey); - TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() {}; - Key> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class); + TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() {}; + Key> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class); bind(agentDataSender).toProvider(AgentGrpcDataSenderProvider.class).in(Scopes.SINGLETON); expose(agentDataSender); - Key> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class); + Key> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class); bind(metadataDataSender).toProvider(MetadataGrpcDataSenderProvider.class).in(Scopes.SINGLETON); expose(metadataDataSender); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModuleLifeCycle.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModuleLifeCycle.java index 713235b5eb7d..bd100aed0a62 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModuleLifeCycle.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/GrpcModuleLifeCycle.java @@ -20,12 +20,13 @@ import com.google.inject.Provider; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; import com.navercorp.pinpoint.grpc.ExecutorUtils; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import com.navercorp.pinpoint.profiler.sender.grpc.metric.ChannelzScheduledReporter; import java.util.Objects; @@ -39,16 +40,16 @@ public class GrpcModuleLifeCycle implements ModuleLifeCycle { private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); - private final Provider> agentDataSenderProvider; - private final Provider> metadataDataSenderProvider; + private final Provider> agentDataSenderProvider; + private final Provider> metadataDataSenderProvider; private final Provider> spanDataSenderProvider; private final Provider> statDataSenderProvider; private final Provider dnsExecutorServiceProvider; private final Provider reconnectScheduledExecutorProvider; - private EnhancedDataSender agentDataSender; - private EnhancedDataSender metadataDataSender; + private EnhancedDataSender agentDataSender; + private EnhancedDataSender metadataDataSender; private DataSender spanDataSender; private DataSender statDataSender; @@ -60,8 +61,8 @@ public class GrpcModuleLifeCycle implements ModuleLifeCycle { @Inject public GrpcModuleLifeCycle( - @AgentDataSender Provider> agentDataSenderProvider, - @MetadataDataSender Provider> metadataDataSenderProvider, + @AgentDataSender Provider> agentDataSenderProvider, + @MetadataDataSender Provider> metadataDataSenderProvider, @SpanDataSender Provider> spanDataSenderProvider, @StatDataSender Provider> statDataSenderProvider, Provider dnsExecutorServiceProvider, diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModule.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModule.java deleted file mode 100644 index b0c13d480ce5..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModule.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.module; - -import com.google.inject.Key; -import com.google.inject.PrivateModule; -import com.google.inject.Scopes; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; -import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; -import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; -import com.navercorp.pinpoint.profiler.context.id.TransactionIdEncoder; -import com.navercorp.pinpoint.profiler.context.provider.CommandDispatcherProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.ConnectionFactoryProviderProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.HeaderTBaseSerializerProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.MetadataMessageConverterProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.PinpointClientFactoryProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.SpanClientFactoryProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.SpanDataSenderProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.SpanProcessorProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.SpanStatChannelFactoryProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.SpanStatConnectTimerProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.StatClientFactoryProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.StatDataSenderProvider; -import com.navercorp.pinpoint.profiler.context.provider.thrift.TcpDataSenderProvider; -import com.navercorp.pinpoint.profiler.context.thrift.DefaultTransactionIdEncoder; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.SpanThriftMessageConverterProvider; -import com.navercorp.pinpoint.profiler.context.thrift.StatThriftMessageConverterProvider; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftMessageToResultConverterProvider; -import com.navercorp.pinpoint.profiler.context.thrift.config.DefaultThriftTransportConfig; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; -import com.navercorp.pinpoint.rpc.client.ConnectionFactoryProvider; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; -import org.apache.thrift.TBase; -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.util.Timer; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.util.Objects; - -/** - * @author Woonduk Kang(emeroad) - */ -public class ThriftModule extends PrivateModule { - private final Logger logger = LogManager.getLogger(this.getClass()); - - private final ProfilerConfig profilerConfig; - - public ThriftModule(ProfilerConfig profilerConfig) { - this.profilerConfig = Objects.requireNonNull(profilerConfig, "profilerConfig"); - } - - @Override - protected void configure() { - logger.info("configure {}", this.getClass().getSimpleName()); - - ThriftTransportConfig thriftTransportConfig = loadThriftTransportConfig(); - bind(ThriftTransportConfig.class).toInstance(thriftTransportConfig); - - bind(TransactionIdEncoder.class).to(DefaultTransactionIdEncoder.class).in(Scopes.SINGLETON); - - Key commandDispatcher = Key.get(CommandDispatcher.class); - bind(commandDispatcher).toProvider(CommandDispatcherProvider.class).in(Scopes.SINGLETON); -// expose(commandDispatcher); - - TypeLiteral> spanPostProcessorType = new TypeLiteral>() { - }; - bind(spanPostProcessorType).toProvider(SpanProcessorProvider.class).in(Scopes.SINGLETON); - - bind(ConnectionFactoryProvider.class).toProvider(ConnectionFactoryProviderProvider.class).in(Scopes.SINGLETON); - - Key pinpointClientFactory = Key.get(PinpointClientFactory.class, DefaultClientFactory.class); - bind(pinpointClientFactory).toProvider(PinpointClientFactoryProvider.class).in(Scopes.SINGLETON); -// expose(pinpointClientFactory); - - bind(HeaderTBaseSerializer.class).toProvider(HeaderTBaseSerializerProvider.class).in(Scopes.SINGLETON); - // EnhancedDataSender - TypeLiteral> dataSenderTypeLiteral = new TypeLiteral>() {}; - bind(dataSenderTypeLiteral).toProvider(TcpDataSenderProvider.class).in(Scopes.SINGLETON); - expose(dataSenderTypeLiteral); - // Bind AgentDataSender to EnhancedDataSender - Key> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class); - bind(agentDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON); - expose(agentDataSender); - // Bind MetadataDataSender to EnhancedDataSender - Key> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class); - bind(metadataDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON); - expose(metadataDataSender); - - Key spanStatConnectTimer = Key.get(Timer.class, SpanStatChannelFactory.class); - bind(spanStatConnectTimer).toProvider(SpanStatConnectTimerProvider.class).in(Scopes.SINGLETON); - - Key spanStatChannelFactory = Key.get(ChannelFactory.class, SpanStatChannelFactory.class); - bind(spanStatChannelFactory).toProvider(SpanStatChannelFactoryProvider.class).in(Scopes.SINGLETON); - - Key spanClientFactory = Key.get(PinpointClientFactory.class, SpanDataSender.class); - bind(spanClientFactory).toProvider(SpanClientFactoryProvider.class).in(Scopes.SINGLETON); - - Key statClientFactory = Key.get(PinpointClientFactory.class, StatDataSender.class); - bind(statClientFactory).toProvider(StatClientFactoryProvider.class).in(Scopes.SINGLETON); - - TypeLiteral>> thriftMessageConverter = new TypeLiteral>>() {}; - Key>> spanMessageConverterKey = Key.get(thriftMessageConverter, SpanDataSender.class); - bind(spanMessageConverterKey).toProvider(SpanThriftMessageConverterProvider.class).in(Scopes.SINGLETON); -// expose(spanMessageConverterKey); - - TypeLiteral>> metadataMessageConverter = new TypeLiteral>>() {}; - Key>> metadataMessageConverterKey = Key.get(metadataMessageConverter, MetadataDataSender.class); - bind(metadataMessageConverterKey).toProvider(MetadataMessageConverterProvider.class).in(Scopes.SINGLETON); -// expose(metadataMessageConverterKey); - - - // Stat Thrift Converter - TypeLiteral>> statMessageConverter = new TypeLiteral>>() {}; - Key>> statMessageConverterKey = Key.get(statMessageConverter, StatDataSender.class); - bind(statMessageConverterKey).toProvider(StatThriftMessageConverterProvider.class).in(Scopes.SINGLETON); - - TypeLiteral> spanDataSenderType = new TypeLiteral>() {}; - Key> spanDataSender = Key.get(spanDataSenderType, SpanDataSender.class); - bind(spanDataSender).toProvider(SpanDataSenderProvider.class).in(Scopes.SINGLETON); - expose(spanDataSender); - - TypeLiteral> statDataSenderType = new TypeLiteral>() {}; - Key> statDataSender = Key.get(statDataSenderType, StatDataSender.class); - bind(statDataSender).toProvider(StatDataSenderProvider.class).in(Scopes.SINGLETON); - expose(statDataSender); - - // For AgentInfoSender -// TypeLiteral agentInfoFactoryTypeLiteral = new TypeLiteral() {}; -// bind(agentInfoFactoryTypeLiteral).toProvider(AgentInfoFactoryProvider.class).in(Scopes.SINGLETON); -// expose(agentInfoFactoryTypeLiteral); - - TypeLiteral> resultMessageConverter = new TypeLiteral>() {}; - Key> resultMessageConverterKey = Key.get(resultMessageConverter, ResultConverter.class); - bind(resultMessageConverterKey).toProvider(ThriftMessageToResultConverterProvider.class).in(Scopes.SINGLETON); - expose(resultMessageConverterKey); - - Key rpcModuleLifeCycleKey = Key.get(ModuleLifeCycle.class, Names.named("RPC-MODULE")); - bind(rpcModuleLifeCycleKey).to(ThriftModuleLifeCycle.class).in(Scopes.SINGLETON); - expose(rpcModuleLifeCycleKey); - } - - public ThriftTransportConfig loadThriftTransportConfig() { - DefaultThriftTransportConfig thriftTransportConfig = new DefaultThriftTransportConfig(); - thriftTransportConfig.read(profilerConfig.getProperties()); - logger.info("{}", thriftTransportConfig); - return thriftTransportConfig; - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModuleLifeCycle.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModuleLifeCycle.java deleted file mode 100644 index 36a9f75e7f93..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftModuleLifeCycle.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.module; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.bootstrap.logging.PLogger; -import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; -import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.util.Timeout; -import org.jboss.netty.util.Timer; - -import java.util.Objects; -import java.util.Set; - -/** - * @author Woonduk Kang(emeroad) - */ -public class ThriftModuleLifeCycle implements ModuleLifeCycle { - - private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); - - private final Provider commandDispatcherProvider; - private final Provider clientFactoryProvider; - private final Provider> tcpDataSenderProvider; - - private final Provider spanStatConnectTimerProvider; - private final Provider spanStatChannelFactoryProvider; - - private final Provider spanClientFactoryProvider; - private final Provider statClientFactoryProvider; - - private final Provider> spanDataSenderProvider; - private final Provider> statDataSenderProvider; - - private CommandDispatcher commandDispatcher; - - private PinpointClientFactory clientFactory; - private EnhancedDataSender tcpDataSender; - - private Timer spanStatConnectTimer; - private ChannelFactory spanStatChannelFactory; - - private PinpointClientFactory spanClientFactory; - private PinpointClientFactory statClientFactory; - - private DataSender spanDataSender; - private DataSender statDataSender; - - @Inject - public ThriftModuleLifeCycle( - Provider commandDispatcherProvider, - @DefaultClientFactory Provider clientFactoryProvider, - @AgentDataSender Provider> tcpDataSenderProvider, - @SpanStatChannelFactory Provider spanStatConnectTimerProvider, - @SpanStatChannelFactory Provider spanStatChannelFactoryProvider, - @SpanDataSender Provider spanClientFactoryProvider, - @StatDataSender Provider statClientFactoryProvider, - @SpanDataSender Provider> spanDataSenderProvider, - @StatDataSender Provider> statDataSenderProvider - ) { - this.commandDispatcherProvider = Objects.requireNonNull(commandDispatcherProvider, "commandDispatcherProvider"); - this.clientFactoryProvider = Objects.requireNonNull(clientFactoryProvider, "clientFactoryProvider"); - this.tcpDataSenderProvider = Objects.requireNonNull(tcpDataSenderProvider, "tcpDataSenderProvider"); - - this.spanStatConnectTimerProvider = Objects.requireNonNull(spanStatConnectTimerProvider, "spanStatConnectTimerProvider"); - - this.spanStatChannelFactoryProvider = Objects.requireNonNull(spanStatChannelFactoryProvider, "spanStatChannelFactoryProvider"); - - this.spanClientFactoryProvider = Objects.requireNonNull(spanClientFactoryProvider, "spanClientFactoryProvider"); - this.statClientFactoryProvider = Objects.requireNonNull(statClientFactoryProvider, "statClientFactoryProvider"); - - this.spanDataSenderProvider = Objects.requireNonNull(spanDataSenderProvider, "spanDataSenderProvider"); - this.statDataSenderProvider = Objects.requireNonNull(statDataSenderProvider, "statDataSenderProvider"); - } - - @Override - public void start() { - logger.info("start()"); - this.commandDispatcher = this.commandDispatcherProvider.get(); - logger.info("commandDispatcher:{}", commandDispatcher); - - this.clientFactory = clientFactoryProvider.get(); - logger.info("pinpointClientFactory:{}", clientFactory); - - this.tcpDataSender = tcpDataSenderProvider.get(); - logger.info("tcpDataSenderProvider:{}", tcpDataSender); - - this.spanStatConnectTimer = spanStatConnectTimerProvider.get(); - logger.info("spanStatConnectTimer:{}", spanStatConnectTimer); - - this.spanStatChannelFactory = spanStatChannelFactoryProvider.get(); - logger.info("spanStatChannelFactory:{}", spanStatChannelFactory); - - this.spanClientFactory = spanClientFactoryProvider.get(); - logger.info("spanClientFactory:{}", spanClientFactory); - - this.statClientFactory = statClientFactoryProvider.get(); - logger.info("statClientFactory:{}", statClientFactory); - - this.spanDataSender = spanDataSenderProvider.get(); - logger.info("spanDataSenderProvider:{}", spanDataSender); - - this.statDataSender = this.statDataSenderProvider.get(); - logger.info("statDataSenderProvider:{}", statDataSender); - } - - @Override - public void shutdown() { - logger.info("shutdown()"); - if (spanDataSender != null) { - this.spanDataSender.stop(); - } - if (statDataSender != null) { - this.statDataSender.stop(); - } - - if (spanClientFactory != null) { - this.spanClientFactory.release(); - } - if (statClientFactory!= null) { - this.statClientFactory.release(); - } - - if (spanStatChannelFactory != null) { - spanStatChannelFactory.releaseExternalResources(); - } - - if (spanStatConnectTimer != null) { - Set stop = spanStatConnectTimer.stop(); - if (!stop.isEmpty()) { - logger.info("stop Timeout:{}", stop.size()); - } - } - - if (tcpDataSender != null) { - this.tcpDataSender.stop(); - } - if (clientFactory != null) { - clientFactory.release(); - } - - if (commandDispatcher != null) { - this.commandDispatcher.close(); - } - } - - @Override - public String toString() { - return "ThriftModuleLifeCycle{" + - "commandDispatcherProvider=" + commandDispatcherProvider + - ", clientFactoryProvider=" + clientFactoryProvider + - ", tcpDataSenderProvider=" + tcpDataSenderProvider + - ", spanStatConnectTimerProvider=" + spanStatConnectTimerProvider + - ", spanStatChannelFactoryProvider=" + spanStatChannelFactoryProvider + - ", spanClientFactoryProvider=" + spanClientFactoryProvider + - ", statClientFactoryProvider=" + statClientFactoryProvider + - ", spanDataSenderProvider=" + spanDataSenderProvider + - ", statDataSenderProvider=" + statDataSenderProvider + - '}'; - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftStatsModule.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftStatsModule.java index 32cc5e402624..12b3b81b0c89 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftStatsModule.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ThriftStatsModule.java @@ -16,6 +16,10 @@ package com.navercorp.pinpoint.profiler.context.module; +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogram; import com.navercorp.pinpoint.profiler.context.provider.stat.activethread.ActiveTraceMetricCollectorProvider; import com.navercorp.pinpoint.profiler.context.provider.stat.buffer.BufferMetricCollectorProvider; @@ -41,75 +45,70 @@ import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeValue; import com.navercorp.pinpoint.profiler.monitor.metric.totalthread.TotalThreadMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.transaction.TransactionMetricSnapshot; - -import com.google.inject.AbstractModule; -import com.google.inject.Scopes; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * @author Woonduk Kang(emeroad) */ -public class ThriftStatsModule extends AbstractModule { - private final Logger logger = LogManager.getLogger(this.getClass()); +public class ThriftStatsModule extends AbstractModule{ + private final Logger logger=LogManager.getLogger(this.getClass()); @Override - protected void configure() { - logger.info("configure {}", this.getClass().getSimpleName()); + protected void configure(){ + logger.info("configure {}",this.getClass().getSimpleName()); binder().requireExplicitBindings(); binder().requireAtInjectOnConstructors(); binder().disableCircularProxies(); // gc - TypeLiteral> jvmGcCollector = new TypeLiteral>() {}; + TypeLiteral>jvmGcCollector=new TypeLiteral>(){}; bind(jvmGcCollector).toProvider(JvmGcMetricCollectorProvider.class).in(Scopes.SINGLETON); // cpu - TypeLiteral> cpuLoadCollector = new TypeLiteral>() {}; + TypeLiteral>cpuLoadCollector=new TypeLiteral>(){}; bind(cpuLoadCollector).toProvider(CpuLoadMetricCollectorProvider.class).in(Scopes.SINGLETON); // FD - TypeLiteral> fdCollector = new TypeLiteral>() {}; + TypeLiteral>fdCollector=new TypeLiteral>(){}; bind(fdCollector).toProvider(FileDescriptorMetricCollectorProvider.class).in(Scopes.SINGLETON); // buffer - TypeLiteral> bufferCollector = new TypeLiteral>() {}; + TypeLiteral>bufferCollector=new TypeLiteral>(){}; bind(bufferCollector).toProvider(BufferMetricCollectorProvider.class).in(Scopes.SINGLETON); // transaction - TypeLiteral> transactionCollector = new TypeLiteral>() {}; + TypeLiteral>transactionCollector=new TypeLiteral>(){}; bind(transactionCollector).toProvider(TransactionMetricCollectorProvider.class).in(Scopes.SINGLETON); // activeTrace - TypeLiteral> activeTraceCollector = new TypeLiteral>() {}; + TypeLiteral>activeTraceCollector=new TypeLiteral>(){}; bind(activeTraceCollector).toProvider(ActiveTraceMetricCollectorProvider.class).in(Scopes.SINGLETON); // responseTime - TypeLiteral> responseTimeCollector = new TypeLiteral>() {}; + TypeLiteral>responseTimeCollector=new TypeLiteral>(){}; bind(responseTimeCollector).toProvider(ResponseTimeMetricCollectorProvider.class).in(Scopes.SINGLETON); // datasource - TypeLiteral> datasourceCollector = new TypeLiteral>() {}; + TypeLiteral>datasourceCollector=new TypeLiteral>(){}; bind(datasourceCollector).toProvider(DataSourceMetricCollectorProvider.class).in(Scopes.SINGLETON); // deadlock - TypeLiteral> deadlockCollector = new TypeLiteral>() {}; + TypeLiteral>deadlockCollector=new TypeLiteral>(){}; bind(deadlockCollector).toProvider(DeadlockMetricCollectorProvider.class).in(Scopes.SINGLETON); // totalThread - TypeLiteral> totalThreadCountCollector = new TypeLiteral>() {}; + TypeLiteral>totalThreadCountCollector=new TypeLiteral>(){}; bind(totalThreadCountCollector).toProvider(TotalThreadMetricCollectorProvider.class).in(Scopes.SINGLETON); // loadedClass - TypeLiteral> loadedClassCollector = new TypeLiteral>() {}; + TypeLiteral>loadedClassCollector=new TypeLiteral>(){}; bind(loadedClassCollector).toProvider(LoadedClassMetricCollectorProvider.class).in(Scopes.SINGLETON); // stat - TypeLiteral> statMetric = new TypeLiteral>() {}; + TypeLiteral>statMetric=new TypeLiteral>(){}; bind(statMetric).annotatedWith(Names.named("AgentStatCollector")) - .to(AgentStatCollector.class).in(Scopes.SINGLETON); + .to(AgentStatCollector.class).in(Scopes.SINGLETON); } } \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInfoSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInfoSenderProvider.java index f255ac4535da..523b25949815 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInfoSenderProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInfoSenderProvider.java @@ -18,15 +18,16 @@ import com.google.inject.Inject; import com.google.inject.Provider; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; +import com.navercorp.pinpoint.common.profiler.message.ResultResponse; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.AgentInfoSender; import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService; import com.navercorp.pinpoint.profiler.context.config.ContextConfig; import com.navercorp.pinpoint.profiler.context.module.AgentDataSender; import com.navercorp.pinpoint.profiler.context.module.ResultConverter; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; import com.navercorp.pinpoint.profiler.util.AgentInfoFactory; import java.util.Objects; @@ -38,7 +39,7 @@ public class AgentInfoSenderProvider implements Provider { private final ContextConfig contextConfig; - private final Provider> enhancedDataSenderProvider; + private final Provider> enhancedDataSenderProvider; private final Provider agentInfoFactoryProvider; private final ServerMetaDataRegistryService serverMetaDataRegistryService; private final MessageConverter messageConverter; @@ -46,7 +47,7 @@ public class AgentInfoSenderProvider implements Provider { @Inject public AgentInfoSenderProvider( ContextConfig contextConfig, - @AgentDataSender Provider> enhancedDataSenderProvider, + @AgentDataSender Provider> enhancedDataSenderProvider, Provider agentInfoFactoryProvider, ServerMetaDataRegistryService serverMetaDataRegistryService, @ResultConverter MessageConverter messageConverter) { @@ -59,7 +60,7 @@ public AgentInfoSenderProvider( @Override public AgentInfoSender get() { - final EnhancedDataSender enhancedDataSender = this.enhancedDataSenderProvider.get(); + final EnhancedDataSender enhancedDataSender = this.enhancedDataSenderProvider.get(); final AgentInfoFactory agentInfoFactory = this.agentInfoFactoryProvider.get(); final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(enhancedDataSender, agentInfoFactory) .sendInterval(contextConfig.getAgentInfoSendRetryInterval()) diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/CommandDispatcherProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/CommandDispatcherProvider.java deleted file mode 100644 index c0d061c5b437..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/CommandDispatcherProvider.java +++ /dev/null @@ -1,58 +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. - */ - -package com.navercorp.pinpoint.profiler.context.provider; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import java.util.Objects; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher; -import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandLocatorBuilder; -import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator; -import com.navercorp.pinpoint.profiler.receiver.service.ActiveThreadService; -import com.navercorp.pinpoint.profiler.receiver.service.EchoService; - -/** - * @author Woonduk Kang(emeroad) - */ -public class CommandDispatcherProvider implements Provider { - - private final ThriftTransportConfig thriftTransportConfig; - private final ActiveTraceRepository activeTraceRepository; - - @Inject - public CommandDispatcherProvider(ThriftTransportConfig thriftTransportConfig, Provider activeTraceRepositoryProvider) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - Objects.requireNonNull(activeTraceRepositoryProvider, "activeTraceRepositoryProvider"); - this.activeTraceRepository = activeTraceRepositoryProvider.get(); - } - - @Override - public CommandDispatcher get() { - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(new EchoService()); - if (activeTraceRepository != null) { - ActiveThreadService activeThreadService = new ActiveThreadService(thriftTransportConfig, activeTraceRepository); - builder.addService(activeThreadService); - } - - ProfilerCommandServiceLocator commandServiceLocator = builder.build(); - CommandDispatcher commandDispatcher = new CommandDispatcher(commandServiceLocator); - return commandDispatcher; - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/StorageFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/StorageFactoryProvider.java index d4c3fa57f265..d9f8bc646686 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/StorageFactoryProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/StorageFactoryProvider.java @@ -18,6 +18,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.config.ContextConfig; import com.navercorp.pinpoint.profiler.context.module.SpanDataSender; @@ -25,9 +26,8 @@ import com.navercorp.pinpoint.profiler.context.storage.StorageFactory; import com.navercorp.pinpoint.profiler.context.storage.TraceLogDelegateStorage; import com.navercorp.pinpoint.profiler.context.storage.TraceLogDelegateStorageFactory; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Objects; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/TraceDataFormatVersionProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/TraceDataFormatVersionProvider.java index 185ae3a3104f..65ee6b158097 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/TraceDataFormatVersionProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/TraceDataFormatVersionProvider.java @@ -21,8 +21,8 @@ import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.TransportModule; import com.navercorp.pinpoint.profiler.context.TraceDataFormatVersion; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * @author Woonduk Kang(emeroad) @@ -40,15 +40,6 @@ public TraceDataFormatVersionProvider(ProfilerConfig profilerConfig) { private TraceDataFormatVersion getVersion(ProfilerConfig profilerConfig) { final TransportModule transportModule = profilerConfig.getTransportModule(); logger.info("TransportModule:{}", transportModule); - if (TransportModule.THRIFT == transportModule) { - final String version = profilerConfig.readString(TraceDataFormatVersion.THRIFT_TRACE_VERSION_KEY, "v1"); - if ("v1".equalsIgnoreCase(version)) { - return TraceDataFormatVersion.V1; - } - throw new UnsupportedOperationException("unknown " + TraceDataFormatVersion.THRIFT_TRACE_VERSION_KEY + ":" + version); - } - - if (TransportModule.GRPC == transportModule) { final String version = profilerConfig.readString(TraceDataFormatVersion.GRPC_TRACE_VERSION_KEY, "v2"); if ("v2".equalsIgnoreCase(version)) { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentGrpcDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentGrpcDataSenderProvider.java index a20fe80c5f03..7c6386618dd0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentGrpcDataSenderProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentGrpcDataSenderProvider.java @@ -19,17 +19,19 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.HeaderFactory; import com.navercorp.pinpoint.grpc.client.UnaryCallDeadlineInterceptor; import com.navercorp.pinpoint.grpc.client.config.ClientOption; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; import com.navercorp.pinpoint.profiler.context.grpc.config.GrpcTransportConfig; import com.navercorp.pinpoint.profiler.context.module.AgentDataSender; import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandLocatorBuilder; import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator; @@ -37,7 +39,6 @@ import com.navercorp.pinpoint.profiler.receiver.grpc.GrpcActiveThreadDumpService; import com.navercorp.pinpoint.profiler.receiver.grpc.GrpcActiveThreadLightDumpService; import com.navercorp.pinpoint.profiler.receiver.grpc.GrpcEchoService; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import com.navercorp.pinpoint.profiler.sender.grpc.AgentGrpcDataSender; import com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor; import io.grpc.ClientInterceptor; @@ -54,7 +55,7 @@ /** * @author jaehong.kim */ -public class AgentGrpcDataSenderProvider implements Provider> { +public class AgentGrpcDataSenderProvider implements Provider> { private final Logger logger = LogManager.getLogger(this.getClass()); @@ -100,7 +101,7 @@ public void setClientInterceptor(@AgentDataSender List client } @Override - public EnhancedDataSender get() { + public EnhancedDataSender get() { final String collectorIp = grpcTransportConfig.getAgentCollectorIp(); final int collectorPort = grpcTransportConfig.getAgentCollectorPort(); final boolean sslEnable = grpcTransportConfig.isAgentSslEnable(); @@ -118,7 +119,7 @@ public EnhancedDataSender get() { channelFactory, reconnectExecutor, retransmissionExecutor, profilerCommandServiceLocator); } - protected EnhancedDataSender newAgentGrpcDataSender(String collectorIp, int collectorPort, int senderExecutorQueueSize, + protected EnhancedDataSender newAgentGrpcDataSender(String collectorIp, int collectorPort, int senderExecutorQueueSize, MessageConverter messageConverter, ChannelFactory channelFactory, ReconnectExecutor reconnectExecutor, ScheduledExecutorService retransmissionExecutor, diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/MetadataGrpcDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/MetadataGrpcDataSenderProvider.java index 371f69a85a85..11df22b3dc6b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/MetadataGrpcDataSenderProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/MetadataGrpcDataSenderProvider.java @@ -19,17 +19,18 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.HeaderFactory; import com.navercorp.pinpoint.grpc.client.UnaryCallDeadlineInterceptor; import com.navercorp.pinpoint.grpc.client.config.ClientOption; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.grpc.config.GrpcTransportConfig; import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import com.navercorp.pinpoint.profiler.sender.grpc.MetadataGrpcDataSender; import io.grpc.ClientInterceptor; import io.grpc.NameResolverProvider; @@ -43,7 +44,7 @@ /** * @author jaehong.kim */ -public class MetadataGrpcDataSenderProvider implements Provider> { +public class MetadataGrpcDataSenderProvider implements Provider> { private final Logger logger = LogManager.getLogger(this.getClass()); @@ -74,7 +75,7 @@ public void setClientInterceptor(@MetadataDataSender List cli } @Override - public EnhancedDataSender get() { + public EnhancedDataSender get() { final String collectorIp = grpcTransportConfig.getMetadataCollectorIp(); final int collectorPort = grpcTransportConfig.getMetadataCollectorPort(); final boolean sslEnable = grpcTransportConfig.isMetadataSslEnable(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/SpanGrpcDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/SpanGrpcDataSenderProvider.java index db1b0ca74dee..a6efa52311b0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/SpanGrpcDataSenderProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/SpanGrpcDataSenderProvider.java @@ -19,6 +19,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder; @@ -31,8 +33,6 @@ import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.grpc.config.GrpcTransportConfig; import com.navercorp.pinpoint.profiler.context.module.SpanDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.sender.DataSender; import com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor; import com.navercorp.pinpoint.profiler.sender.grpc.SimpleStreamState; import com.navercorp.pinpoint.profiler.sender.grpc.SpanGrpcDataSender; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/StatGrpcDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/StatGrpcDataSenderProvider.java index a164d2ba08fd..49d3ad7cab16 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/StatGrpcDataSenderProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/StatGrpcDataSenderProvider.java @@ -19,6 +19,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder; @@ -27,9 +29,7 @@ import com.navercorp.pinpoint.grpc.client.config.ClientOption; import com.navercorp.pinpoint.profiler.context.grpc.config.GrpcTransportConfig; import com.navercorp.pinpoint.profiler.context.module.StatDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; import com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor; import com.navercorp.pinpoint.profiler.sender.grpc.StatGrpcDataSender; import io.grpc.ClientInterceptor; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/ApiMetaDataServiceProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/ApiMetaDataServiceProvider.java index 6f9b362cdf4d..a13a29e3c264 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/ApiMetaDataServiceProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/ApiMetaDataServiceProvider.java @@ -18,12 +18,13 @@ import com.google.inject.Inject; import com.google.inject.Provider; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; +import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService; import com.navercorp.pinpoint.profiler.metadata.DefaultApiMetaDataService; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import java.util.Objects; @@ -32,11 +33,11 @@ */ public class ApiMetaDataServiceProvider implements Provider { - private final Provider> enhancedDataSenderProvider; + private final Provider> enhancedDataSenderProvider; private final SimpleCacheFactory simpleCacheFactory; @Inject - public ApiMetaDataServiceProvider(@MetadataDataSender Provider> enhancedDataSenderProvider, SimpleCacheFactory simpleCacheFactory) { + public ApiMetaDataServiceProvider(@MetadataDataSender Provider> enhancedDataSenderProvider, SimpleCacheFactory simpleCacheFactory) { this.enhancedDataSenderProvider = Objects.requireNonNull(enhancedDataSenderProvider, "enhancedDataSenderProvider"); this.simpleCacheFactory = Objects.requireNonNull(simpleCacheFactory, "simpleCacheFactory"); @@ -44,7 +45,7 @@ public ApiMetaDataServiceProvider(@MetadataDataSender Provider enhancedDataSender = this.enhancedDataSenderProvider.get(); + final EnhancedDataSender enhancedDataSender = this.enhancedDataSenderProvider.get(); final SimpleCache simpleCache = simpleCacheFactory.newSimpleCache(); return new DefaultApiMetaDataService(enhancedDataSender, simpleCache); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SimpleCacheFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SimpleCacheFactoryProvider.java index 2b3f771e618e..8df92af604a5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SimpleCacheFactoryProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SimpleCacheFactoryProvider.java @@ -30,9 +30,10 @@ public class SimpleCacheFactoryProvider implements Provider @Inject public SimpleCacheFactoryProvider(TransportModule transportModule) { - if (TransportModule.THRIFT == transportModule) { - this.type = IdAllocator.ID_TYPE.ZIGZAG; - } else if (TransportModule.GRPC == transportModule) { +// if (TransportModule.THRIFT == transportModule) { +// this.type = IdAllocator.ID_TYPE.ZIGZAG; +// } + if (TransportModule.GRPC == transportModule) { this.type = IdAllocator.ID_TYPE.BYPASS; } else { throw new IllegalStateException("Unsupported transportModule:" + transportModule); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SqlMetadataServiceProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SqlMetadataServiceProvider.java index e5714e382710..f4fa78224a87 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SqlMetadataServiceProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/SqlMetadataServiceProvider.java @@ -18,12 +18,13 @@ import com.google.inject.Inject; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; +import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; import com.navercorp.pinpoint.profiler.metadata.DefaultSqlMetaDataService; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import javax.inject.Provider; import java.util.Objects; @@ -34,12 +35,12 @@ public class SqlMetadataServiceProvider implements Provider { private final ProfilerConfig profilerConfig; - private final EnhancedDataSender enhancedDataSender; + private final EnhancedDataSender enhancedDataSender; private final SimpleCacheFactory simpleCacheFactory; @Inject public SqlMetadataServiceProvider(ProfilerConfig profilerConfig, - @MetadataDataSender EnhancedDataSender enhancedDataSender, + @MetadataDataSender EnhancedDataSender enhancedDataSender, SimpleCacheFactory simpleCacheFactory) { this.profilerConfig = Objects.requireNonNull(profilerConfig, "profilerConfig"); this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender"); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/StringMetadataServiceProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/StringMetadataServiceProvider.java index 888148c7faef..9b1e73d09728 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/StringMetadataServiceProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/metadata/StringMetadataServiceProvider.java @@ -17,12 +17,13 @@ package com.navercorp.pinpoint.profiler.context.provider.metadata; import com.google.inject.Inject; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; +import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; import com.navercorp.pinpoint.profiler.metadata.DefaultStringMetaDataService; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import javax.inject.Provider; import java.util.Objects; @@ -33,11 +34,11 @@ */ public class StringMetadataServiceProvider implements Provider { - private final EnhancedDataSender enhancedDataSender; + private final EnhancedDataSender enhancedDataSender; private final SimpleCacheFactory simpleCacheFactory; @Inject - public StringMetadataServiceProvider(@MetadataDataSender EnhancedDataSender enhancedDataSender, SimpleCacheFactory simpleCacheFactory) { + public StringMetadataServiceProvider(@MetadataDataSender EnhancedDataSender enhancedDataSender, SimpleCacheFactory simpleCacheFactory) { this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender"); this.simpleCacheFactory = Objects.requireNonNull(simpleCacheFactory, "simpleCacheFactory"); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/AbstractClientFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/AbstractClientFactoryProvider.java deleted file mode 100644 index 275f658262d9..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/AbstractClientFactoryProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.navercorp.pinpoint.common.util.ByteSizeUnit; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -/** - * @author Taejin Koo - */ -public abstract class AbstractClientFactoryProvider { - - protected final Logger logger = LogManager.getLogger(this.getClass()); - - protected int getByteSize(String value, int defaultSize) { - try { - long byteSize = ByteSizeUnit.getByteSize(value); - if (byteSize > Integer.MAX_VALUE) { - logger.warn("must be writeBufferWaterMark({}) range is 0 ~ {}", value, Integer.MAX_VALUE); - byteSize = Integer.MAX_VALUE; - } else if (byteSize <= 0) { - logger.warn("must be writeBufferWaterMark({}) range is 0 ~ {}", value, Integer.MAX_VALUE); - byteSize = defaultSize; - } - return (int) byteSize; - } catch (Exception e) { - logger.warn("Failed to get byteSize({}). byteSize will be defaultSize:{}", value, defaultSize); - } - return defaultSize; - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/ConnectionFactoryProviderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/ConnectionFactoryProviderProvider.java deleted file mode 100644 index 69145efc5c7c..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/ConnectionFactoryProviderProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.rpc.client.ClientCodecPipelineFactory; -import com.navercorp.pinpoint.rpc.client.ConnectionFactoryProvider; -import com.navercorp.pinpoint.rpc.client.DefaultConnectionFactoryProvider; - -/** - * @author Taejin Koo - */ -public class ConnectionFactoryProviderProvider implements Provider { - - @Inject - public ConnectionFactoryProviderProvider() { - } - - @Override - public ConnectionFactoryProvider get() { - return new DefaultConnectionFactoryProvider(new ClientCodecPipelineFactory()); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/HeaderTBaseSerializerProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/HeaderTBaseSerializerProvider.java deleted file mode 100644 index cb9902cab9bc..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/HeaderTBaseSerializerProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; - -/** - * @author Taejin Koo - */ -public class HeaderTBaseSerializerProvider implements Provider { - - private final HeaderTBaseSerializerFactory serializerFactory = new HeaderTBaseSerializerFactory(); - - @Inject - public HeaderTBaseSerializerProvider() { - } - - @Override - public HeaderTBaseSerializer get() { - return serializerFactory.createSerializer(); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/MetadataMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/MetadataMessageConverterProvider.java deleted file mode 100644 index 5e27099f0bdd..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/MetadataMessageConverterProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.module.AgentId; -import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; -import com.navercorp.pinpoint.profiler.context.module.ApplicationName; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.MetadataMessageConverter; -import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import org.apache.thrift.TBase; - -import java.util.Objects; - - -/** - * @author Woonduk Kang(emeroad) - */ -public class MetadataMessageConverterProvider implements Provider>> { - - private final String applicationName; - private final String agentId; - private final long agentStartTime; - - @Inject - public MetadataMessageConverterProvider(@ApplicationName String applicationName, @AgentId String agentId, @AgentStartTime long agentStartTime) { - this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); - this.agentId = Objects.requireNonNull(agentId, "agentId"); - this.agentStartTime = agentStartTime; - } - - - @Override - public MessageConverter> get() { - return new MetadataMessageConverter(applicationName, agentId, agentStartTime); - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/PinpointClientFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/PinpointClientFactoryProvider.java deleted file mode 100644 index 1a59a5817948..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/PinpointClientFactoryProvider.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.common.util.ByteSizeUnit; -import com.navercorp.pinpoint.profiler.AgentInformation; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher; -import com.navercorp.pinpoint.rpc.client.ConnectionFactoryProvider; -import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import com.navercorp.pinpoint.rpc.packet.HandshakePropertyType; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -/** - * @author Woonduk Kang(emeroad) - */ -public class PinpointClientFactoryProvider extends AbstractClientFactoryProvider implements Provider { - - private final ThriftTransportConfig thriftTransportConfig; - private final Provider agentInformation; - private final Provider connectionFactoryProvider; - private final CommandDispatcher commandDispatcher; - - @Inject - public PinpointClientFactoryProvider(ThriftTransportConfig thriftTransportConfig, Provider agentInformation, CommandDispatcher commandDispatcher, Provider connectionFactoryProvider) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - this.agentInformation = Objects.requireNonNull(agentInformation, "agentInformation"); - this.commandDispatcher = Objects.requireNonNull(commandDispatcher, "commandDispatcher"); - this.connectionFactoryProvider = Objects.requireNonNull(connectionFactoryProvider, "connectionFactoryProvider"); - - } - - public PinpointClientFactory get() { - PinpointClientFactory pinpointClientFactory = new DefaultPinpointClientFactory(connectionFactoryProvider.get()); - pinpointClientFactory.setWriteTimeoutMillis(thriftTransportConfig.getTcpDataSenderPinpointClientWriteTimeout()); - pinpointClientFactory.setRequestTimeoutMillis(thriftTransportConfig.getTcpDataSenderPinpointClientRequestTimeout()); - pinpointClientFactory.setReconnectDelay(thriftTransportConfig.getTcpDataSenderPinpointClientReconnectInterval()); - pinpointClientFactory.setPingDelay(thriftTransportConfig.getTcpDataSenderPinpointClientPingInterval()); - pinpointClientFactory.setEnableWorkerPacketDelay(thriftTransportConfig.getTcpDataSenderPinpointClientHandshakeInterval()); - - int writeBufferHighWaterMark = getByteSize(thriftTransportConfig.getTcpDataSenderPinpointClientWriteBufferHighWaterMark(), ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(32)); - int writeBufferLowWaterMark = getByteSize(thriftTransportConfig.getTcpDataSenderPinpointClientWriteBufferLowWaterMark(), ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(16)); - if (writeBufferLowWaterMark > writeBufferHighWaterMark) { - logger.warn("must be writeBufferHighWaterMark({}) >= writeBufferLowWaterMark({})", writeBufferHighWaterMark, writeBufferLowWaterMark); - writeBufferLowWaterMark = writeBufferHighWaterMark; - } - pinpointClientFactory.setWriteBufferHighWaterMark(writeBufferHighWaterMark); - pinpointClientFactory.setWriteBufferLowWaterMark(writeBufferLowWaterMark); - - AgentInformation agentInformation = this.agentInformation.get(); - Map properties = toMap(agentInformation); - - boolean isSupportServerMode = thriftTransportConfig.isTcpDataSenderCommandAcceptEnable(); - - if (isSupportServerMode) { - pinpointClientFactory.setMessageListener(commandDispatcher); - pinpointClientFactory.setServerStreamChannelMessageHandler(commandDispatcher); - - properties.put(HandshakePropertyType.SUPPORT_SERVER.getName(), true); - properties.put(HandshakePropertyType.SUPPORT_COMMAND_LIST.getName(), commandDispatcher.getRegisteredCommandServiceCodes()); - } else { - properties.put(HandshakePropertyType.SUPPORT_SERVER.getName(), false); - } - - pinpointClientFactory.setProperties(properties); - return pinpointClientFactory; - } - - private Map toMap(AgentInformation agentInformation) { - Map map = new HashMap(); - - map.put(HandshakePropertyType.AGENT_ID.getName(), agentInformation.getAgentId()); - map.put(HandshakePropertyType.APPLICATION_NAME.getName(), agentInformation.getApplicationName()); - map.put(HandshakePropertyType.HOSTNAME.getName(), agentInformation.getMachineName()); - map.put(HandshakePropertyType.IP.getName(), agentInformation.getHostIp()); - map.put(HandshakePropertyType.PID.getName(), agentInformation.getPid()); - map.put(HandshakePropertyType.SERVICE_TYPE.getName(), agentInformation.getServerType().getCode()); - map.put(HandshakePropertyType.START_TIMESTAMP.getName(), agentInformation.getStartTime()); - map.put(HandshakePropertyType.VERSION.getName(), agentInformation.getAgentVersion()); - - return map; - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanClientFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanClientFactoryProvider.java deleted file mode 100644 index ddc8c8e28607..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanClientFactoryProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.common.util.ByteSizeUnit; -import com.navercorp.pinpoint.profiler.context.module.SpanStatChannelFactory; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.util.Timer; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class SpanClientFactoryProvider extends AbstractClientFactoryProvider implements Provider { - - private final ThriftTransportConfig thriftTransportConfig; - private final Provider channelFactoryProvider; - private final Provider spanStatConnectTimer; - - @Inject - public SpanClientFactoryProvider(ThriftTransportConfig thriftTransportConfig, - @SpanStatChannelFactory Provider channelFactoryProvider, - @SpanStatChannelFactory Provider spanStatConnectTimer) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - this.channelFactoryProvider = Objects.requireNonNull(channelFactoryProvider, "channelFactoryProvider"); - this.spanStatConnectTimer = Objects.requireNonNull(spanStatConnectTimer, "spanStatConnectTimer"); - } - - public PinpointClientFactory get() { - if (!"TCP".equalsIgnoreCase(thriftTransportConfig.getSpanDataSenderTransportType())) { - return null; - } - - PinpointClientFactory pinpointClientFactory = new DefaultPinpointClientFactory(channelFactoryProvider.get(), spanStatConnectTimer.get()); - pinpointClientFactory.setWriteTimeoutMillis(1000 * 3); - pinpointClientFactory.setRequestTimeoutMillis(1000 * 5); - - int writeBufferHighWaterMark = getByteSize(thriftTransportConfig.getSpanDataSenderWriteBufferHighWaterMark(), ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(16)); - int writeBufferLowWaterMark = getByteSize(thriftTransportConfig.getSpanDataSenderWriteBufferLowWaterMark(), ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(8)); - if (writeBufferLowWaterMark > writeBufferHighWaterMark) { - logger.warn("must be writeBufferHighWaterMark({}) >= writeBufferLowWaterMark({})", writeBufferHighWaterMark, writeBufferLowWaterMark); - writeBufferLowWaterMark = writeBufferHighWaterMark; - } - pinpointClientFactory.setWriteBufferHighWaterMark(writeBufferHighWaterMark); - pinpointClientFactory.setWriteBufferLowWaterMark(writeBufferLowWaterMark); - - return pinpointClientFactory; - } - -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanDataSenderProvider.java deleted file mode 100644 index 691075087799..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanDataSenderProvider.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.context.module.SpanDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.MessageSerializer; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; -import com.navercorp.pinpoint.profiler.sender.ThriftMessageSerializer; -import com.navercorp.pinpoint.profiler.sender.UdpDataSenderFactory; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class SpanDataSenderProvider implements Provider> { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - private static final String UDP_EXECUTOR_NAME = "Pinpoint-UdpSpanDataExecutor"; - - private final Provider clientFactoryProvider; - - private final String ip; - private final int port; - private final int writeQueueSize; - private final int timeout; - private final int sendBufferSize; - private final String ioType; - private final String transportType; - private final MessageConverter> messageConverter; - - @Inject - public SpanDataSenderProvider(ThriftTransportConfig thriftTransportConfig, - @SpanDataSender Provider clientFactoryProvider, - @SpanDataSender MessageConverter> messageConverter) { - Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - this.clientFactoryProvider = Objects.requireNonNull(clientFactoryProvider, "clientFactoryProvider"); - - this.ip = thriftTransportConfig.getCollectorSpanServerIp(); - this.port = thriftTransportConfig.getCollectorSpanServerPort(); - this.writeQueueSize = thriftTransportConfig.getSpanDataSenderWriteQueueSize(); - this.timeout = thriftTransportConfig.getSpanDataSenderSocketTimeout(); - this.sendBufferSize = thriftTransportConfig.getSpanDataSenderSocketSendBufferSize(); - this.ioType = thriftTransportConfig.getSpanDataSenderSocketType(); - this.transportType = thriftTransportConfig.getSpanDataSenderTransportType(); - this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter"); - } - - @Override - public DataSender get() { - if ("TCP".equalsIgnoreCase(transportType)) { - if ("OIO".equalsIgnoreCase(ioType)) { - logger.warn("TCP transport not support OIO type.(only support NIO)"); - } - - PinpointClientFactory pinpointClientFactory = clientFactoryProvider.get(); - MessageSerializer messageSerializer = new ThriftMessageSerializer<>(messageConverter); - return new TcpDataSender<>("SpanDataSender", ip, port, pinpointClientFactory, messageSerializer, writeQueueSize); - } else { - UdpDataSenderFactory factory = new UdpDataSenderFactory<>(ip, port, UDP_EXECUTOR_NAME, writeQueueSize, timeout, sendBufferSize, messageConverter); - return factory.create(ioType); - } - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SpanDataSenderProvider{"); - sb.append("ip='").append(ip).append('\''); - sb.append(", port=").append(port); - sb.append(", writeQueueSize=").append(writeQueueSize); - sb.append(", timeout=").append(timeout); - sb.append(", sendBufferSize=").append(sendBufferSize); - sb.append(", ioType='").append(ioType).append('\''); - sb.append(", transportType='").append(transportType).append('\''); - sb.append('}'); - return sb.toString(); - } - -} - diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanProcessorProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanProcessorProvider.java deleted file mode 100644 index 5ff1f3a5f908..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanProcessorProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.TraceDataFormatVersion; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessorV1; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; - -import java.util.Objects; - -/** - * @author Woonduk Kang(emeroad) - */ -public class SpanProcessorProvider implements Provider> { - - private final TraceDataFormatVersion version; - - @Inject - public SpanProcessorProvider(TraceDataFormatVersion version) { - this.version = Objects.requireNonNull(version, "version"); - } - - @Override - public SpanProcessor get() { - if (version == TraceDataFormatVersion.V1) { - return new SpanProcessorV1(); - } - throw new UnsupportedOperationException("unknown version :" + version); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatChannelFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatChannelFactoryProvider.java deleted file mode 100644 index 8efbdd4227c2..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatChannelFactoryProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.module.SpanStatChannelFactory; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.rpc.client.ClientChannelFactory; -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.util.Timer; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class SpanStatChannelFactoryProvider implements Provider { - - private final ThriftTransportConfig thriftTransportConfig; - private final Provider connectTimerProvider; - - @Inject - public SpanStatChannelFactoryProvider(ThriftTransportConfig thriftTransportConfig, @SpanStatChannelFactory Provider connectTimerProvider) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - this.connectTimerProvider = Objects.requireNonNull(connectTimerProvider, "connectTimerProvider"); - } - - @Override - public ChannelFactory get() { - int workerCount = 0; - - if ("TCP".equalsIgnoreCase(thriftTransportConfig.getSpanDataSenderTransportType())) { - workerCount++; - } - if ("TCP".equalsIgnoreCase(thriftTransportConfig.getStatDataSenderTransportType())) { - workerCount++; - } - - if (workerCount == 0) { - return null; - } else { - Timer timer = connectTimerProvider.get(); - - final ClientChannelFactory clientChannelFactory = new ClientChannelFactory(); - return clientChannelFactory.createChannelFactory(1, workerCount, timer); - } - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatConnectTimerProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatConnectTimerProvider.java deleted file mode 100644 index dd6d5f65039a..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/SpanStatConnectTimerProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.rpc.util.TimerFactory; -import org.jboss.netty.util.HashedWheelTimer; -import org.jboss.netty.util.Timer; - -import java.util.Objects; -import java.util.concurrent.TimeUnit; - -/** - * @author Taejin Koo - */ -public class SpanStatConnectTimerProvider implements Provider { - - private final ThriftTransportConfig thriftTransportConfig; - - @Inject - public SpanStatConnectTimerProvider(ThriftTransportConfig thriftTransportConfig) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - } - - @Override - public Timer get() { - if ("TCP".equalsIgnoreCase(thriftTransportConfig.getSpanDataSenderTransportType()) || "TCP".equalsIgnoreCase(thriftTransportConfig.getStatDataSenderTransportType())) { - return createTimer("Pinpoint-SpanStatConnect-Timer"); - } - return null; - } - - private static Timer createTimer(String timerName) { - HashedWheelTimer timer = TimerFactory.createHashedWheelTimer(timerName, 100, TimeUnit.MILLISECONDS, 512); - timer.start(); - return timer; - } - -} - diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatClientFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatClientFactoryProvider.java deleted file mode 100644 index 49e27128dc4f..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatClientFactoryProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.common.util.ByteSizeUnit; -import com.navercorp.pinpoint.profiler.context.module.SpanStatChannelFactory; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.util.Timer; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class StatClientFactoryProvider extends AbstractClientFactoryProvider implements Provider { - - private final ThriftTransportConfig thriftTransportConfig; - private final Provider channelFactoryProvider; - private final Provider connectTimerProvider; - - @Inject - public StatClientFactoryProvider(ThriftTransportConfig thriftTransportConfig, - @SpanStatChannelFactory Provider channelFactoryProvider, - @SpanStatChannelFactory Provider connectTimerProvider) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - this.channelFactoryProvider = Objects.requireNonNull(channelFactoryProvider, "channelFactoryProvider"); - this.connectTimerProvider = Objects.requireNonNull(connectTimerProvider, "connectTimerProvider"); - } - - public PinpointClientFactory get() { - if (!"TCP".equalsIgnoreCase(thriftTransportConfig.getStatDataSenderTransportType())) { - return null; - } - - PinpointClientFactory pinpointClientFactory = new DefaultPinpointClientFactory(channelFactoryProvider.get(), connectTimerProvider.get()); - pinpointClientFactory.setWriteTimeoutMillis(1000 * 3); - pinpointClientFactory.setRequestTimeoutMillis(1000 * 5); - - int writeBufferHighWaterMark = getByteSize(thriftTransportConfig.getStatDataSenderWriteBufferHighWaterMark(), ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(16)); - int writeBufferLowWaterMark = getByteSize(thriftTransportConfig.getStatDataSenderWriteBufferLowWaterMark(), ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(8)); - if (writeBufferLowWaterMark > writeBufferHighWaterMark) { - logger.warn("must be writeBufferHighWaterMark({}) >= writeBufferLowWaterMark({})", writeBufferHighWaterMark, writeBufferLowWaterMark); - writeBufferLowWaterMark = writeBufferHighWaterMark; - } - pinpointClientFactory.setWriteBufferHighWaterMark(writeBufferHighWaterMark); - pinpointClientFactory.setWriteBufferLowWaterMark(writeBufferLowWaterMark); - - return pinpointClientFactory; - } - -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatDataSenderProvider.java deleted file mode 100644 index 95879f409e07..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/StatDataSenderProvider.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.module.StatDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.MessageSerializer; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; -import com.navercorp.pinpoint.profiler.sender.ThriftMessageSerializer; -import com.navercorp.pinpoint.profiler.sender.UdpDataSenderFactory; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class StatDataSenderProvider implements Provider> { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - private static final String UDP_EXECUTOR_NAME = "Pinpoint-UdpStatDataExecutor"; - - private final Provider clientFactoryProvider; - - private final String ip; - private final int port; - private final int writeQueueSize; - private final int timeout; - private final int sendBufferSize; - private final String ioType; - private final String transportType; - - private final MessageConverter> messageConverter; - - @Inject - public StatDataSenderProvider(ThriftTransportConfig thriftTransportConfig, - @StatDataSender Provider clientFactoryProvider, - @StatDataSender MessageConverter> messageConverter) { - Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - - this.clientFactoryProvider = Objects.requireNonNull(clientFactoryProvider, "clientFactoryProvider"); - - this.ip = thriftTransportConfig.getCollectorStatServerIp(); - this.port = thriftTransportConfig.getCollectorStatServerPort(); - this.writeQueueSize = thriftTransportConfig.getStatDataSenderWriteQueueSize(); - this.timeout = thriftTransportConfig.getStatDataSenderSocketTimeout(); - this.sendBufferSize = thriftTransportConfig.getStatDataSenderSocketSendBufferSize(); - this.ioType = thriftTransportConfig.getStatDataSenderSocketType(); - this.transportType = thriftTransportConfig.getStatDataSenderTransportType(); - this.messageConverter = messageConverter; - } - - @Override - public DataSender get() { - if ("TCP".equalsIgnoreCase(transportType)) { - if ("OIO".equalsIgnoreCase(ioType)) { - logger.warn("TCP transport not support OIO type.(only support NIO)"); - } - - PinpointClientFactory pinpointClientFactory = clientFactoryProvider.get(); - MessageSerializer messageSerializer = new ThriftMessageSerializer<>(messageConverter); - return new TcpDataSender<>("StatDataSender", ip, port, pinpointClientFactory, messageSerializer, writeQueueSize); - } else { - UdpDataSenderFactory factory = new UdpDataSenderFactory<>(ip, port, UDP_EXECUTOR_NAME, writeQueueSize, timeout, sendBufferSize, messageConverter); - return factory.create(ioType); - } - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("StatDataSenderProvider{"); - sb.append("ip='").append(ip).append('\''); - sb.append(", port=").append(port); - sb.append(", writeQueueSize=").append(writeQueueSize); - sb.append(", timeout=").append(timeout); - sb.append(", sendBufferSize=").append(sendBufferSize); - sb.append(", ioType='").append(ioType).append('\''); - sb.append(", transportType='").append(transportType).append('\''); - sb.append('}'); - return sb.toString(); - } - -} - diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/TcpDataSenderProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/TcpDataSenderProvider.java deleted file mode 100644 index 75ec72e9afc1..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/thrift/TcpDataSenderProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.module.DefaultClientFactory; -import com.navercorp.pinpoint.profiler.context.module.MetadataDataSender; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.MessageSerializer; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; -import com.navercorp.pinpoint.profiler.sender.ThriftMessageSerializer; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; -import org.apache.thrift.TBase; - -import java.util.Objects; - -/** - * @author Woonduk Kang(emeroad) - */ -public class TcpDataSenderProvider implements Provider> { - private final ThriftTransportConfig thriftTransportConfig; - private final Provider clientFactoryProvider; - private final Provider tBaseSerializerProvider; - private final MessageConverter> messageConverter; - - @Inject - public TcpDataSenderProvider(ThriftTransportConfig thriftTransportConfig, - @DefaultClientFactory Provider clientFactoryProvider, - Provider tBaseSerializerProvider, - @MetadataDataSender MessageConverter> messageConverter) { - this.thriftTransportConfig = Objects.requireNonNull(thriftTransportConfig, "thriftTransportConfig"); - this.clientFactoryProvider = Objects.requireNonNull(clientFactoryProvider, "clientFactoryProvider"); - this.tBaseSerializerProvider = Objects.requireNonNull(tBaseSerializerProvider, "tBaseSerializerProvider"); - this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter"); - } - - @Override - public EnhancedDataSender get() { - PinpointClientFactory clientFactory = clientFactoryProvider.get(); - - String collectorTcpServerIp = thriftTransportConfig.getCollectorTcpServerIp(); - int collectorTcpServerPort = thriftTransportConfig.getCollectorTcpServerPort(); - HeaderTBaseSerializer headerTBaseSerializer = tBaseSerializerProvider.get(); - MessageSerializer messageSerializer = new ThriftMessageSerializer<>(messageConverter, headerTBaseSerializer); - return new TcpDataSender<>("Default", collectorTcpServerIp, collectorTcpServerPort, clientFactory, messageSerializer); - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java index 1efd3d946bf8..12e27ece65f7 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java @@ -19,13 +19,13 @@ import com.navercorp.pinpoint.bootstrap.plugin.http.URITemplate; import com.navercorp.pinpoint.common.profiler.clock.Clock; import com.navercorp.pinpoint.common.profiler.clock.TickClock; +import com.navercorp.pinpoint.common.profiler.concurrent.executor.AsyncQueueingExecutor; +import com.navercorp.pinpoint.common.profiler.concurrent.executor.MultiConsumer; import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; import com.navercorp.pinpoint.profiler.monitor.metric.uri.UriStatInfo; -import com.navercorp.pinpoint.profiler.sender.AsyncQueueingExecutor; -import com.navercorp.pinpoint.profiler.sender.AsyncQueueingExecutorListener; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -40,19 +40,19 @@ public class AsyncQueueingUriStatStorage extends AsyncQueueingExecutor { + static class UriStatConsumer implements MultiConsumer { private static final int DEFAULT_COLLECT_INTERVAL = 30000; // 30s @@ -94,11 +94,11 @@ static class ExecutorListener implements AsyncQueueingExecutorListener snapshotManager; - public ExecutorListener(int uriStatDataLimitSize) { + public UriStatConsumer(int uriStatDataLimitSize) { this(uriStatDataLimitSize, DEFAULT_COLLECT_INTERVAL); } - public ExecutorListener(int uriStatDataLimitSize, int collectInterval) { + public UriStatConsumer(int uriStatDataLimitSize, int collectInterval) { Assert.isTrue(uriStatDataLimitSize > 0, "uriStatDataLimitSize must be ' > 0'"); Assert.isTrue(collectInterval > 0, "collectInterval must be ' > 0'"); @@ -109,7 +109,7 @@ public ExecutorListener(int uriStatDataLimitSize, int collectInterval) { } @Override - public void execute(Collection messageList) { + public void acceptN(Collection messageList) { final long currentBaseTimestamp = clock.millis(); checkAndFlushOldData(currentBaseTimestamp); @@ -122,7 +122,7 @@ public void execute(Collection messageList) { } @Override - public void execute(UriStatInfo message) { + public void accept(UriStatInfo message) { long currentBaseTimestamp = clock.millis(); checkAndFlushOldData(currentBaseTimestamp); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorage.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorage.java index 06e8f4bc15db..0113f67108c0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorage.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorage.java @@ -16,16 +16,19 @@ package com.navercorp.pinpoint.profiler.context.storage; -import java.util.Objects; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.common.util.CollectionUtils; -import com.navercorp.pinpoint.profiler.context.*; -import com.navercorp.pinpoint.profiler.sender.DataSender; - -import org.apache.logging.log4j.Logger; +import com.navercorp.pinpoint.profiler.context.Span; +import com.navercorp.pinpoint.profiler.context.SpanChunk; +import com.navercorp.pinpoint.profiler.context.SpanChunkFactory; +import com.navercorp.pinpoint.profiler.context.SpanEvent; +import com.navercorp.pinpoint.profiler.context.SpanType; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * @author emeroad diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageFactory.java index 6279a4b9e0a0..0c2afcfc08c0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageFactory.java @@ -16,10 +16,11 @@ package com.navercorp.pinpoint.profiler.context.storage; -import java.util.Objects; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.SpanChunkFactory; import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.sender.DataSender; + +import java.util.Objects; /** * @author emeroad diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/AnnotationValueThriftMapper.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/AnnotationValueThriftMapper.java deleted file mode 100644 index 2138625ce9c6..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/AnnotationValueThriftMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.profiler.context.Annotation; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; - -/** - * @author Woonduk Kang(emeroad) - */ -public class AnnotationValueThriftMapper { - public TAnnotationValue buildTAnnotationValue(Annotation annotation) { - if (annotation == null) { - throw new NullPointerException("annotation"); - } - - if (annotation instanceof ThriftAnnotationSerializable) { - ThriftAnnotationSerializable serializable = (ThriftAnnotationSerializable) annotation; - return serializable.apply(this); - } - throw new UnsupportedOperationException("unsupported annotation:" + annotation); - - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoder.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoder.java deleted file mode 100644 index a3a470b9cc88..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoder.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.google.inject.Inject; -import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; -import com.navercorp.pinpoint.common.buffer.Buffer; -import java.util.Objects; -import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.common.util.StringUtils; -import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; -import com.navercorp.pinpoint.profiler.context.id.TransactionIdEncoder; -import com.navercorp.pinpoint.profiler.context.module.AgentId; -import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; - -import java.nio.ByteBuffer; - -/** - * @author Woonduk Kang(emeroad) - */ -public class DefaultTransactionIdEncoder implements TransactionIdEncoder { - - private static final byte VERSION = TransactionIdUtils.VERSION; - - private final String agentId; - private final long agentStartTime; - - private final byte[] agentIdCache; - private final byte[] agentIdAndStartTimeCache; - - @Inject - public DefaultTransactionIdEncoder(@AgentId String agentId, @AgentStartTime long agentStartTime) { - this.agentId = Objects.requireNonNull(agentId, "agentId"); - this.agentStartTime = agentStartTime; - - this.agentIdCache = newCache(null); - this.agentIdAndStartTimeCache= newCache(null, agentStartTime); - } - - private byte[] newCache(String agentId, long agentStartTime) { - final int agentStartTimeSize = BytesUtils.computeVar64Size(agentStartTime); - final int agentIdSize = StringUtils.getLength(agentId); - final Buffer buffer = new AutomaticBuffer(1 + 5 + agentIdSize + agentStartTimeSize); - buffer.putByte(VERSION); - buffer.putPrefixedString(agentId); - buffer.putVLong(agentStartTime); - return buffer.copyBuffer(); - } - - private byte[] newCache(String agentId) { - final int agentIdSize = StringUtils.getLength(agentId); - final Buffer buffer = new AutomaticBuffer(1 + 5 + agentIdSize); - buffer.putByte(VERSION); - buffer.putPrefixedString(agentId); - return buffer.copyBuffer(); - } - - - private byte[] encode(String agentId, long agentStartTime, long transactionSequence) { - return TransactionIdUtils.formatBytes(agentId, agentStartTime, transactionSequence); - } - - private byte[] encodeAgentIdAndTransactionSequence(byte[] agentIdCache, long agentStartTime, long transactionSequence) { - final int agentStartTimeSize = BytesUtils.computeVar64Size(agentStartTime); - final int transactionSequenceSize = BytesUtils.computeVar64Size(transactionSequence); - final int prefixLength = agentIdCache.length; - final byte[] transactionId = new byte[prefixLength + agentStartTimeSize + transactionSequenceSize]; - // copy prefix - System.arraycopy(agentIdCache, 0, transactionId, 0, prefixLength); - - BytesUtils.writeVar64(agentStartTime, transactionId, prefixLength); - BytesUtils.writeVar64(transactionSequence, transactionId, prefixLength + agentStartTimeSize); - - return transactionId; - } - - private byte[] encodeTransactionSequence(byte[] agentIdAndStartTimeCache, long transactionSequence) { - final int transactionSequenceSize = BytesUtils.computeVar64Size(transactionSequence); - final int prefixLength = agentIdAndStartTimeCache.length; - final byte[] transactionId = new byte[prefixLength + transactionSequenceSize]; - // copy prefix - System.arraycopy(agentIdAndStartTimeCache, 0, transactionId, 0, prefixLength); - - BytesUtils.writeVar64(transactionSequence, transactionId, prefixLength); - - return transactionId; - } - - /** - * skip agentId + agentStartTime - */ - private byte[] encode(long transactionSequence) { - final byte[] encode = encodeTransactionSequence(agentIdAndStartTimeCache, transactionSequence); - return encode; - } - - private byte[] encode(long agentStartTime, long transactionSequence) { - final byte[] encode = encodeAgentIdAndTransactionSequence(agentIdCache, agentStartTime, transactionSequence); - return encode; - } - - private boolean isCompressedType(TraceId traceId) { - // skip agentId - return agentId.equals(traceId.getAgentId()); - } - - @Override - public ByteBuffer encodeTransactionId(TraceId traceId) { - Objects.requireNonNull(traceId, "traceId"); - - return ByteBuffer.wrap(encodeTransaction0(traceId)); - } - - private byte[] encodeTransaction0(TraceId traceId) { - if (isCompressedType(traceId)) { - final long transactionSequence = traceId.getTransactionSequence(); - if (this.agentStartTime == traceId.getAgentStartTime()) { - return this.encode(traceId.getTransactionSequence()); - } - return this.encode(traceId.getAgentStartTime(), transactionSequence); - } - return this.encode(traceId.getAgentId(), traceId.getAgentStartTime(), traceId.getTransactionSequence()); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/JvmGcTypeThriftMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/JvmGcTypeThriftMessageConverter.java deleted file mode 100644 index d4c0a87df2ef..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/JvmGcTypeThriftMessageConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.profiler.monitor.metric.gc.JvmGcType; -import com.navercorp.pinpoint.thrift.dto.TJvmGcType; - -/** - * @author jaehong.kim - */ -public class JvmGcTypeThriftMessageConverter implements MessageConverter { - - @Override - public TJvmGcType toMessage(Object message) { - if (message instanceof JvmGcType) { - final JvmGcType jvmGcType = (JvmGcType) message; - return convertJvmGcType(jvmGcType); - } - throw new IllegalArgumentException("invalid message type. message=" + message); - } - - private TJvmGcType convertJvmGcType(final JvmGcType jvmGcType) { - switch (jvmGcType) { - case UNKNOWN: - return TJvmGcType.UNKNOWN; - case SERIAL: - return TJvmGcType.SERIAL; - case PARALLEL: - return TJvmGcType.PARALLEL; - case CMS: - return TJvmGcType.CMS; - case G1: - return TJvmGcType.G1; - default: - return TJvmGcType.UNKNOWN; - } - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MetadataMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MetadataMessageConverter.java deleted file mode 100644 index 7c3961b13a46..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/MetadataMessageConverter.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2018 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.profiler.context.thrift; - -import com.navercorp.pinpoint.bootstrap.context.ServerMetaData; -import com.navercorp.pinpoint.bootstrap.context.ServiceInfo; -import com.navercorp.pinpoint.common.Version; -import java.util.Objects; - -import com.navercorp.pinpoint.common.util.StringUtils; -import com.navercorp.pinpoint.profiler.AgentInformation; -import com.navercorp.pinpoint.profiler.JvmInformation; -import com.navercorp.pinpoint.profiler.metadata.AgentInfo; -import com.navercorp.pinpoint.profiler.metadata.ApiMetaData; -import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.metadata.SqlMetaData; -import com.navercorp.pinpoint.profiler.metadata.StringMetaData; -import com.navercorp.pinpoint.thrift.dto.TAgentInfo; -import com.navercorp.pinpoint.thrift.dto.TApiMetaData; -import com.navercorp.pinpoint.thrift.dto.TJvmGcType; -import com.navercorp.pinpoint.thrift.dto.TJvmInfo; -import com.navercorp.pinpoint.thrift.dto.TServerMetaData; -import com.navercorp.pinpoint.thrift.dto.TServiceInfo; -import com.navercorp.pinpoint.thrift.dto.TSqlMetaData; -import com.navercorp.pinpoint.thrift.dto.TStringMetaData; -import org.apache.thrift.TBase; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Woonduk Kang(emeroad) - */ -public class MetadataMessageConverter implements MessageConverter> { - - private final String applicationName; - private final String agentId; - private final long agentStartTime; - private final JvmGcTypeThriftMessageConverter jvmGcTypeMessageConverter = new JvmGcTypeThriftMessageConverter(); - - public MetadataMessageConverter(String applicationName, String agentId, long agentStartTime) { - this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); - this.agentId = Objects.requireNonNull(agentId, "agentId"); - this.agentStartTime = agentStartTime; - } - - @Override - public TBase toMessage(MetaDataType message) { - if (message instanceof AgentInfo) { - final AgentInfo agentInfo = (AgentInfo) message; - return convertAgentInfo(agentInfo); - } else if (message instanceof SqlMetaData) { - final SqlMetaData sqlMetaData = (SqlMetaData) message; - return convertSqlMetaData(sqlMetaData); - } else if (message instanceof ApiMetaData) { - final ApiMetaData apiMetaData = (ApiMetaData) message; - return convertApiMetaData(apiMetaData); - } else if (message instanceof StringMetaData) { - final StringMetaData stringMetaData = (StringMetaData) message; - return convertStringMetaData(stringMetaData); - } - return null; - } - - public TAgentInfo convertAgentInfo(final AgentInfo agentInfo) { - final AgentInformation agentInformation = agentInfo.getAgentInformation(); - - final TAgentInfo tAgentInfo = new TAgentInfo(); - tAgentInfo.setIp(agentInformation.getHostIp()); - tAgentInfo.setHostname(agentInformation.getMachineName()); - tAgentInfo.setPorts(""); - tAgentInfo.setAgentId(agentInformation.getAgentId()); - final String agentName = agentInformation.getAgentName(); - if (!StringUtils.isEmpty(agentName)) { - tAgentInfo.setAgentName(agentName); - } - tAgentInfo.setApplicationName(agentInformation.getApplicationName()); - tAgentInfo.setContainer(agentInformation.isContainer()); - tAgentInfo.setPid(agentInformation.getPid()); - tAgentInfo.setStartTimestamp(agentInformation.getStartTime()); - tAgentInfo.setServiceType(agentInformation.getServerType().getCode()); - tAgentInfo.setVmVersion(agentInformation.getJvmVersion()); - tAgentInfo.setAgentVersion(Version.VERSION); - - final TServerMetaData tServerMetaData = convertServerMetaData(agentInfo.getServerMetaData()); - tAgentInfo.setServerMetaData(tServerMetaData); - - final TJvmInfo tJvmInfo = convertJvmInfo(agentInfo.getJvmInfo()); - tAgentInfo.setJvmInfo(tJvmInfo); - return tAgentInfo; - } - - private TServerMetaData convertServerMetaData(final ServerMetaData serverMetaData) { - if (serverMetaData == null) { - return null; - } - - final TServerMetaData tServerMetaData = new TServerMetaData(); - tServerMetaData.setServerInfo(serverMetaData.getServerInfo()); - tServerMetaData.setVmArgs(serverMetaData.getVmArgs()); - List tServiceInfos = new ArrayList<>(); - for (ServiceInfo serviceInfo : serverMetaData.getServiceInfos()) { - TServiceInfo tServiceInfo = new TServiceInfo(); - tServiceInfo.setServiceName(serviceInfo.getServiceName()); - tServiceInfo.setServiceLibs(serviceInfo.getServiceLibs()); - tServiceInfos.add(tServiceInfo); - } - tServerMetaData.setServiceInfos(tServiceInfos); - return tServerMetaData; - } - - private TJvmInfo convertJvmInfo(final JvmInformation jvmInformation) { - final TJvmInfo tJvmInfo = new TJvmInfo(); - tJvmInfo.setVmVersion(jvmInformation.getJvmVersion()); - TJvmGcType gcType = this.jvmGcTypeMessageConverter.toMessage(jvmInformation.getJvmGcType()); - tJvmInfo.setGcType(gcType); - return tJvmInfo; - } - - private TSqlMetaData convertSqlMetaData(final SqlMetaData sqlMetaData) { - return new TSqlMetaData(agentId, agentStartTime, sqlMetaData.getSqlId(), sqlMetaData.getSql()); - } - - private TApiMetaData convertApiMetaData(final ApiMetaData apiMetaData) { - final TApiMetaData tApiMetaData = new TApiMetaData(agentId, agentStartTime, apiMetaData.getApiId(), apiMetaData.getApiInfo()); - tApiMetaData.setLine(apiMetaData.getLine()); - tApiMetaData.setType(apiMetaData.getType()); - return tApiMetaData; - } - - private TStringMetaData convertStringMetaData(final StringMetaData stringMetaData) { - return new TStringMetaData(agentId, agentStartTime, stringMetaData.getStringId(), stringMetaData.getStringValue()); - } -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverter.java deleted file mode 100644 index df9320a7ed08..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverter.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2018 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.profiler.context.thrift; - -import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import java.util.Objects; -import com.navercorp.pinpoint.common.util.CollectionUtils; -import com.navercorp.pinpoint.common.util.IntStringValue; -import com.navercorp.pinpoint.profiler.context.Annotation; -import com.navercorp.pinpoint.profiler.context.AsyncId; -import com.navercorp.pinpoint.profiler.context.AsyncSpanChunk; -import com.navercorp.pinpoint.profiler.context.LocalAsyncId; -import com.navercorp.pinpoint.profiler.context.Span; -import com.navercorp.pinpoint.profiler.context.SpanChunk; -import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; -import com.navercorp.pinpoint.profiler.context.id.Shared; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.profiler.context.id.TransactionIdEncoder; -import com.navercorp.pinpoint.thrift.dto.TAnnotation; -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; -import com.navercorp.pinpoint.thrift.dto.TIntStringValue; -import com.navercorp.pinpoint.thrift.dto.TLocalAsyncId; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import com.navercorp.pinpoint.thrift.dto.TSpanEvent; -import org.apache.thrift.TBase; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Woonduk Kang(emeroad) - */ -public class SpanThriftMessageConverter implements MessageConverter> { - - private final String agentId; - private final String applicationName; - private final long agentStartTime; - private final short applicationServiceType; - private final TransactionIdEncoder transactionIdEncoder; - private final SpanProcessor spanPostProcessor; - private final AnnotationValueThriftMapper annotationMapper = new AnnotationValueThriftMapper(); - - public SpanThriftMessageConverter(String applicationName, String agentId, long agentStartTime, short applicationServiceType, - TransactionIdEncoder transactionIdEncoder, SpanProcessor spanPostProcessor) { - this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); - this.agentId = Objects.requireNonNull(agentId, "agentId"); - this.agentStartTime = agentStartTime; - this.applicationServiceType = applicationServiceType; - this.transactionIdEncoder = Objects.requireNonNull(transactionIdEncoder, "transactionIdEncoder"); - this.spanPostProcessor = Objects.requireNonNull(spanPostProcessor, "spanPostProcessor"); - - } - - - @Override - public TBase toMessage(SpanType message) { - if (message instanceof SpanChunk) { - final SpanChunk spanChunk = (SpanChunk) message; - return buildTSpanChunk(spanChunk); - } - if (message instanceof Span) { - final Span span = (Span) message; - return buildTSpan(span); - } - return null; - } - - - @VisibleForTesting - TSpan buildTSpan(Span span) { - final TSpan tSpan = new TSpan(); - -// tSpan.setVersion(span.getVersion()); - - tSpan.setApplicationName(applicationName); - tSpan.setAgentId(agentId); - tSpan.setAgentStartTime(agentStartTime); - tSpan.setApplicationServiceType(applicationServiceType); - - final TraceRoot traceRoot = span.getTraceRoot(); - final TraceId traceId = traceRoot.getTraceId(); - final ByteBuffer transactionId = transactionIdEncoder.encodeTransactionId(traceId); - tSpan.setTransactionId(transactionId); - tSpan.setSpanId(traceId.getSpanId()); - tSpan.setParentSpanId(traceId.getParentSpanId()); - - tSpan.setStartTime(span.getStartTime()); - tSpan.setElapsed(span.getElapsedTime()); - tSpan.setServiceType(span.getServiceType()); - - tSpan.setRemoteAddr(span.getRemoteAddr()); - - final Shared shared = traceRoot.getShared(); - tSpan.setRpc(shared.getRpcName()); - tSpan.setEndPoint(shared.getEndPoint()); - tSpan.setFlag(traceId.getFlags()); - tSpan.setErr(shared.getErrorCode()); - - tSpan.setParentApplicationName(span.getParentApplicationName()); - tSpan.setParentApplicationType(span.getParentApplicationType()); - tSpan.setAcceptorHost(span.getAcceptorHost()); - - tSpan.setApiId(span.getApiId()); - - final IntStringValue exceptionInfo = span.getExceptionInfo(); - if (exceptionInfo != null) { - TIntStringValue tIntStringValue = buildTIntStringValue(exceptionInfo); - tSpan.setExceptionInfo(tIntStringValue); - } - - tSpan.setLoggingTransactionInfo(shared.getLoggingInfo()); - - final List> annotations = span.getAnnotations(); - if (CollectionUtils.hasLength(annotations)) { - final List tAnnotations = buildTAnnotation(annotations); - tSpan.setAnnotations(tAnnotations); - } - spanPostProcessor.preProcess(span, tSpan); - final List spanEventList = span.getSpanEventList(); - if (CollectionUtils.hasLength(spanEventList)) { - final List tSpanEvents = buildTSpanEventList(spanEventList); - tSpan.setSpanEventList(tSpanEvents); - } - spanPostProcessor.postProcess(span, tSpan); - return tSpan; - - } - - private List buildTSpanEventList(List spanEventList) { - final int eventSize = spanEventList.size(); - final List tSpanEventList = new ArrayList<>(eventSize); - for (SpanEvent spanEvent : spanEventList) { - final TSpanEvent tSpanEvent = buildTSpanEvent(spanEvent); - tSpanEventList.add(tSpanEvent); - } - return tSpanEventList; - } - - @VisibleForTesting - TSpanChunk buildTSpanChunk(SpanChunk spanChunk) { - final TSpanChunk tSpanChunk = new TSpanChunk(); - - tSpanChunk.setApplicationName(applicationName); - tSpanChunk.setAgentId(agentId); - tSpanChunk.setAgentStartTime(agentStartTime); - tSpanChunk.setApplicationServiceType(applicationServiceType); - - final TraceRoot traceRoot = spanChunk.getTraceRoot(); - final TraceId traceId = traceRoot.getTraceId(); - final ByteBuffer transactionId = transactionIdEncoder.encodeTransactionId(traceId); - tSpanChunk.setTransactionId(transactionId); - - tSpanChunk.setSpanId(traceId.getSpanId()); - - final Shared shared = traceRoot.getShared(); - tSpanChunk.setEndPoint(shared.getEndPoint()); - - if (spanChunk instanceof AsyncSpanChunk) { - final AsyncSpanChunk asyncSpanChunk = (AsyncSpanChunk) spanChunk; - final LocalAsyncId localAsyncId = asyncSpanChunk.getLocalAsyncId(); - final TLocalAsyncId tLocalAsyncId = new TLocalAsyncId(localAsyncId.getAsyncId(), localAsyncId.getSequence()); - tSpanChunk.setLocalAsyncId(tLocalAsyncId); - } - - spanPostProcessor.preProcess(spanChunk, tSpanChunk); - final List spanEventList = spanChunk.getSpanEventList(); - if (CollectionUtils.hasLength(spanEventList)) { - final List tSpanEvents = buildTSpanEventList(spanEventList); - tSpanChunk.setSpanEventList(tSpanEvents); - } - spanPostProcessor.postProcess(spanChunk, tSpanChunk); - - return tSpanChunk; - } - - @VisibleForTesting - TSpanEvent buildTSpanEvent(SpanEvent spanEvent) { - final TSpanEvent tSpanEvent = new TSpanEvent(); - -// if (spanEvent.getStartElapsed() != 0) { -// tSpanEvent.setStartElapsed(spanEvent.getStartElapsed()); -// } -// tSpanEvent.setStartElapsed(spanEvent.getStartElapsed()); - if (spanEvent.getElapsedTime() != 0) { - tSpanEvent.setEndElapsed(spanEvent.getElapsedTime()); - } - tSpanEvent.setSequence((short) spanEvent.getSequence()); -// tSpanEvent.setRpc(spanEvent.getRpc()); - tSpanEvent.setServiceType(spanEvent.getServiceType()); - tSpanEvent.setEndPoint(spanEvent.getEndPoint()); - - // tSpanEvent.setAnnotations(); - if (spanEvent.getDepth() != -1) { - tSpanEvent.setDepth(spanEvent.getDepth()); - } - if (spanEvent.getNextSpanId() != -1) { - tSpanEvent.setNextSpanId(spanEvent.getNextSpanId()); - } - - tSpanEvent.setDestinationId(spanEvent.getDestinationId()); - tSpanEvent.setApiId(spanEvent.getApiId()); - - final IntStringValue exceptionInfo = spanEvent.getExceptionInfo(); - if (exceptionInfo != null) { - TIntStringValue tIntStringValue = buildTIntStringValue(exceptionInfo); - tSpanEvent.setExceptionInfo(tIntStringValue); - } - - - final AsyncId asyncIdObject = spanEvent.getAsyncIdObject(); - if (asyncIdObject != null) { - tSpanEvent.setNextAsyncId(asyncIdObject.getAsyncId()); - } - - final List> annotations = spanEvent.getAnnotations(); - if (CollectionUtils.hasLength(annotations)) { - final List tAnnotations = buildTAnnotation(annotations); - tSpanEvent.setAnnotations(tAnnotations); - } - - return tSpanEvent; - } - - private TIntStringValue buildTIntStringValue(IntStringValue exceptionInfo) { - TIntStringValue tIntStringValue = new TIntStringValue(exceptionInfo.getIntValue()); - final String stringValue = exceptionInfo.getStringValue(); - if (stringValue != null) { - tIntStringValue.setStringValue(stringValue); - } - return tIntStringValue; - } - - @VisibleForTesting - List buildTAnnotation(List> annotations) { - final List tAnnotationList = new ArrayList<>(annotations.size()); - for (Annotation annotation : annotations) { - final TAnnotation tAnnotation = new TAnnotation(annotation.getKey()); - final TAnnotationValue tAnnotationValue = annotationMapper.buildTAnnotationValue(annotation); - if (tAnnotationValue != null) { - tAnnotation.setValue(tAnnotationValue); - } - - tAnnotationList.add(tAnnotation); - } - return tAnnotationList; - } - - @Override - public String toString() { - return "SpanThriftMessageConverter{" + - "agentId='" + agentId + '\'' + - ", applicationName='" + applicationName + '\'' + - ", agentStartTime=" + agentStartTime + - ", applicationServiceType=" + applicationServiceType + - '}'; - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterProvider.java deleted file mode 100644 index 78829b5cef2c..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import java.util.Objects; - -import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; -import com.navercorp.pinpoint.profiler.context.id.TransactionIdEncoder; -import com.navercorp.pinpoint.profiler.context.module.AgentId; -import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; -import com.navercorp.pinpoint.profiler.context.module.ApplicationName; -import com.navercorp.pinpoint.profiler.context.module.ApplicationServerType; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import org.apache.thrift.TBase; - -import javax.inject.Inject; -import javax.inject.Provider; - -/** - * @author Woonduk Kang(emeroad) - */ -public class SpanThriftMessageConverterProvider implements Provider>> { - - private final String applicationName; - private final String agentId; - private final long agentStartTime; - private final ServiceType applicationServiceType; - private final TransactionIdEncoder transactionIdEncoder; - private final SpanProcessor spanPostProcessor; - - @Inject - public SpanThriftMessageConverterProvider(@ApplicationName String applicationName, @AgentId String agentId, @AgentStartTime long agentStartTime, - @ApplicationServerType ServiceType applicationServiceType, - TransactionIdEncoder transactionIdEncoder, SpanProcessor spanPostProcessor) { - this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); - this.agentId = Objects.requireNonNull(agentId, "agentId"); - this.agentStartTime = agentStartTime; - this.applicationServiceType = Objects.requireNonNull(applicationServiceType, "applicationServiceType"); - this.transactionIdEncoder = Objects.requireNonNull(transactionIdEncoder, "transactionIdEncoder"); - this.spanPostProcessor = Objects.requireNonNull(spanPostProcessor, "spanPostProcessor"); - } - - @Override - public MessageConverter> get() { - return new SpanThriftMessageConverter(applicationName, agentId, agentStartTime, applicationServiceType.getCode(), transactionIdEncoder, spanPostProcessor); - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverter.java deleted file mode 100644 index ff7b8ed5a060..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverter.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogram; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogramUtils; -import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshotBatch; -import com.navercorp.pinpoint.profiler.monitor.metric.JvmGcDetailedMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.JvmGcMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.monitor.metric.buffer.BufferMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.datasource.DataSource; -import com.navercorp.pinpoint.profiler.monitor.metric.datasource.DataSourceMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.DeadlockMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.ThreadDumpMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.filedescriptor.FileDescriptorMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.loadedclass.LoadedClassMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeValue; -import com.navercorp.pinpoint.profiler.monitor.metric.transaction.TransactionMetricSnapshot; -import com.navercorp.pinpoint.profiler.monitor.metric.totalthread.TotalThreadMetricSnapshot; -import com.navercorp.pinpoint.thrift.dto.TActiveTrace; -import com.navercorp.pinpoint.thrift.dto.TActiveTraceHistogram; -import com.navercorp.pinpoint.thrift.dto.TAgentStat; -import com.navercorp.pinpoint.thrift.dto.TAgentStatBatch; -import com.navercorp.pinpoint.thrift.dto.TCpuLoad; -import com.navercorp.pinpoint.thrift.dto.TDataSource; -import com.navercorp.pinpoint.thrift.dto.TDataSourceList; -import com.navercorp.pinpoint.thrift.dto.TDeadlock; -import com.navercorp.pinpoint.thrift.dto.TDirectBuffer; -import com.navercorp.pinpoint.thrift.dto.TFileDescriptor; -import com.navercorp.pinpoint.thrift.dto.TJvmGc; -import com.navercorp.pinpoint.thrift.dto.TJvmGcDetailed; -import com.navercorp.pinpoint.thrift.dto.TJvmGcType; -import com.navercorp.pinpoint.thrift.dto.TResponseTime; -import com.navercorp.pinpoint.thrift.dto.TTransaction; -import com.navercorp.pinpoint.thrift.dto.TTotalThreadCount; -import com.navercorp.pinpoint.thrift.dto.TLoadedClass; -import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; -import org.apache.thrift.TBase; - -import java.util.List; - -/** - * @author jaehong.kim - */ -public class StatThriftMessageConverter implements MessageConverter> { - private final ThreadDumpThriftMessageConverter threadDumpMessageConverter = new ThreadDumpThriftMessageConverter(); - private final JvmGcTypeThriftMessageConverter jvmGcTypeMessageConverter = new JvmGcTypeThriftMessageConverter(); - - @Override - public TBase toMessage(MetricType message) { - if (message instanceof AgentStatMetricSnapshotBatch) { - final AgentStatMetricSnapshotBatch agentStatMetricSnapshotBatch = (AgentStatMetricSnapshotBatch) message; - final TAgentStatBatch agentStatBatch = new TAgentStatBatch(); - agentStatBatch.setAgentId(agentStatMetricSnapshotBatch.getAgentId()); - agentStatBatch.setStartTimestamp(agentStatMetricSnapshotBatch.getStartTimestamp()); - for (AgentStatMetricSnapshot agentStatMetricSnapshot : agentStatMetricSnapshotBatch.getAgentStats()) { - final TAgentStat agentStat = convertAgentStat(agentStatMetricSnapshot); - agentStatBatch.addToAgentStats(agentStat); - } - return agentStatBatch; - } else if (message instanceof AgentStatMetricSnapshot) { - final AgentStatMetricSnapshot agentStatMetricSnapshot = (AgentStatMetricSnapshot) message; - final TAgentStat agentStat = convertAgentStat(agentStatMetricSnapshot); - return agentStat; - } - return null; - } - - private TAgentStat convertAgentStat(final AgentStatMetricSnapshot agentStatMetricSnapshot) { - final TAgentStat agentStat = new TAgentStat(); - agentStat.setTimestamp(agentStatMetricSnapshot.getTimestamp()); - agentStat.setCollectInterval(agentStatMetricSnapshot.getCollectInterval()); - - // Agent information - agentStat.setAgentId(agentStatMetricSnapshot.getAgentId()); - agentStat.setStartTimestamp(agentStatMetricSnapshot.getStartTimestamp()); - - // Metric - final JvmGcMetricSnapshot jvmGcMetricSnapshot = agentStatMetricSnapshot.getGc(); - if (jvmGcMetricSnapshot != null) { - final TJvmGc jvmGc = convertJvmGc(jvmGcMetricSnapshot); - agentStat.setGc(jvmGc); - } - - final CpuLoadMetricSnapshot cpuLoadMetricSnapshot = agentStatMetricSnapshot.getCpuLoad(); - if (cpuLoadMetricSnapshot != null) { - final TCpuLoad cpuLoad = convertCpuLoad(cpuLoadMetricSnapshot); - agentStat.setCpuLoad(cpuLoad); - } - - final TransactionMetricSnapshot transactionMetricSnapshot = agentStatMetricSnapshot.getTransaction(); - if (transactionMetricSnapshot != null) { - final TTransaction transaction = convertTransaction(transactionMetricSnapshot); - agentStat.setTransaction(transaction); - } - - final ActiveTraceHistogram activeTraceHistogram = agentStatMetricSnapshot.getActiveTrace(); - if (activeTraceHistogram != null) { - final TActiveTrace activeTrace = convertActiveTrace(activeTraceHistogram); - agentStat.setActiveTrace(activeTrace); - } - - final DataSourceMetricSnapshot dataSourceMetricSnapshot = agentStatMetricSnapshot.getDataSourceList(); - if (dataSourceMetricSnapshot != null) { - final TDataSourceList dataSourceList = convertDataSourceList(dataSourceMetricSnapshot); - agentStat.setDataSourceList(dataSourceList); - } - - final ResponseTimeValue responseTimeValue = agentStatMetricSnapshot.getResponseTime(); - if(responseTimeValue != null) { - final TResponseTime responseTime = convertResponseTime(responseTimeValue); - agentStat.setResponseTime(responseTime); - } - - final DeadlockMetricSnapshot deadlockMetricSnapshot = agentStatMetricSnapshot.getDeadlock(); - if (deadlockMetricSnapshot != null) { - final TDeadlock deadlock = convertDeadlock(deadlockMetricSnapshot); - agentStat.setDeadlock(deadlock); - } - - final FileDescriptorMetricSnapshot fileDescriptorMetricSnapshot = agentStatMetricSnapshot.getFileDescriptor(); - if (fileDescriptorMetricSnapshot != null) { - final TFileDescriptor fileDescriptor = convertFileDescriptor(fileDescriptorMetricSnapshot); - agentStat.setFileDescriptor(fileDescriptor); - } - - final BufferMetricSnapshot bufferMetricSnapshot = agentStatMetricSnapshot.getDirectBuffer(); - if (bufferMetricSnapshot != null) { - final TDirectBuffer directBuffer = convertDirectBuffer(bufferMetricSnapshot); - agentStat.setDirectBuffer(directBuffer); - } - - final TotalThreadMetricSnapshot totalThreadMetricSnapshot = agentStatMetricSnapshot.getTotalThread(); - if (totalThreadMetricSnapshot != null) { - final TTotalThreadCount totalThreadCount = convertTotalThreadCount(totalThreadMetricSnapshot); - agentStat.setTotalThreadCount(totalThreadCount); - } - - final LoadedClassMetricSnapshot loadedClassMetricSnapshot = agentStatMetricSnapshot.getLoadedClassCount(); - if (loadedClassMetricSnapshot != null) { - final TLoadedClass loadedClass = convertLoadedClass(loadedClassMetricSnapshot); - agentStat.setLoadedClass(loadedClass); - } - - return agentStat; - } - - private TJvmGc convertJvmGc(JvmGcMetricSnapshot jvmGcMetricSnapshot) { - final TJvmGc jvmGc = new TJvmGc(); - jvmGc.setJvmMemoryHeapMax(jvmGcMetricSnapshot.getJvmMemoryHeapMax()); - jvmGc.setJvmMemoryHeapUsed(jvmGcMetricSnapshot.getJvmMemoryHeapUsed()); - jvmGc.setJvmMemoryNonHeapMax(jvmGcMetricSnapshot.getJvmMemoryNonHeapMax()); - jvmGc.setJvmMemoryNonHeapUsed(jvmGcMetricSnapshot.getJvmMemoryNonHeapUsed()); - jvmGc.setJvmGcOldCount(jvmGcMetricSnapshot.getJvmGcOldCount()); - jvmGc.setJvmGcOldTime(jvmGcMetricSnapshot.getJvmGcOldTime()); - - final TJvmGcType jvmGcType = this.jvmGcTypeMessageConverter.toMessage(jvmGcMetricSnapshot.getType()); - jvmGc.setType(jvmGcType); - - if (jvmGcMetricSnapshot.getJvmGcDetailed() != null) { - final JvmGcDetailedMetricSnapshot jvmGcDetailedMetricSnapshot = jvmGcMetricSnapshot.getJvmGcDetailed(); - final TJvmGcDetailed jvmGcDetailed = new TJvmGcDetailed(); - jvmGcDetailed.setJvmPoolNewGenUsed(jvmGcDetailedMetricSnapshot.getJvmPoolNewGenUsed()); - jvmGcDetailed.setJvmPoolOldGenUsed(jvmGcDetailedMetricSnapshot.getJvmPoolOldGenUsed()); - jvmGcDetailed.setJvmPoolSurvivorSpaceUsed(jvmGcDetailedMetricSnapshot.getJvmPoolSurvivorSpaceUsed()); - jvmGcDetailed.setJvmPoolCodeCacheUsed(jvmGcDetailedMetricSnapshot.getJvmPoolCodeCacheUsed()); - jvmGcDetailed.setJvmPoolPermGenUsed(jvmGcDetailedMetricSnapshot.getJvmPoolPermGenUsed()); - jvmGcDetailed.setJvmPoolMetaspaceUsed(jvmGcDetailedMetricSnapshot.getJvmPoolMetaspaceUsed()); - jvmGcDetailed.setJvmGcNewCount(jvmGcDetailedMetricSnapshot.getJvmGcNewCount()); - jvmGcDetailed.setJvmGcNewTime(jvmGcDetailedMetricSnapshot.getJvmGcNewTime()); - jvmGc.setJvmGcDetailed(jvmGcDetailed); - } - return jvmGc; - } - - private TCpuLoad convertCpuLoad(CpuLoadMetricSnapshot cpuLoadMetricSnapshot) { - final TCpuLoad cpuLoad = new TCpuLoad(); - cpuLoad.setJvmCpuLoad(cpuLoadMetricSnapshot.getJvmCpuUsage()); - cpuLoad.setSystemCpuLoad(cpuLoadMetricSnapshot.getSystemCpuUsage()); - return cpuLoad; - } - - private TTransaction convertTransaction(TransactionMetricSnapshot transactionMetricSnapshot) { - final TTransaction transaction = new TTransaction(); - transaction.setSampledNewCount(transactionMetricSnapshot.getSampledNewCount()); - transaction.setSampledContinuationCount(transactionMetricSnapshot.getSampledContinuationCount()); - transaction.setUnsampledNewCount(transactionMetricSnapshot.getUnsampledNewCount()); - transaction.setUnsampledContinuationCount(transactionMetricSnapshot.getUnsampledContinuationCount()); - transaction.setSkippedNewCount(transactionMetricSnapshot.getSkippedNewCount()); - transaction.setSkippedContinuationCount(transactionMetricSnapshot.getSkippedContinuationCount()); - return transaction; - } - - private TActiveTrace convertActiveTrace(ActiveTraceHistogram activeTraceHistogramMetricSnapshot) { - final TActiveTrace activeTrace = new TActiveTrace(); - final TActiveTraceHistogram activeTraceHistogram = new TActiveTraceHistogram(); - if(activeTraceHistogramMetricSnapshot.getHistogramSchema() != null) { - activeTraceHistogram.setHistogramSchemaType(activeTraceHistogramMetricSnapshot.getHistogramSchema().getTypeCode()); - } - final List activeTraceCounts = ActiveTraceHistogramUtils.asList(activeTraceHistogramMetricSnapshot); - activeTraceHistogram.setActiveTraceCount(activeTraceCounts); - activeTrace.setHistogram(activeTraceHistogram); - return activeTrace; - } - - private TDataSourceList convertDataSourceList(DataSourceMetricSnapshot dataSourceMetricSnapshot) { - final TDataSourceList dataSourceList = new TDataSourceList(); - for (DataSource dataSourceCollectData : dataSourceMetricSnapshot.getDataSourceList()) { - final TDataSource dataSource = new TDataSource(dataSourceCollectData.getId()); - dataSource.setServiceTypeCode(dataSourceCollectData.getServiceTypeCode()); - if (dataSourceCollectData.getDatabaseName() != null) { - dataSource.setDatabaseName(dataSourceCollectData.getDatabaseName()); - } - if (dataSourceCollectData.getActiveConnectionSize() != 0) { - dataSource.setActiveConnectionSize(dataSourceCollectData.getActiveConnectionSize()); - } - if (dataSourceCollectData.getUrl() != null) { - dataSource.setUrl(dataSourceCollectData.getUrl()); - } - dataSource.setMaxConnectionSize(dataSourceCollectData.getMaxConnectionSize()); - dataSourceList.addToDataSourceList(dataSource); - } - return dataSourceList; - } - - private TResponseTime convertResponseTime(ResponseTimeValue responseTimeValue) { - final TResponseTime responseTime = new TResponseTime(); - if (responseTimeValue.getAvg() != 0) { - responseTime.setAvg(responseTimeValue.getAvg()); - } - if (responseTimeValue.getMax() != 0) { - responseTime.setMax(responseTimeValue.getMax()); - } - return responseTime; - } - - - private TDeadlock convertDeadlock(DeadlockMetricSnapshot deadlockMetricSnapshot) { - // Only send id values that have already been sent - final TDeadlock deadlock = new TDeadlock(); - deadlock.setDeadlockedThreadCount(deadlockMetricSnapshot.getDeadlockedThreadCount()); - - for (ThreadDumpMetricSnapshot threadDumpMetricSnapshot : deadlockMetricSnapshot.getDeadlockedThreadList()) { - final TThreadDump threadDump = this.threadDumpMessageConverter.toMessage(threadDumpMetricSnapshot); - if (threadDump != null) { - deadlock.addToDeadlockedThreadList(threadDump); - } - } - return deadlock; - } - - private TFileDescriptor convertFileDescriptor(FileDescriptorMetricSnapshot fileDescriptorMetricSnapshot) { - final TFileDescriptor fileDescriptor = new TFileDescriptor(); - fileDescriptor.setOpenFileDescriptorCount(fileDescriptorMetricSnapshot.getOpenFileDescriptorCount()); - return fileDescriptor; - } - - private TDirectBuffer convertDirectBuffer(BufferMetricSnapshot bufferMetricSnapshot) { - final TDirectBuffer tdirectBuffer = new TDirectBuffer(); - tdirectBuffer.setDirectCount(bufferMetricSnapshot.getDirectCount()); - tdirectBuffer.setDirectMemoryUsed(bufferMetricSnapshot.getDirectMemoryUsed()); - tdirectBuffer.setMappedCount(bufferMetricSnapshot.getMappedCount()); - tdirectBuffer.setMappedMemoryUsed(bufferMetricSnapshot.getMappedMemoryUsed()); - return tdirectBuffer; - } - - private TTotalThreadCount convertTotalThreadCount(TotalThreadMetricSnapshot totalThreadMetricSnapshot) { - final TTotalThreadCount tTotalThreadCount = new TTotalThreadCount(); - tTotalThreadCount.setTotalThreadCount(totalThreadMetricSnapshot.getTotalThreadCount()); - return tTotalThreadCount; - } - - private TLoadedClass convertLoadedClass(LoadedClassMetricSnapshot loadedClassMetricSnapshot) { - final TLoadedClass tLoadedClass = new TLoadedClass(); - tLoadedClass.setLoadedClassCount(loadedClassMetricSnapshot.getLoadedClassCount()); - tLoadedClass.setUnloadedClassCount(loadedClassMetricSnapshot.getUnloadedClassCount()); - return tLoadedClass; - } -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverterProvider.java deleted file mode 100644 index 18d1bfd1f7f3..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/StatThriftMessageConverterProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import org.apache.thrift.TBase; - -/** - * @author jaehong.kim - */ -public class StatThriftMessageConverterProvider implements Provider>> { - - @Inject - public StatThriftMessageConverterProvider() { - } - - @Override - public MessageConverter> get() { - return new StatThriftMessageConverter(); - } -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftAnnotationSerializable.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftAnnotationSerializable.java deleted file mode 100644 index 30bf1c00351d..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftAnnotationSerializable.java +++ /dev/null @@ -1,28 +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.profiler.context.thrift; - -import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; - -/** - * @author Woonduk Kang(emeroad) - */ -public interface ThriftAnnotationSerializable { - - TAnnotationValue apply(AnnotationValueThriftMapper context); - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverter.java deleted file mode 100644 index 97a86a47c2a2..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.io.request.Message; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; -import com.navercorp.pinpoint.rpc.ResponseMessage; -import com.navercorp.pinpoint.thrift.dto.TResult; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory; -import com.navercorp.pinpoint.thrift.util.SerializationUtils; -import org.apache.thrift.TBase; - -/** - * @author jaehong.kim - */ -public class ThriftMessageToResultConverter implements MessageConverter { - @Override - public ResultResponse toMessage(Object object) { - if (object instanceof ResponseMessage) { - final ResponseMessage responseMessage = (ResponseMessage) object; - final byte[] byteMessage = responseMessage.getMessage(); - final Message> message = SerializationUtils.deserialize(byteMessage, HeaderTBaseDeserializerFactory.DEFAULT_FACTORY, null); - if (message == null) { - throw new IllegalArgumentException("message is null. response message=" + responseMessage); - } - - final TBase tbase = message.getData(); - if (!(tbase instanceof TResult)) { - throw new IllegalArgumentException("invalid message data. response message=" + responseMessage + ", data=" + tbase.getClass()); - } - - final TResult result = (TResult) tbase; - return new ResultResponse() { - @Override - public boolean isSuccess() { - return result.isSuccess(); - } - - @Override - public String getMessage() { - return result.getMessage(); - } - }; - } - return null; - } -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverterProvider.java deleted file mode 100644 index 3c3ee26beaab..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/ThriftMessageToResultConverterProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; - -/** - * @author jaehong.kim - */ -public class ThriftMessageToResultConverterProvider implements Provider> { - @Inject - public ThriftMessageToResultConverterProvider() { - } - - @Override - public MessageConverter get() { - return new ThriftMessageToResultConverter(); - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfig.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfig.java deleted file mode 100644 index c76ca033bbe9..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfig.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift.config; - -import com.navercorp.pinpoint.common.config.Value; -import com.navercorp.pinpoint.common.config.util.ValueAnnotationProcessor; - -import java.util.Properties; - -/** - * @author Woonduk Kang(emeroad) - */ -public class DefaultThriftTransportConfig implements ThriftTransportConfig { - - private static final String DEFAULT_IP = "127.0.0.1"; - - @Value("${profiler.collector.span.ip}") - private String collectorSpanServerIp = DEFAULT_IP; - @Value("${profiler.collector.span.port}") - private int collectorSpanServerPort = 9996; - - @Value("${profiler.collector.stat.ip}") - private String collectorStatServerIp = DEFAULT_IP; - @Value("${profiler.collector.stat.port}") - private int collectorStatServerPort = 9995; - - @Value("${profiler.collector.tcp.ip}") - private String collectorTcpServerIp = DEFAULT_IP; - @Value("${profiler.collector.tcp.port}") - private int collectorTcpServerPort = 9994; - - @Value("${profiler.spandatasender.write.queue.size}") - private int spanDataSenderWriteQueueSize = 1024 * 5; - @Value("${profiler.spandatasender.socket.sendbuffersize}") - private int spanDataSenderSocketSendBufferSize = 1024 * 64 * 16; - @Value("${profiler.spandatasender.socket.timeout}") - private int spanDataSenderSocketTimeout = 1000 * 3; - @Value("${profiler.spandatasender.chunk.size}") - private int spanDataSenderChunkSize = 1024 * 16; - private static final String DEFAULT_SPAN_DATA_SENDER_WRITE_BUFFER_HIGH_WATER_MAK = "16m"; - @Value("${profiler.spandatasender.write.buffer.highwatermark}") - private String spanDataSenderWriteBufferHighWaterMark = DEFAULT_SPAN_DATA_SENDER_WRITE_BUFFER_HIGH_WATER_MAK; - private static final String DEFAULT_SPAN_DATA_SENDER_WRITE_BUFFER_LOW_WATER_MAK = "8m"; - @Value("${profiler.spandatasender.write.buffer.lowwatermark}") - private String spanDataSenderWriteBufferLowWaterMark = DEFAULT_SPAN_DATA_SENDER_WRITE_BUFFER_LOW_WATER_MAK; - @Value("${profiler.spandatasender.transport.type}") - private String spanDataSenderTransportType = "UDP"; - @Value("${profiler.spandatasender.socket.type}") - private String spanDataSenderSocketType = "OIO"; - - @Value("${profiler.statdatasender.write.queue.size}") - private int statDataSenderWriteQueueSize = 1024 * 5; - @Value("${profiler.statdatasender.socket.sendbuffersize}") - private int statDataSenderSocketSendBufferSize = 1024 * 64 * 16; - @Value("${profiler.statdatasender.socket.timeout}") - private int statDataSenderSocketTimeout = 1000 * 3; - @Value("${profiler.statdatasender.chunk.size}") - private int statDataSenderChunkSize = 1024 * 16; - - private static final String DEFAULT_STAT_DATA_SENDER_WRITE_BUFFER_HIGH_WATER_MAK = "16m"; - @Value("${profiler.statdatasender.write.buffer.highwatermark}") - private String statDataSenderWriteBufferHighWaterMark = DEFAULT_STAT_DATA_SENDER_WRITE_BUFFER_HIGH_WATER_MAK; - - private static final String DEFAULT_STAT_DATA_SENDER_WRITE_BUFFER_LOW_WATER_MAK = "8m"; - @Value("${profiler.statdatasender.write.buffer.lowwatermark}") - private String statDataSenderWriteBufferLowWaterMark = DEFAULT_STAT_DATA_SENDER_WRITE_BUFFER_LOW_WATER_MAK; - @Value("${profiler.statdatasender.transport.type}") - private String statDataSenderTransportType = "UDP"; - @Value("${profiler.statdatasender.socket.type}") - private String statDataSenderSocketType = "OIO"; - - @Value("${profiler.tcpdatasender.command.accept.enable}") - private boolean tcpDataSenderCommandAcceptEnable = false; - @Value("${profiler.tcpdatasender.command.activethread.enable}") - private boolean tcpDataSenderCommandActiveThreadEnable = false; - @Value("${profiler.tcpdatasender.command.activethread.count.enable}") - private boolean tcpDataSenderCommandActiveThreadCountEnable = false; - @Value("${profiler.tcpdatasender.command.activethread.threaddump.enable}") - private boolean tcpDataSenderCommandActiveThreadDumpEnable = false; - @Value("${profiler.tcpdatasender.command.activethread.threadlightdump.enable}") - private boolean tcpDataSenderCommandActiveThreadLightDumpEnable = false; - - private static final long DEFAULT_DATA_SENDER_PINPOINT_CLIENT_WRITE_TIMEOUT = 3 * 1000; - @Value("${profiler.tcpdatasender.client.write.timeout}") - private long tcpDataSenderPinpointClientWriteTimeout = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_WRITE_TIMEOUT; - - private static final long DEFAULT_DATA_SENDER_PINPOINT_CLIENT_REQUEST_TIMEOUT = 3 * 1000; - @Value("${profiler.tcpdatasender.client.request.timeout}") - private long tcpDataSenderPinpointClientRequestTimeout = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_REQUEST_TIMEOUT; - - private static final long DEFAULT_DATA_SENDER_PINPOINT_CLIENT_RECONNECT_INTERVAL = 3 * 1000; - @Value("${profiler.tcpdatasender.client.reconnect.interval}") - private long tcpDataSenderPinpointClientReconnectInterval = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_RECONNECT_INTERVAL; - - private static final long DEFAULT_DATA_SENDER_PINPOINT_CLIENT_PING_INTERVAL = 60 * 1000 * 5; - @Value("${profiler.tcpdatasender.client.ping.interval}") - private long tcpDataSenderPinpointClientPingInterval = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_PING_INTERVAL; - - private static final long DEFAULT_DATA_SENDER_PINPOINT_CLIENT_HANDSHAKE_INTERVAL = 60 * 1000 * 1; - @Value("${profiler.tcpdatasender.client.handshake.interval}") - private long tcpDataSenderPinpointClientHandshakeInterval = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_HANDSHAKE_INTERVAL; - - private static final String DEFAULT_DATA_SENDER_PINPOINT_CLIENT_WRITE_BUFFER_HIGH_WATER_MAK = "32m"; - @Value("${profiler.tcpdatasender.client.write.buffer.highwatermark}") - private String tcpDataSenderPinpointClientWriteBufferHighWaterMark = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_WRITE_BUFFER_HIGH_WATER_MAK; - - private static final String DEFAULT_DATA_SENDER_PINPOINT_CLIENT_WRITE_BUFFER_LOW_WATER_MAK = "16m"; - @Value("${profiler.tcpdatasender.client.write.buffer.lowwatermark}") - private String tcpDataSenderPinpointClientWriteBufferLowWaterMark = DEFAULT_DATA_SENDER_PINPOINT_CLIENT_WRITE_BUFFER_LOW_WATER_MAK; - - public DefaultThriftTransportConfig() { - } - - public void read(Properties properties) { - final ValueAnnotationProcessor reader = new ValueAnnotationProcessor(); - reader.process(this, properties); - } - - @Override - public String getCollectorSpanServerIp() { - return collectorSpanServerIp; - } - - @Override - public int getCollectorSpanServerPort() { - return collectorSpanServerPort; - } - - @Override - public String getCollectorStatServerIp() { - return collectorStatServerIp; - } - - @Override - public int getCollectorStatServerPort() { - return collectorStatServerPort; - } - - @Override - public String getCollectorTcpServerIp() { - return collectorTcpServerIp; - } - - @Override - public int getCollectorTcpServerPort() { - return collectorTcpServerPort; - } - - @Override - public int getStatDataSenderWriteQueueSize() { - return statDataSenderWriteQueueSize; - } - - @Override - public int getStatDataSenderSocketSendBufferSize() { - return statDataSenderSocketSendBufferSize; - } - - @Override - public int getStatDataSenderSocketTimeout() { - return statDataSenderSocketTimeout; - } - - @Override - public String getStatDataSenderWriteBufferHighWaterMark() { - return statDataSenderWriteBufferHighWaterMark; - } - - @Override - public String getStatDataSenderWriteBufferLowWaterMark() { - return statDataSenderWriteBufferLowWaterMark; - } - - @Override - public String getStatDataSenderSocketType() { - return statDataSenderSocketType; - } - - @Override - public String getStatDataSenderTransportType() { - return statDataSenderTransportType; - } - - @Override - public int getSpanDataSenderWriteQueueSize() { - return spanDataSenderWriteQueueSize; - } - - @Override - public int getSpanDataSenderSocketSendBufferSize() { - return spanDataSenderSocketSendBufferSize; - } - - @Override - public boolean isTcpDataSenderCommandAcceptEnable() { - return tcpDataSenderCommandAcceptEnable; - } - - @Override - public boolean isTcpDataSenderCommandActiveThreadEnable() { - return tcpDataSenderCommandActiveThreadEnable; - } - - @Override - public boolean isTcpDataSenderCommandActiveThreadCountEnable() { - return tcpDataSenderCommandActiveThreadCountEnable; - } - - @Override - public boolean isTcpDataSenderCommandActiveThreadDumpEnable() { - return tcpDataSenderCommandActiveThreadDumpEnable; - } - - @Override - public boolean isTcpDataSenderCommandActiveThreadLightDumpEnable() { - return tcpDataSenderCommandActiveThreadLightDumpEnable; - } - - @Override - public long getTcpDataSenderPinpointClientWriteTimeout() { - return tcpDataSenderPinpointClientWriteTimeout; - } - - @Override - public long getTcpDataSenderPinpointClientRequestTimeout() { - return tcpDataSenderPinpointClientRequestTimeout; - } - - @Override - public long getTcpDataSenderPinpointClientReconnectInterval() { - return tcpDataSenderPinpointClientReconnectInterval; - } - - @Override - public long getTcpDataSenderPinpointClientPingInterval() { - return tcpDataSenderPinpointClientPingInterval; - } - - @Override - public long getTcpDataSenderPinpointClientHandshakeInterval() { - return tcpDataSenderPinpointClientHandshakeInterval; - } - - @Override - public String getTcpDataSenderPinpointClientWriteBufferHighWaterMark() { - return tcpDataSenderPinpointClientWriteBufferHighWaterMark; - } - - @Override - public String getTcpDataSenderPinpointClientWriteBufferLowWaterMark() { - return tcpDataSenderPinpointClientWriteBufferLowWaterMark; - } - - @Override - public int getSpanDataSenderSocketTimeout() { - return spanDataSenderSocketTimeout; - } - - @Override - public String getSpanDataSenderSocketType() { - return spanDataSenderSocketType; - } - - @Override - public String getSpanDataSenderTransportType() { - return spanDataSenderTransportType; - } - - @Override - public String getSpanDataSenderWriteBufferHighWaterMark() { - return spanDataSenderWriteBufferHighWaterMark; - } - - @Override - public String getSpanDataSenderWriteBufferLowWaterMark() { - return spanDataSenderWriteBufferLowWaterMark; - } - - @Override - public int getSpanDataSenderChunkSize() { - return spanDataSenderChunkSize; - } - - @Override - public int getStatDataSenderChunkSize() { - return statDataSenderChunkSize; - } - - @Override - public String toString() { - return "DefaultThriftTransportConfig{" + - "collectorSpanServerIp='" + collectorSpanServerIp + '\'' + - ", collectorSpanServerPort=" + collectorSpanServerPort + - ", collectorStatServerIp='" + collectorStatServerIp + '\'' + - ", collectorStatServerPort=" + collectorStatServerPort + - ", collectorTcpServerIp='" + collectorTcpServerIp + '\'' + - ", collectorTcpServerPort=" + collectorTcpServerPort + - ", spanDataSenderWriteQueueSize=" + spanDataSenderWriteQueueSize + - ", spanDataSenderSocketSendBufferSize=" + spanDataSenderSocketSendBufferSize + - ", spanDataSenderSocketTimeout=" + spanDataSenderSocketTimeout + - ", spanDataSenderChunkSize=" + spanDataSenderChunkSize + - ", spanDataSenderWriteBufferHighWaterMark=" + spanDataSenderWriteBufferHighWaterMark + - ", spanDataSenderWriteBufferLowWaterMark=" + spanDataSenderWriteBufferLowWaterMark + - ", spanDataSenderTransportType='" + spanDataSenderTransportType + '\'' + - ", spanDataSenderSocketType='" + spanDataSenderSocketType + '\'' + - ", statDataSenderWriteQueueSize=" + statDataSenderWriteQueueSize + - ", statDataSenderSocketSendBufferSize=" + statDataSenderSocketSendBufferSize + - ", statDataSenderSocketTimeout=" + statDataSenderSocketTimeout + - ", statDataSenderChunkSize=" + statDataSenderChunkSize + - ", statDataSenderWriteBufferHighWaterMark=" + statDataSenderWriteBufferHighWaterMark + - ", statDataSenderWriteBufferLowWaterMark=" + statDataSenderWriteBufferLowWaterMark + - ", statDataSenderTransportType='" + statDataSenderTransportType + '\'' + - ", statDataSenderSocketType='" + statDataSenderSocketType + '\'' + - ", tcpDataSenderCommandAcceptEnable=" + tcpDataSenderCommandAcceptEnable + - ", tcpDataSenderCommandActiveThreadEnable=" + tcpDataSenderCommandActiveThreadEnable + - ", tcpDataSenderCommandActiveThreadCountEnable=" + tcpDataSenderCommandActiveThreadCountEnable + - ", tcpDataSenderCommandActiveThreadDumpEnable=" + tcpDataSenderCommandActiveThreadDumpEnable + - ", tcpDataSenderCommandActiveThreadLightDumpEnable=" + tcpDataSenderCommandActiveThreadLightDumpEnable + - ", tcpDataSenderPinpointClientWriteTimeout=" + tcpDataSenderPinpointClientWriteTimeout + - ", tcpDataSenderPinpointClientRequestTimeout=" + tcpDataSenderPinpointClientRequestTimeout + - ", tcpDataSenderPinpointClientReconnectInterval=" + tcpDataSenderPinpointClientReconnectInterval + - ", tcpDataSenderPinpointClientPingInterval=" + tcpDataSenderPinpointClientPingInterval + - ", tcpDataSenderPinpointClientHandshakeInterval=" + tcpDataSenderPinpointClientHandshakeInterval + - ", tcpDataSenderPinpointClientWriteBufferHighWaterMark=" + tcpDataSenderPinpointClientWriteBufferHighWaterMark + - ", tcpDataSenderPinpointClientWriteBufferLowWaterMark=" + tcpDataSenderPinpointClientWriteBufferLowWaterMark + - '}'; - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/ThriftTransportConfig.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/ThriftTransportConfig.java deleted file mode 100644 index 5b434a14f08c..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/thrift/config/ThriftTransportConfig.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift.config; - -/** - * @author Woonduk Kang(emeroad) - */ -public interface ThriftTransportConfig { - - String getCollectorSpanServerIp(); - - int getCollectorSpanServerPort(); - - String getCollectorStatServerIp(); - - int getCollectorStatServerPort(); - - String getCollectorTcpServerIp(); - - int getCollectorTcpServerPort(); - - int getStatDataSenderWriteQueueSize(); - - int getStatDataSenderSocketSendBufferSize(); - - int getStatDataSenderSocketTimeout(); - - String getStatDataSenderSocketType(); - - String getStatDataSenderTransportType(); - - String getStatDataSenderWriteBufferHighWaterMark(); - - String getStatDataSenderWriteBufferLowWaterMark(); - - - int getSpanDataSenderWriteQueueSize(); - - int getSpanDataSenderSocketSendBufferSize(); - - boolean isTcpDataSenderCommandAcceptEnable(); - - boolean isTcpDataSenderCommandActiveThreadEnable(); - - boolean isTcpDataSenderCommandActiveThreadCountEnable(); - - - - boolean isTcpDataSenderCommandActiveThreadDumpEnable(); - - boolean isTcpDataSenderCommandActiveThreadLightDumpEnable(); - - long getTcpDataSenderPinpointClientWriteTimeout(); - - long getTcpDataSenderPinpointClientRequestTimeout(); - - long getTcpDataSenderPinpointClientReconnectInterval(); - - - long getTcpDataSenderPinpointClientPingInterval(); - - long getTcpDataSenderPinpointClientHandshakeInterval(); - - String getTcpDataSenderPinpointClientWriteBufferHighWaterMark(); - - String getTcpDataSenderPinpointClientWriteBufferLowWaterMark(); - - int getSpanDataSenderSocketTimeout(); - - String getSpanDataSenderSocketType(); - - String getSpanDataSenderTransportType(); - - String getSpanDataSenderWriteBufferHighWaterMark(); - - String getSpanDataSenderWriteBufferLowWaterMark(); - - int getSpanDataSenderChunkSize(); - - int getStatDataSenderChunkSize(); - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataService.java index 1442c9893a4c..b54da45d2045 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataService.java @@ -17,11 +17,12 @@ package com.navercorp.pinpoint.profiler.metadata; import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; -import java.util.Objects; - +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.cache.Result; import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; + +import java.util.Objects; /** * @author Woonduk Kang(emeroad) @@ -30,9 +31,9 @@ public class DefaultApiMetaDataService implements ApiMetaDataService { private final SimpleCache apiCache; - private final EnhancedDataSender enhancedDataSender; + private final EnhancedDataSender enhancedDataSender; - public DefaultApiMetaDataService(EnhancedDataSender enhancedDataSender, SimpleCache apiCache) { + public DefaultApiMetaDataService(EnhancedDataSender enhancedDataSender, SimpleCache apiCache) { this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender"); this.apiCache = Objects.requireNonNull(apiCache, "apiCache"); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataService.java index edd938500ba8..49aa81d96840 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataService.java @@ -17,12 +17,13 @@ package com.navercorp.pinpoint.profiler.metadata; import com.navercorp.pinpoint.bootstrap.context.ParsingResult; -import java.util.Objects; - +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Objects; /** * @author Woonduk Kang(emeroad) @@ -34,9 +35,9 @@ public class DefaultSqlMetaDataService implements SqlMetaDataService { private final CachingSqlNormalizer cachingSqlNormalizer; - private final EnhancedDataSender enhancedDataSender; + private final EnhancedDataSender enhancedDataSender; - public DefaultSqlMetaDataService(EnhancedDataSender enhancedDataSender, SimpleCache sqlCache) { + public DefaultSqlMetaDataService(EnhancedDataSender enhancedDataSender, SimpleCache sqlCache) { this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender"); Objects.requireNonNull(sqlCache, "sqlCache"); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataService.java index 28616d65ddc0..35d001b24930 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataService.java @@ -16,11 +16,12 @@ package com.navercorp.pinpoint.profiler.metadata; -import java.util.Objects; - +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.cache.Result; import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; + +import java.util.Objects; /** * @author Woonduk Kang(emeroad) @@ -29,9 +30,9 @@ public class DefaultStringMetaDataService implements StringMetaDataService { private final SimpleCache stringCache; - private final EnhancedDataSender enhancedDataSender; + private final EnhancedDataSender enhancedDataSender; - public DefaultStringMetaDataService(EnhancedDataSender enhancedDataSender, SimpleCache stringCache) { + public DefaultStringMetaDataService(EnhancedDataSender enhancedDataSender, SimpleCache stringCache) { this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender"); this.stringCache = Objects.requireNonNull(stringCache, "stringCache"); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java index dd8dafe0abc9..489dd46412f3 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java @@ -16,13 +16,13 @@ package com.navercorp.pinpoint.profiler.monitor; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshotBatch; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CustomMetricCollectingJob.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CustomMetricCollectingJob.java index 862b99053116..966f126e978c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CustomMetricCollectingJob.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CustomMetricCollectingJob.java @@ -16,20 +16,18 @@ package com.navercorp.pinpoint.profiler.monitor; -import java.util.Objects; - +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.profiler.monitor.collector.AgentCustomMetricCollector; import com.navercorp.pinpoint.profiler.monitor.metric.AgentCustomMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.AgentCustomMetricSnapshotBatch; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * @author Taejin Koo diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java index ab20570ada9d..3bfc93451d48 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java @@ -19,6 +19,8 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.EmptyDataSender; import com.navercorp.pinpoint.profiler.context.module.AgentId; import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; import com.navercorp.pinpoint.profiler.context.module.StatDataSender; @@ -30,8 +32,6 @@ import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; -import com.navercorp.pinpoint.profiler.sender.EmptyDataSender; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -116,7 +116,7 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender // eg) executor.scheduleAtFixedRate(collectJob, 0(initialDelay is zero), this.collectionIntervalMs, TimeUnit.MILLISECONDS); private void preLoadClass(String agentId, long agentStartTimestamp, AgentStatMetricCollector agentStatCollector) { logger.debug("pre-load class start"); - CollectJob collectJob = new CollectJob(EmptyDataSender.instance(), agentId, agentStartTimestamp, agentStatCollector, 1); + CollectJob collectJob = new CollectJob(EmptyDataSender.instance(), agentId, agentStartTimestamp, agentStatCollector, 1); // It is called twice to initialize some fields. collectJob.run(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/UriStatCollectingJob.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/UriStatCollectingJob.java index 13b68618f593..d51f9a2fbb23 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/UriStatCollectingJob.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/UriStatCollectingJob.java @@ -16,13 +16,12 @@ package com.navercorp.pinpoint.profiler.monitor; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.storage.UriStatStorage; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; -import com.navercorp.pinpoint.profiler.sender.DataSender; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.Closeable; import java.util.Objects; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java deleted file mode 100644 index 48a9a84b45b8..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver; - -import com.google.inject.Inject; -import java.util.Objects; -import com.navercorp.pinpoint.io.request.Message; -import com.navercorp.pinpoint.rpc.MessageListener; -import com.navercorp.pinpoint.rpc.PinpointSocket; -import com.navercorp.pinpoint.rpc.packet.RequestPacket; -import com.navercorp.pinpoint.rpc.packet.SendPacket; -import com.navercorp.pinpoint.rpc.packet.stream.StreamClosePacket; -import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; -import com.navercorp.pinpoint.rpc.packet.stream.StreamCreatePacket; -import com.navercorp.pinpoint.rpc.stream.ServerStreamChannel; -import com.navercorp.pinpoint.rpc.stream.ServerStreamChannelMessageHandler; -import com.navercorp.pinpoint.thrift.dto.TResult; -import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseDeserializerFactory; -import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseSerializerFactory; -import com.navercorp.pinpoint.thrift.util.SerializationUtils; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.io.Closeable; -import java.util.Set; - -/** - * @author Taejin Koo - */ -public class CommandDispatcher extends ServerStreamChannelMessageHandler implements MessageListener { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - private final ProfilerCommandServiceLocator, TBase> commandServiceLocator; - - private final CommandHeaderTBaseSerializerFactory commandHeaderTBaseSerializerFactory = CommandHeaderTBaseSerializerFactory.getDefaultInstance(); - private final CommandHeaderTBaseDeserializerFactory commandHeaderTBaseDeserializerFactory = CommandHeaderTBaseDeserializerFactory.getDefaultInstance(); - - @Inject - public CommandDispatcher(ProfilerCommandServiceLocator, TBase> commandServiceLocator) { - this.commandServiceLocator = Objects.requireNonNull(commandServiceLocator, "commandServiceLocator"); - } - - @Override - public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) { - logger.info("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress()); - } - - @Override - public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) { - logger.info("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress()); - - final Message> message = SerializationUtils.deserialize(requestPacket.getPayload(), commandHeaderTBaseDeserializerFactory, null); - if (logger.isDebugEnabled()) { - logger.debug("handleRequest request:{}, remote:{}", message, pinpointSocket.getRemoteAddress()); - } - - final TBase response = processRequest(message); - - final byte[] payload = SerializationUtils.serialize(response, commandHeaderTBaseSerializerFactory, null); - if (payload != null) { - pinpointSocket.response(requestPacket.getRequestId(), payload); - } - } - - private TBase processRequest(Message> message) { - if (message == null) { - final TResult tResult = new TResult(false); - tResult.setMessage("Unsupported ServiceTypeInfo."); - - return tResult; - } - - final short type = message.getHeader().getType(); - final ProfilerRequestCommandService, TBase> service = commandServiceLocator.getRequestService(type); - if (service == null) { - TResult tResult = new TResult(false); - tResult.setMessage("Can't find suitable service(" + message + ")."); - - return tResult; - } - - final TBase request = message.getData(); - final TBase tResponse = service.requestCommandService(request); - return tResponse; - } - - @Override - public StreamCode handleStreamCreatePacket(ServerStreamChannel streamChannel, StreamCreatePacket packet) { - logger.info("handleStreamCreatePacket() streamChannel:{}, packet:{}", streamChannel, packet); - - final Message> message = SerializationUtils.deserialize(packet.getPayload(), commandHeaderTBaseDeserializerFactory, null); - if (message == null) { - return StreamCode.TYPE_UNKNOWN; - } - - final short type = message.getHeader().getType(); - final ProfilerStreamCommandService> service = commandServiceLocator.getStreamService(type); - if (service == null) { - return StreamCode.TYPE_UNSUPPORT; - } - - final TBase request = message.getData(); - return service.streamCommandService(request, streamChannel); - } - - @Override - public void handleStreamClosePacket(ServerStreamChannel streamChannel, StreamClosePacket packet) { - logger.info("handleStreamClosePacket() streamChannel:{}, packet:{}", streamChannel, packet); - } - - public Set getRegisteredCommandServiceCodes() { - return commandServiceLocator.getCommandServiceCodes(); - } - - public void close() { - logger.info("close() started"); - - Set commandServiceCodes = commandServiceLocator.getCommandServiceCodes(); - for (Short commandServiceCode : commandServiceCodes) { - ProfilerCommandService service = commandServiceLocator.getService(commandServiceCode); - if (service instanceof Closeable) { - try { - ((Closeable) service).close(); - } catch (Exception e) { - logger.warn("failed to close for CommandService:{}. message:{}", service, e.getMessage()); - } - } - } - - logger.info("close() completed"); - } - - @Override - public String toString() { - return "CommandDispatcher{" + commandServiceLocator.getCommandServiceCodes() + '}'; - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java index b033941a363b..3a559f8b8b9c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java @@ -43,39 +43,6 @@ public ProfilerCommandService getService(short commandCode) { return profilerCommandServiceRepository.get(commandCode); } - @Override - public ProfilerSimpleCommandService getSimpleService(short commandCode) { - - final ProfilerCommandService service = profilerCommandServiceRepository.get(commandCode); - if (service instanceof ProfilerSimpleCommandService) { - return (ProfilerSimpleCommandService) service; - } - - return null; - } - - @Override - public ProfilerRequestCommandService getRequestService(short commandCode) { - - final ProfilerCommandService service = profilerCommandServiceRepository.get(commandCode); - if (service instanceof ProfilerRequestCommandService) { - return (ProfilerRequestCommandService) service; - } - - return null; - } - - @Override - public ProfilerStreamCommandService getStreamService(short commandCode) { - - final ProfilerCommandService service = profilerCommandServiceRepository.get(commandCode); - if (service instanceof ProfilerStreamCommandService) { - return (ProfilerStreamCommandService) service; - } - - return null; - } - @Override public ProfilerGrpcCommandService getGrpcService(short commandCode) { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java index 8e8c3503f926..6678d3ba5135 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java @@ -27,12 +27,6 @@ public interface ProfilerCommandServiceLocator { ProfilerCommandService getService(short commandCode); - ProfilerSimpleCommandService getSimpleService(short commandCode); - - ProfilerRequestCommandService getRequestService(short commandCode); - - ProfilerStreamCommandService getStreamService(short commandCode); - ProfilerGrpcCommandService getGrpcService(short commandCode); Set getCommandServiceCodes(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java deleted file mode 100644 index a72201ccb357..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver; - -/** - * @author koo.taejin - */ -public interface ProfilerRequestCommandService extends ProfilerCommandService { - - RES requestCommandService(REQ request); - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java deleted file mode 100644 index 5ae1c1fbdc78..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver; - -/** - * @author koo.taejin - */ -public interface ProfilerSimpleCommandService extends ProfilerCommandService { - - void simpleCommandService(REQ request); - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java deleted file mode 100644 index 1c86fec8d822..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver; - -import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; -import com.navercorp.pinpoint.rpc.stream.ServerStreamChannel; - -public interface ProfilerStreamCommandService extends ProfilerCommandService { - - StreamCode streamCommandService(REQ request, ServerStreamChannel serverStreamChannel); - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcActiveThreadLightDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcActiveThreadLightDumpService.java index 5aec1f08fe45..fdf2ab12ef8f 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcActiveThreadLightDumpService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcActiveThreadLightDumpService.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.profiler.receiver.grpc; -import java.util.Objects; import com.navercorp.pinpoint.common.util.JvmUtils; import com.navercorp.pinpoint.grpc.trace.PActiveThreadLightDump; import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDump; @@ -32,14 +31,14 @@ import com.navercorp.pinpoint.profiler.receiver.service.ActiveThreadDumpCoreService; import com.navercorp.pinpoint.profiler.receiver.service.ThreadDump; import com.navercorp.pinpoint.profiler.receiver.service.ThreadDumpRequest; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.management.ThreadInfo; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * @author Taejin Koo @@ -90,7 +89,7 @@ private List getActiveThreadDumpList(PCmdActiveThreadLig } private List toPActiveThreadLightDump(Collection activeTraceInfoList) { - final List result = new ArrayList(activeTraceInfoList.size()); + final List result = new ArrayList<>(activeTraceInfoList.size()); for (ThreadDump threadDump : activeTraceInfoList) { PActiveThreadLightDump pActiveThreadLightDump = createActiveThreadDump(threadDump); result.add(pActiveThreadLightDump); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandDispatcher.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandDispatcher.java index 78c23544ccac..258f2e3bed4e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandDispatcher.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandDispatcher.java @@ -16,22 +16,21 @@ package com.navercorp.pinpoint.profiler.receiver.grpc; -import java.util.Objects; +import com.google.protobuf.StringValue; +import com.navercorp.pinpoint.common.profiler.message.RouteResult; import com.navercorp.pinpoint.grpc.trace.PCmdMessage; import com.navercorp.pinpoint.grpc.trace.PCmdRequest; import com.navercorp.pinpoint.grpc.trace.PCmdResponse; import com.navercorp.pinpoint.grpc.trace.ProfilerCommandServiceGrpc; import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandService; import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator; -import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; - -import com.google.protobuf.StringValue; import io.grpc.stub.StreamObserver; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.Closeable; import java.util.Collection; +import java.util.Objects; import java.util.Set; /** @@ -65,7 +64,7 @@ public void handle(PCmdRequest commandRequest, StreamObserver strea } } } else { - PCmdResponse failMessage = createFailMessage(commandRequest, TRouteResult.NOT_SUPPORTED_REQUEST.name()); + PCmdResponse failMessage = createFailMessage(commandRequest, RouteResult.NOT_SUPPORTED_REQUEST.name()); if (streamObserver != null) { streamObserver.onNext(PCmdMessage.newBuilder().setFailMessage(failMessage).build()); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandService.java index 40fefa0ae936..332a07072855 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/grpc/GrpcCommandService.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.profiler.receiver.grpc; -import java.util.Objects; import com.navercorp.pinpoint.grpc.StatusError; import com.navercorp.pinpoint.grpc.StatusErrors; import com.navercorp.pinpoint.grpc.client.SupportCommandCodeClientInterceptor; @@ -27,11 +26,12 @@ import com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor; import com.navercorp.pinpoint.profiler.sender.grpc.Reconnector; import com.navercorp.pinpoint.profiler.sender.grpc.StreamUtils; - import io.grpc.stub.ClientCallStreamObserver; import io.grpc.stub.ClientResponseObserver; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Objects; /** * @author Taejin Koo @@ -157,14 +157,14 @@ public void onError(Throwable t) { @Override public void onCompleted() { logger.info("onCompleted"); - StreamUtils.close(requestStream); + StreamUtils.close(requestStream, GrpcCommandService.this.logger); // TODO : needs to check whether needs new action reserveReconnect(); } private void stop() { logger.info("stop"); - StreamUtils.close(requestStream); + StreamUtils.close(requestStream, GrpcCommandService.this.logger); commandDispatcher.close(); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java deleted file mode 100644 index 2711ba085f68..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver.service; - -import java.util.Objects; - -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogram; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogramUtils; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.receiver.ProfilerRequestCommandService; -import com.navercorp.pinpoint.profiler.receiver.ProfilerStreamCommandService; -import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; -import com.navercorp.pinpoint.rpc.stream.ServerStreamChannel; -import com.navercorp.pinpoint.rpc.stream.StreamChannelStateChangeEventHandler; -import com.navercorp.pinpoint.rpc.stream.StreamChannelStateCode; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes; -import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseSerializerFactory; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import com.navercorp.pinpoint.thrift.util.SerializationUtils; - -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.io.Closeable; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicReference; - -/** - * @author Taejin Koo - */ -public class ActiveThreadCountService implements ProfilerRequestCommandService, TBase>, ProfilerStreamCommandService>, Closeable { - - private static final long DEFAULT_FLUSH_DELAY = 1000; - - private final Logger logger = LogManager.getLogger(this.getClass()); - private final boolean isDebug = logger.isDebugEnabled(); - - private final StreamChannelStateChangeEventHandler stateChangeEventHandler = new ActiveThreadCountStreamChannelStateChangeEventHandler(); - - private final Timer timer = new Timer("Pinpoint-ActiveThreadCountService-Timer", true); - - private final long flushDelay; - - private final List streamChannelRepository = new CopyOnWriteArrayList(); - - private final ActiveTraceRepository activeTraceRepository; - - private final CommandHeaderTBaseSerializerFactory commandHeaderTBaseSerializerFactory = CommandHeaderTBaseSerializerFactory.getDefaultInstance(); - - public ActiveThreadCountService(ActiveTraceRepository activeTraceRepository) { - this(activeTraceRepository, DEFAULT_FLUSH_DELAY); - } - - public ActiveThreadCountService(ActiveTraceRepository activeTraceRepository, long flushDelay) { - this.activeTraceRepository = Objects.requireNonNull(activeTraceRepository, "activeTraceRepository"); - this.flushDelay = flushDelay; - } - - @Override - public short getCommandServiceCode() { - return TCommandType.ACTIVE_THREAD_COUNT.getCode(); - } - - @Override - public TBase requestCommandService(TBase activeThreadCountObject) { - Objects.requireNonNull(activeThreadCountObject, "activeThreadCountObject"); - - return getActiveThreadCountResponse(); - } - - @Override - public StreamCode streamCommandService(TBase tBase, ServerStreamChannel serverStreamChannel) { - logger.info("streamCommandService object:{}, serverStreamChannel:{}", tBase, serverStreamChannel); - serverStreamChannel.setStateChangeEventHandler(stateChangeEventHandler); - return StreamCode.OK; - } - - private TCmdActiveThreadCountRes getActiveThreadCountResponse() { - - final long currentTime = System.currentTimeMillis(); - final ActiveTraceHistogram histogram = this.activeTraceRepository.getActiveTraceHistogram(currentTime); - - - TCmdActiveThreadCountRes response = new TCmdActiveThreadCountRes(); - response.setHistogramSchemaType(histogram.getHistogramSchema().getTypeCode()); - - final List activeTraceCounts = ActiveTraceHistogramUtils.asList(histogram); - response.setActiveThreadCount(activeTraceCounts); - response.setTimeStamp(currentTime); - - return response; - } - - private class ActiveThreadCountStreamChannelStateChangeEventHandler implements StreamChannelStateChangeEventHandler { - - private final Object lock = new Object(); - - private final AtomicReference currentTaskReference = new AtomicReference(); - - @Override - public void stateUpdated(ServerStreamChannel streamChannel, StreamChannelStateCode updatedStateCode) { - logger.info("stateUpdated() streamChannel:{}, updatedStateCode:{}.", streamChannel, updatedStateCode); - synchronized (lock) { - switch (updatedStateCode) { - case CONNECTED: - streamChannelRepository.add(streamChannel); - - ActiveThreadCountTimerTask activeThreadCountTimerTask = new ActiveThreadCountTimerTask(); - boolean turnOn = currentTaskReference.compareAndSet(null, activeThreadCountTimerTask); - if (turnOn) { - logger.info("turn on ActiveThreadCountTimerTask."); - - timer.scheduleAtFixedRate(activeThreadCountTimerTask, flushDelay, flushDelay); - } - break; - case CLOSED: - case ILLEGAL_STATE: - boolean removed = streamChannelRepository.remove(streamChannel); - // turnOff - if (removed && streamChannelRepository.isEmpty()) { - ActiveThreadCountTimerTask currentTask = currentTaskReference.get(); - if (currentTask != null) { - currentTaskReference.compareAndSet(currentTask, null); - currentTask.cancel(); - - logger.info("turn off ActiveThreadCountTimerTask."); - } - } - break; - default: - logger.info("unexpected updatedStateCode={}", updatedStateCode); - break; - } - } - } - - } - - @Override - public void close() { - if (timer != null) { - timer.cancel(); - } - } - - private class ActiveThreadCountTimerTask extends TimerTask { - - @Override - public void run() { - if (isDebug) { - logger.debug("ActiveThreadCountTimerTask started. target-streams:{}", streamChannelRepository); - } - - try { - TCmdActiveThreadCountRes activeThreadCountResponse = getActiveThreadCountResponse(); - for (ServerStreamChannel serverStreamChannel : streamChannelRepository) { - byte[] payload = SerializationUtils.serialize(activeThreadCountResponse, commandHeaderTBaseSerializerFactory, null); - if (payload != null) { - serverStreamChannel.sendData(payload); - } - } - } catch (Exception e) { - logger.warn("failed to execute ActiveThreadCountTimerTask.run method. message:{}", e.getMessage(), e); - } - } - - } - -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java deleted file mode 100644 index 1beddfd66a10..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver.service; - -import com.navercorp.pinpoint.common.util.JvmUtils; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.thrift.ThreadDumpThriftMessageConverter; -import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.ThreadDumpMetricSnapshot; -import com.navercorp.pinpoint.profiler.receiver.ProfilerRequestCommandService; -import com.navercorp.pinpoint.profiler.util.ThreadDumpUtils; -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDumpRes; -import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.apache.thrift.TBase; - -import java.lang.management.ThreadInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author Taejin Koo - */ -public class ActiveThreadDumpService implements ProfilerRequestCommandService, TBase> { - - static final String JAVA = "JAVA"; - - private final ActiveThreadDumpCoreService activeThreadDumpCoreService; - private final ThreadDumpThriftMessageConverter threadDumpThriftMessageConverter = new ThreadDumpThriftMessageConverter(); - - public ActiveThreadDumpService(ActiveThreadDumpCoreService activeThreadDumpCoreService) { - this.activeThreadDumpCoreService = activeThreadDumpCoreService; - } - - @Override - public TBase requestCommandService(TBase tBase) { - TCmdActiveThreadDump request = (TCmdActiveThreadDump) tBase; - - List activeThreadDumpList = getActiveThreadDumpList(request); - - TCmdActiveThreadDumpRes response = new TCmdActiveThreadDumpRes(); - response.setType(JAVA); - response.setSubType(JvmUtils.getType().name()); - response.setVersion(JvmUtils.getVersion().name()); - response.setThreadDumps(activeThreadDumpList); - return response; - } - - private List getActiveThreadDumpList(TCmdActiveThreadDump tRequest) { - - final ThreadDumpRequest request = ThreadDumpRequest.create(tRequest); - - Collection activeThreadDumpList = activeThreadDumpCoreService.getActiveThreadDumpList(request); - - return toTActiveThreadDump(activeThreadDumpList); - } - - - private List toTActiveThreadDump(Collection activeTraceInfoList) { - - final List result = new ArrayList(activeTraceInfoList.size()); - for (ThreadDump threadDump : activeTraceInfoList) { - TActiveThreadDump tActiveThreadDump = createTActiveThreadDump(threadDump); - result.add(tActiveThreadDump); - } - - return result; - } - - - private TActiveThreadDump createTActiveThreadDump(ThreadDump threadDump) { - final ActiveTraceSnapshot activeTraceInfo = threadDump.getActiveTraceSnapshot(); - final ThreadInfo threadInfo = threadDump.getThreadInfo(); - - final ThreadDumpMetricSnapshot threadDumpMetricSnapshot = ThreadDumpUtils.createThreadDump(threadInfo); - final TThreadDump tThreadDump = this.threadDumpThriftMessageConverter.toMessage(threadDumpMetricSnapshot); - - TActiveThreadDump activeThreadDump = new TActiveThreadDump(); - activeThreadDump.setStartTime(activeTraceInfo.getStartTime()); - activeThreadDump.setLocalTraceId(activeTraceInfo.getLocalTransactionId()); - activeThreadDump.setThreadDump(tThreadDump); - - if (activeTraceInfo.isSampled()) { - activeThreadDump.setSampled(true); - activeThreadDump.setTransactionId(activeTraceInfo.getTransactionId()); - activeThreadDump.setEntryPoint(activeTraceInfo.getEntryPoint()); - } - return activeThreadDump; - } - - @Override - public short getCommandServiceCode() { - return TCommandType.ACTIVE_THREAD_DUMP.getCode(); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java deleted file mode 100644 index 5934d450ca94..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver.service; - -import java.util.Objects; -import com.navercorp.pinpoint.common.util.JvmUtils; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.thrift.ThreadStateThriftMessageConverter; -import com.navercorp.pinpoint.profiler.receiver.ProfilerRequestCommandService; -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDumpRes; -import com.navercorp.pinpoint.thrift.dto.command.TThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TThreadState; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.apache.thrift.TBase; - -import java.lang.management.ThreadInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author Taejin Koo - */ -public class ActiveThreadLightDumpService implements ProfilerRequestCommandService, TBase> { - - private final ActiveThreadDumpCoreService activeThreadDump; - private final ThreadStateThriftMessageConverter threadStateThriftMessageConverter = new ThreadStateThriftMessageConverter(); - - public ActiveThreadLightDumpService(ActiveThreadDumpCoreService activeThreadDump) { - this.activeThreadDump = Objects.requireNonNull(activeThreadDump, "activeThreadDump"); - } - - @Override - public TBase requestCommandService(TBase tBase) { - TCmdActiveThreadLightDump request = (TCmdActiveThreadLightDump) tBase; - - List activeThreadDumpList = getActiveThreadDumpList(request); - - TCmdActiveThreadLightDumpRes response = new TCmdActiveThreadLightDumpRes(); - response.setType(ActiveThreadDumpService.JAVA); - response.setSubType(JvmUtils.getType().name()); - response.setVersion(JvmUtils.getVersion().name()); - response.setThreadDumps(activeThreadDumpList); - return response; - } - - private List getActiveThreadDumpList(TCmdActiveThreadLightDump tRequest) { - ThreadDumpRequest request = ThreadDumpRequest.create(tRequest); - - Collection activeTraceInfoList = activeThreadDump.getActiveThreadDumpList(request); - - return toTActiveThreadLightDump(activeTraceInfoList); - } - - - - private List toTActiveThreadLightDump(Collection activeTraceInfoList) { - - final List result = new ArrayList(activeTraceInfoList.size()); - - for (ThreadDump threadDump : activeTraceInfoList) { - TActiveThreadLightDump tActiveThreadDump = createActiveThreadDump(threadDump); - result.add(tActiveThreadDump); - } - - return result; - } - - - private TThreadLightDump createTThreadLightDump(ThreadInfo threadInfo) { - TThreadLightDump threadDump = new TThreadLightDump(); - threadDump.setThreadName(threadInfo.getThreadName()); - threadDump.setThreadId(threadInfo.getThreadId()); - - final TThreadState threadState = this.threadStateThriftMessageConverter.toMessage(threadInfo.getThreadState()); - threadDump.setThreadState(threadState); - return threadDump; - } - - private TActiveThreadLightDump createActiveThreadDump(ThreadDump threadDump) { - - final ActiveTraceSnapshot activeTraceInfo = threadDump.getActiveTraceSnapshot(); - final ThreadInfo threadInfo = threadDump.getThreadInfo(); - - TThreadLightDump tThreadLightDump = createTThreadLightDump(threadInfo); - - TActiveThreadLightDump activeThreadDump = new TActiveThreadLightDump(); - activeThreadDump.setStartTime(activeTraceInfo.getStartTime()); - activeThreadDump.setLocalTraceId(activeTraceInfo.getLocalTransactionId()); - activeThreadDump.setThreadDump(tThreadLightDump); - - if (activeTraceInfo.isSampled()) { - activeThreadDump.setSampled(true); - activeThreadDump.setTransactionId(activeTraceInfo.getTransactionId()); - activeThreadDump.setEntryPoint(activeTraceInfo.getEntryPoint()); - } - return activeThreadDump; - } - - @Override - public short getCommandServiceCode() { - return TCommandType.ACTIVE_THREAD_LIGHT_DUMP.getCode(); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadService.java deleted file mode 100644 index dea7c1332a34..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadService.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * * Copyright 2014 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.profiler.receiver.service; - -import com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandService; -import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceGroup; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Taejin Koo - */ -public class ActiveThreadService implements ProfilerCommandServiceGroup { - - private final List serviceList; - - public ActiveThreadService(ThriftTransportConfig thriftTransportConfig, ActiveTraceRepository activeTraceRepository) { - serviceList = new ArrayList(); - - if (!thriftTransportConfig.isTcpDataSenderCommandActiveThreadEnable()) { - return; - } - - if (thriftTransportConfig.isTcpDataSenderCommandActiveThreadCountEnable()) { - serviceList.add(new ActiveThreadCountService(activeTraceRepository)); - } - - ActiveThreadDumpCoreService activeThreadDump = new ActiveThreadDumpCoreService(activeTraceRepository); - if (thriftTransportConfig.isTcpDataSenderCommandActiveThreadLightDumpEnable()) { - serviceList.add(new ActiveThreadLightDumpService(activeThreadDump)); - } - if (thriftTransportConfig.isTcpDataSenderCommandActiveThreadDumpEnable()) { - serviceList.add(new ActiveThreadDumpService(activeThreadDump)); - } - } - - @Override - public List getCommandServiceList() { - return serviceList; - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java deleted file mode 100644 index 849c27495fcf..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver.service; - -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import com.navercorp.pinpoint.profiler.receiver.ProfilerRequestCommandService; -import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; - -/** - * @author koo.taejin - */ -public class EchoService implements ProfilerRequestCommandService, TBase> { - private final Logger logger = LogManager.getLogger(this.getClass()); - - @Override - public TBase requestCommandService(TBase tbase) { - logger.info("{} execute {}.", this, tbase); - - TCommandEcho param = (TCommandEcho) tbase; - return param; - } - - @Override - public short getCommandServiceCode() { - return TCommandType.ECHO.getCode(); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequest.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequest.java index e5cf6a357b14..96afcd15f599 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequest.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequest.java @@ -17,16 +17,14 @@ package com.navercorp.pinpoint.profiler.receiver.service; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import java.util.Objects; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDump; import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDump; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; /** @@ -47,28 +45,6 @@ public class ThreadDumpRequest { private final StackTrace stackTrace; - public static ThreadDumpRequest create(TCmdActiveThreadDump request) { - Objects.requireNonNull(request, "request"); - - final int limit = getLimit(request.getLimit()); - - final List localTransactionIdList = request.getLocalTraceIdList(); - final List threadNameList = request.getThreadNameList(); - - return new ThreadDumpRequest(StackTrace.DUMP, limit, localTransactionIdList, threadNameList); - } - - public static ThreadDumpRequest create(TCmdActiveThreadLightDump request) { - Objects.requireNonNull(request, "request"); - - int limit = getLimit(request.getLimit()); - - final List localTransactionIdList = request.getLocalTraceIdList(); - final List threadNameList = request.getThreadNameList(); - - return new ThreadDumpRequest(StackTrace.SKIP, limit, localTransactionIdList, threadNameList); - } - public static ThreadDumpRequest create(PCmdActiveThreadDump request) { Objects.requireNonNull(request, "request"); @@ -128,7 +104,7 @@ private Set newHashSet(List list) { if (CollectionUtils.isEmpty(list)) { return Collections.emptySet(); } - return new HashSet(list); + return new HashSet<>(list); } public int getLimit() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java deleted file mode 100644 index b82040069ded..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver.service; - -import com.navercorp.pinpoint.common.util.StringUtils; -import com.navercorp.pinpoint.common.util.ThreadMXBeanUtils; -import com.navercorp.pinpoint.profiler.receiver.ProfilerRequestCommandService; -import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse; -import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo; -import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TThreadDumpType; -import com.navercorp.pinpoint.thrift.dto.command.TThreadState; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.apache.thrift.TBase; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.lang.management.LockInfo; -import java.lang.management.MonitorInfo; -import java.lang.management.ThreadInfo; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * @author koo.taejin - */ -public class ThreadDumpService implements ProfilerRequestCommandService, TBase> { - - private static final Set THREAD_STATES = EnumSet.allOf(TThreadState.class); - - private final Logger logger = LogManager.getLogger(this.getClass()); - - - @Override - public TBase requestCommandService(TBase tbase) { - logger.info("{} execute {}.", this, tbase); - - TCommandThreadDump param = (TCommandThreadDump) tbase; - TThreadDumpType type = param.getType(); - - final List threadInfoList = getThreadInfos(type, param); - - final List threadDumpList = getTThreadDumpList(threadInfoList); - - TCommandThreadDumpResponse response = new TCommandThreadDumpResponse(); - response.setThreadDumps(threadDumpList); - return response; - } - - private List getTThreadDumpList(List threadInfoList) { - final List threadDumpList = new ArrayList(threadInfoList.size()); - for (ThreadInfo info : threadInfoList) { - final TThreadDump dump = toTThreadDump(info); - threadDumpList.add(dump); - } - return threadDumpList; - } - - private TThreadDump toTThreadDump(ThreadInfo info) { - TThreadDump dump = new TThreadDump(); - - dump.setThreadName(info.getThreadName()); - dump.setThreadId(info.getThreadId()); - dump.setBlockedTime(info.getBlockedTime()); - dump.setBlockedCount(info.getBlockedCount()); - dump.setWaitedTime(info.getWaitedTime()); - dump.setWaitedCount(info.getWaitedCount()); - - dump.setLockName(info.getLockName()); - dump.setLockOwnerId(info.getLockOwnerId()); - dump.setLockOwnerName(info.getLockOwnerName()); - - dump.setInNative(info.isInNative()); - dump.setSuspended(info.isSuspended()); - - dump.setThreadState(getThreadState(info)); - - StackTraceElement[] stackTraceElements = info.getStackTrace(); - for (StackTraceElement each : stackTraceElements) { - dump.addToStackTrace(each.toString()); - } - - MonitorInfo[] monitorInfos = info.getLockedMonitors(); - for (MonitorInfo each : monitorInfos) { - TMonitorInfo tMonitorInfo = new TMonitorInfo(); - - tMonitorInfo.setStackDepth(each.getLockedStackDepth()); - tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString()); - - dump.addToLockedMonitors(tMonitorInfo); - } - - LockInfo[] lockInfos = info.getLockedSynchronizers(); - for (LockInfo lockInfo : lockInfos) { - dump.addToLockedSynchronizers(lockInfo.toString()); - } - return dump; - } - - private List getThreadInfos(TThreadDumpType type, TCommandThreadDump param) { - if (TThreadDumpType.TARGET == type) { - return getThreadInfo(param.getName()); - } else if (TThreadDumpType.PENDING == type) { - return getThreadInfo(param.getPendingTimeMillis()); - } - - return Arrays.asList(getAllThreadInfo()); - } - - private TThreadState getThreadState(ThreadInfo info) { - - final String stateName = info.getThreadState().name(); - - for (TThreadState state : THREAD_STATES) { - if (state.name().equalsIgnoreCase(stateName)) { - return state; - } - } - - return null; - } - - private List getThreadInfo(String threadName) { - if (!StringUtils.hasText(threadName)) { - return Arrays.asList(getAllThreadInfo()); - } - - final List result = new ArrayList(); - for (ThreadInfo threadIno : getAllThreadInfo()) { - if (threadName.equals(threadIno.getThreadName())) { - result.add(threadIno); - } - } - - return result; - } - - // TODO : need to modify later - private List getThreadInfo(long pendingTimeMillis) { - if (pendingTimeMillis <= 0) { - return Arrays.asList(getAllThreadInfo()); - } - - final List result = new ArrayList(); - for (ThreadInfo threadInfo : getAllThreadInfo()) { - if (threadInfo.getBlockedTime() >= pendingTimeMillis) { - result.add(threadInfo); - continue; - } - - if (threadInfo.getWaitedTime() >= pendingTimeMillis) { - result.add(threadInfo); - } - } - - return result; - } - - private ThreadInfo[] getAllThreadInfo() { - ThreadInfo[] threadInfos = ThreadMXBeanUtils.dumpAllThread(); - - return threadInfos; - } - - @Override - public short getCommandServiceCode() { - return TCommandType.THREAD_DUMP.getCode(); - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EnhancedDataSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EnhancedDataSender.java deleted file mode 100644 index 34af20138029..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/EnhancedDataSender.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2018 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.profiler.sender; - -import com.navercorp.pinpoint.rpc.ResponseMessage; - -import java.util.function.BiConsumer; - - -/** - * @author emeroad - */ -public interface EnhancedDataSender extends DataSender { - - boolean request(T data); - - boolean request(T data, int retry); - - boolean request(T data, BiConsumer listener); - - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftUdpMessageSerializer.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftUdpMessageSerializer.java deleted file mode 100644 index 7f91503e994d..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/ThriftUdpMessageSerializer.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2018 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.profiler.sender; - -import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import java.util.Objects; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; -import org.apache.thrift.TBase; -import org.apache.thrift.TException; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - - -/** - * not thread safe - * @author Woonduk Kang(emeroad) - */ -public class ThriftUdpMessageSerializer implements MessageSerializer { - - public static final int UDP_MAX_PACKET_LENGTH = 65507; - - private final Logger logger = LogManager.getLogger(this.getClass()); - - // Caution. not thread safe - private final HeaderTBaseSerializer serializer; - private final int maxPacketLength; - private final MessageConverter> messageConverter; - - - public ThriftUdpMessageSerializer(MessageConverter> messageConverter, HeaderTBaseSerializer serializer) { - this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter"); - // Caution. not thread safe - this.serializer = Objects.requireNonNull(serializer, "serializer"); - this.maxPacketLength = ThriftUdpMessageSerializer.UDP_MAX_PACKET_LENGTH; - } - - // single thread only - @Override - public ByteMessage serializer(T message) { - if (message instanceof TBase) { - return serialize((TBase) message); - } - - final TBase tBase = messageConverter.toMessage(message); - if (tBase != null) { - return serialize(tBase); - } - return null; - } - - public ByteMessage serialize(TBase message) { - final TBase dto = message; - // do not copy bytes because it's single threaded - final byte[] byteMessage = serialize(this.serializer, dto); - if (byteMessage == null) { - return null; - } - if (isLimit(byteMessage.length)) { - // When packet size is greater than UDP packet size limit, it's better to discard packet than let the socket API fails. - logger.warn("discard packet. Caused:too large message. size:{}, {}", byteMessage.length, dto); - return null; - } - - return ByteMessage.wrap(byteMessage); - } - - private byte[] serialize(HeaderTBaseSerializer serializer, TBase tBase) { - try { - return serializer.serialize(tBase); - } catch (TException e) { - logger.warn("Serialize {} failed. Error:{}", tBase, e.getMessage(), e); - } - return null; - } - - @VisibleForTesting - protected boolean isLimit(int interBufferSize) { - return interBufferSize > maxPacketLength; - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderType.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderType.java deleted file mode 100644 index e2a1f97560d4..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/UdpDataSenderType.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2016 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.profiler.sender; - -/** - * @author Taejin Koo - */ -public enum UdpDataSenderType { - - OIO, - NIO - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSender.java index fb432bc80634..5e6082f1c113 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSender.java @@ -17,19 +17,18 @@ package com.navercorp.pinpoint.profiler.sender.grpc; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.client.SocketIdClientInterceptor; import com.navercorp.pinpoint.grpc.trace.AgentGrpc; import com.navercorp.pinpoint.grpc.trace.PAgentInfo; import com.navercorp.pinpoint.grpc.trace.PResult; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator; import com.navercorp.pinpoint.profiler.receiver.grpc.CommandServiceStubFactory; import com.navercorp.pinpoint.profiler.receiver.grpc.GrpcCommandService; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.rpc.ResponseMessage; import io.grpc.stub.StreamObserver; -import org.jboss.netty.buffer.ChannelBuffers; import java.util.concurrent.ScheduledExecutorService; import java.util.function.BiConsumer; @@ -37,13 +36,7 @@ /** * @author jaehong.kim */ -public class AgentGrpcDataSender extends GrpcDataSender implements EnhancedDataSender { - - static { - // preClassLoad - ChannelBuffers.buffer(2); - } - +public class AgentGrpcDataSender extends GrpcDataSender implements EnhancedDataSender { private final AgentGrpc.AgentStub agentInfoStub; private final AgentGrpc.AgentStub agentPingStub; private final GrpcCommandService grpcCommandService; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/GrpcDataSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/GrpcDataSender.java index 289d1e25ce4e..b0a8726c27f1 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/GrpcDataSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/GrpcDataSender.java @@ -16,23 +16,21 @@ package com.navercorp.pinpoint.profiler.sender.grpc; -import java.util.Objects; +import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.common.profiler.concurrent.ExecutorFactory; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger; +import com.navercorp.pinpoint.common.profiler.message.DataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.ExecutorUtils; import com.navercorp.pinpoint.grpc.ManagedChannelUtils; import com.navercorp.pinpoint.grpc.client.ChannelFactory; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.sender.DataSender; - -import com.google.protobuf.GeneratedMessageV3; - import io.grpc.ConnectivityState; import io.grpc.ManagedChannel; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSender.java index 9bffffceeced..78fbef1b2eca 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSender.java @@ -18,6 +18,8 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.MessageFormatUtils; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.trace.MetadataGrpc; @@ -25,9 +27,7 @@ import com.navercorp.pinpoint.grpc.trace.PResult; import com.navercorp.pinpoint.grpc.trace.PSqlMetaData; import com.navercorp.pinpoint.grpc.trace.PStringMetaData; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import io.grpc.stub.StreamObserver; import io.netty.util.HashedWheelTimer; import io.netty.util.Timeout; @@ -42,7 +42,7 @@ /** * @author jaehong.kim */ -public class MetadataGrpcDataSender extends GrpcDataSender implements EnhancedDataSender { +public class MetadataGrpcDataSender extends GrpcDataSender implements EnhancedDataSender { private final MetadataGrpc.MetadataStub metadataStub; private final int maxAttempts; private final int retryDelayMillis; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/PingStreamContext.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/PingStreamContext.java index ac3dc59ad6ae..55e4f5be6480 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/PingStreamContext.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/PingStreamContext.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.profiler.sender.grpc; -import java.util.Objects; import com.navercorp.pinpoint.grpc.MessageFormatUtils; import com.navercorp.pinpoint.grpc.StatusError; import com.navercorp.pinpoint.grpc.StatusErrors; @@ -25,9 +24,10 @@ import io.grpc.stub.ClientCallStreamObserver; import io.grpc.stub.ClientResponseObserver; import io.grpc.stub.StreamObserver; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.util.Objects; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -140,7 +140,7 @@ private ScheduledFuture schedule(Runnable command) { public void close() { logger.info("{} close()", streamId); - StreamUtils.close(this.requestObserver); + StreamUtils.close(this.requestObserver, this.logger); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/SpanGrpcDataSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/SpanGrpcDataSender.java index 41dfdb2b3112..ad17a75483ce 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/SpanGrpcDataSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/SpanGrpcDataSender.java @@ -19,13 +19,13 @@ import com.google.protobuf.Empty; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; import com.navercorp.pinpoint.grpc.trace.PSpanMessage; import com.navercorp.pinpoint.grpc.trace.SpanGrpc; import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.sender.grpc.stream.ClientStreamingProvider; import com.navercorp.pinpoint.profiler.sender.grpc.stream.DefaultStreamTask; import com.navercorp.pinpoint.profiler.sender.grpc.stream.StreamExecutorFactory; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StatGrpcDataSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StatGrpcDataSender.java index 3172f6a6edc5..f54d1301c80b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StatGrpcDataSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StatGrpcDataSender.java @@ -19,6 +19,7 @@ import com.google.protobuf.Empty; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.trace.PAgentStat; import com.navercorp.pinpoint.grpc.trace.PAgentStatBatch; @@ -26,7 +27,6 @@ import com.navercorp.pinpoint.grpc.trace.PCustomMetricMessage; import com.navercorp.pinpoint.grpc.trace.PStatMessage; import com.navercorp.pinpoint.grpc.trace.StatGrpc; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; import com.navercorp.pinpoint.profiler.sender.grpc.stream.ClientStreamingProvider; import com.navercorp.pinpoint.profiler.sender.grpc.stream.DefaultStreamTask; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StreamUtils.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StreamUtils.java index 1fc358877aef..f008579b7f60 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StreamUtils.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/sender/grpc/StreamUtils.java @@ -17,6 +17,8 @@ package com.navercorp.pinpoint.profiler.sender.grpc; import io.grpc.stub.StreamObserver; +import org.apache.logging.log4j.Logger; + /** * @author Woonduk Kang(emeroad) @@ -26,9 +28,15 @@ public final class StreamUtils { private StreamUtils() { } - public static void close(final StreamObserver streamObserver) { + public static void close(final StreamObserver streamObserver, Logger logger) { if (streamObserver != null) { - streamObserver.onCompleted(); + try { + streamObserver.onCompleted(); + } catch (Throwable th) { + if (logger != null) { + logger.info("StreamObserver.onCompleted error", th); + } + } } } } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/AgentInfoSenderTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/AgentInfoSenderTest.java deleted file mode 100644 index 344739359efb..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/AgentInfoSenderTest.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Copyright 2018 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.profiler; - -import com.navercorp.pinpoint.bootstrap.context.ServiceInfo; -import com.navercorp.pinpoint.common.Version; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.common.util.JvmUtils; -import com.navercorp.pinpoint.common.util.SystemPropertyKey; -import com.navercorp.pinpoint.profiler.context.DefaultServiceInfo; -import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService; -import com.navercorp.pinpoint.profiler.context.provider.JvmInformationProvider; -import com.navercorp.pinpoint.profiler.context.provider.ServerMetaDataRegistryServiceProvider; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.MetadataMessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.ThriftMessageToResultConverter; -import com.navercorp.pinpoint.profiler.metadata.MetaDataType; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.MessageSerializer; -import com.navercorp.pinpoint.profiler.sender.ResultResponse; -import com.navercorp.pinpoint.profiler.sender.TcpDataSender; -import com.navercorp.pinpoint.profiler.sender.ThriftMessageSerializer; -import com.navercorp.pinpoint.profiler.util.AgentInfoFactory; -import com.navercorp.pinpoint.rpc.PinpointSocket; -import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; -import com.navercorp.pinpoint.rpc.client.PinpointClient; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode; -import com.navercorp.pinpoint.rpc.packet.HandshakeResponseType; -import com.navercorp.pinpoint.rpc.packet.PingPayloadPacket; -import com.navercorp.pinpoint.rpc.packet.RequestPacket; -import com.navercorp.pinpoint.rpc.packet.SendPacket; -import com.navercorp.pinpoint.rpc.server.PinpointServer; -import com.navercorp.pinpoint.rpc.server.ServerMessageListener; -import com.navercorp.pinpoint.rpc.server.ServerMessageListenerFactory; -import com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor; -import com.navercorp.pinpoint.testcase.util.SocketUtils; -import com.navercorp.pinpoint.thrift.dto.TResult; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; -import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; -import org.apache.commons.lang3.RandomUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.thrift.TBase; -import org.apache.thrift.TException; -import org.awaitility.Awaitility; -import org.awaitility.core.ConditionFactory; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class AgentInfoSenderTest { - - public static final String HOST = "127.0.0.1"; - - private ConditionFactory awaitility() { - return Awaitility.await() - .pollDelay(50, TimeUnit.MILLISECONDS) - .timeout(60000, TimeUnit.MILLISECONDS); - } - - private AgentInformation agentInformation; - private ServerMetaDataRegistryService serverMetaDataRegistryService; - private AgentInfoFactory agentInfoFactory; - private MessageConverter resultResponseMessageConverter; - - @BeforeEach - public void init() { - agentInformation = createAgentInformation(); - serverMetaDataRegistryService = new ServerMetaDataRegistryServiceProvider().get(); - JvmInformation jvmInformation = new JvmInformationProvider().get(); - agentInfoFactory = new AgentInfoFactory(agentInformation, serverMetaDataRegistryService, jvmInformation); - resultResponseMessageConverter = new ThriftMessageToResultConverter(); - - } - - private TcpDataSender newTcpDataSender(PinpointClientFactory clientFactory, int port) { - MessageConverter> messageConverter - = new MetadataMessageConverter(agentInformation.getApplicationName(), agentInformation.getAgentId(), agentInformation.getStartTime()); - MessageSerializer messageSerializer = new ThriftMessageSerializer<>(messageConverter); - - return new TcpDataSender<>(this.getClass().getName(), HOST, port, clientFactory, messageSerializer); - } - - @Test - public void agentInfoShouldBeSent() { - final long agentInfoSendRetryIntervalMs = 100L; - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory clientFactory = createPinpointClientFactory(); - EnhancedDataSender dataSender = newTcpDataSender(clientFactory, bindPort); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .sendInterval(agentInfoSendRetryIntervalMs) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - try { - agentInfoSender.start(); - waitExpectedRequestCount(1, messageListener); - } finally { - closeAll(agentInfoSender, clientFactory); - testPinpointServerAcceptor.close(); - } - assertEquals(1, messageListener.getRequestCount()); - assertEquals(1, messageListener.getSuccessCount()); - } - - @Test - public void agentInfoShouldRetryUntilSuccess() { - final long agentInfoSendRetryIntervalMs = 100L; - final int maxTryPerAttempt = 3; - final int expectedTriesUntilSuccess = maxTryPerAttempt; - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory socketFactory = createPinpointClientFactory(); - EnhancedDataSender dataSender = newTcpDataSender(socketFactory, bindPort); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .maxTryPerAttempt(maxTryPerAttempt) - .sendInterval(agentInfoSendRetryIntervalMs) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - try { - agentInfoSender.start(); - waitExpectedRequestCount(expectedTriesUntilSuccess, messageListener); - } finally { - closeAll(agentInfoSender, socketFactory); - testPinpointServerAcceptor.close(); - } - assertEquals(expectedTriesUntilSuccess, messageListener.getRequestCount()); - assertEquals(1, messageListener.getSuccessCount()); - } - - @Test - public void agentInfoShouldInitiallyRetryIndefinitely() { - final long agentInfoSendRetryIntervalMs = 100L; - final int maxTryPerAttempt = 3; - final int expectedTriesUntilSuccess = maxTryPerAttempt * 5; - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory socketFactory = createPinpointClientFactory(); - EnhancedDataSender dataSender = newTcpDataSender(socketFactory, bindPort); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .maxTryPerAttempt(maxTryPerAttempt) - .sendInterval(agentInfoSendRetryIntervalMs) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - try { - agentInfoSender.start(); - waitExpectedRequestCount(expectedTriesUntilSuccess, messageListener); - } finally { - closeAll(agentInfoSender, socketFactory); - testPinpointServerAcceptor.close(); - } - assertEquals(expectedTriesUntilSuccess, messageListener.getRequestCount()); - assertEquals(1, messageListener.getSuccessCount()); - } - - @Test - public void agentInfoShouldRetryUntilAttemptsAreExhaustedWhenRefreshing() { - - final long agentInfoSendRetryIntervalMs = 1000L; - final long agentInfoSendRefreshIntervalMs = 5000L; - final int maxTryPerAttempt = 3; - final int expectedSuccessServerTries = 1; - final int expectedFailServerTries = maxTryPerAttempt; - final CountDownLatch agentReconnectLatch = new CountDownLatch(1); - - final ResponseServerMessageListenerFactory successMessageListenerFactory = new ResponseServerMessageListenerFactory(); - ResponseServerMessageListener successMessageListener = successMessageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(successMessageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - TestPinpointServerAcceptor failTestPinpointServerAcceptor = null; - - PinpointClientFactory socketFactory = createPinpointClientFactory(); - - TcpDataSender dataSender = newTcpDataSender(socketFactory, bindPort); - dataSender.addEventListener(new Consumer() { - @Override - public void accept(PinpointClient client) { - agentReconnectLatch.countDown(); - } - }); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .maxTryPerAttempt(maxTryPerAttempt) - .refreshInterval(agentInfoSendRefreshIntervalMs) - .sendInterval(agentInfoSendRetryIntervalMs) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - final ResponseServerMessageListenerFactory failMessageListenerFactory = new ResponseServerMessageListenerFactory(Integer.MAX_VALUE); - ResponseServerMessageListener failMessageListener = failMessageListenerFactory.create(); - - try { - agentInfoSender.start(); - waitExpectedRequestCount(expectedSuccessServerTries, successMessageListener); - testPinpointServerAcceptor.close(); - sleep(agentInfoSendRetryIntervalMs * maxTryPerAttempt); - - failTestPinpointServerAcceptor = new TestPinpointServerAcceptor(failMessageListenerFactory); - failTestPinpointServerAcceptor.bind(bindPort); - - // wait till agent reconnects - await(agentReconnectLatch, 3000); - waitExpectedRequestCount(expectedFailServerTries, failMessageListener); - } finally { - closeAll(agentInfoSender, socketFactory); - TestPinpointServerAcceptor.staticClose(failTestPinpointServerAcceptor); - TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor); - } - assertEquals(1, successMessageListener.getSuccessCount() + failMessageListener.getSuccessCount()); - assertEquals(expectedSuccessServerTries, successMessageListener.getRequestCount()); - assertEquals(expectedFailServerTries, failMessageListener.getRequestCount()); - } - - private boolean await(CountDownLatch agentReconnectLatch, long timeout) { - try { - return agentReconnectLatch.await(timeout, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - return false; - } - - @Test - public void agentInfoShouldBeSentOnlyOnceEvenAfterReconnect() throws Exception { - - final AtomicInteger reconnectCount = new AtomicInteger(); - final int expectedReconnectCount = 3; - final long agentInfoSendRetryIntervalMs = 100L; - final int maxTryPerAttempt = Integer.MAX_VALUE; - - final CyclicBarrier reconnectEventBarrier = new CyclicBarrier(2); - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory clientFactory = createPinpointClientFactory(); - TcpDataSender dataSender = newTcpDataSender(clientFactory, bindPort); - dataSender.addEventListener(new Consumer() { - @Override - public void accept(PinpointClient client) { - reconnectCount.incrementAndGet(); - try { - reconnectEventBarrier.await(); - } catch (Exception e) { - // just fail - throw new RuntimeException(e); - } - } - }); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .sendInterval(agentInfoSendRetryIntervalMs) - .maxTryPerAttempt(maxTryPerAttempt) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - try { - // initial connect - agentInfoSender.start(); - waitExpectedRequestCount(1, messageListener); - testPinpointServerAcceptor.close(); - // reconnect - for (int i = 0; i < expectedReconnectCount; i++) { - TestPinpointServerAcceptor reconnectPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - reconnectPinpointServerAcceptor.bind(bindPort); - - // wait for agent to reconnect - reconnectEventBarrier.await(); - // wait to see if AgentInfo is sent again (it shouldn't) - sleep(1000L); - reconnectPinpointServerAcceptor.close(); - reconnectEventBarrier.reset(); - } - } finally { - closeAll(agentInfoSender, clientFactory); - testPinpointServerAcceptor.close(); - } - assertEquals(1, messageListener.getSuccessCount()); - assertEquals(expectedReconnectCount, reconnectCount.get()); - } - - @Test - public void agentInfoShouldKeepRefreshing() { - final long agentInfoSendRetryIntervalMs = 100L; - final long agentInfoSendRefreshIntervalMs = 100L; - final int expectedRefreshCount = 5; - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory socketFactory = createPinpointClientFactory(); - EnhancedDataSender dataSender = newTcpDataSender(socketFactory, bindPort); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .refreshInterval(agentInfoSendRefreshIntervalMs) - .sendInterval(agentInfoSendRetryIntervalMs) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - try { - agentInfoSender.start(); - while (messageListener.getRequestCount() < expectedRefreshCount) { - sleep(1000L); - } - } finally { - closeAll(agentInfoSender, socketFactory); - testPinpointServerAcceptor.close(); - } - assertTrue(messageListener.getRequestCount() >= expectedRefreshCount); - assertTrue(messageListener.getSuccessCount() >= expectedRefreshCount); - } - - @Test - public void agentInfoShouldBeRefreshedOnServerMetaDataChange() { - // Given - final int expectedRequestCount = 5; - final long agentInfoSendRetryIntervalMs = 1000L; - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory clientFactory = createPinpointClientFactory(); - - EnhancedDataSender dataSender = newTcpDataSender(clientFactory, bindPort); - final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build(); - serverMetaDataRegistryService.addListener(new ServerMetaDataRegistryService.OnChangeListener() { - @Override - public void onServerMetaDataChange() { - agentInfoSender.refresh(); - } - }); - - // When - try { - for (int i = 0; i < expectedRequestCount; i++) { - serverMetaDataRegistryService.notifyListeners(); - } - - waitExpectedRequestCount(expectedRequestCount, messageListener); - } finally { - closeAll(agentInfoSender, clientFactory); - testPinpointServerAcceptor.close(); - } - // Then - assertEquals(expectedRequestCount, messageListener.getRequestCount()); - assertEquals(expectedRequestCount, messageListener.getSuccessCount()); - } - - @Test - public void agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads() { - // Given - final long agentInfoSendRetryIntervalMs = 1000L; - final int threadCount = 50; - final CountDownLatch initLatch = new CountDownLatch(threadCount); - final CountDownLatch startLatch = new CountDownLatch(1); - final CountDownLatch endLatch = new CountDownLatch(threadCount); - final ExecutorService executorService = Executors.newFixedThreadPool(threadCount); - final Queue exceptions = new ConcurrentLinkedQueue<>(); - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - int bindPort = testPinpointServerAcceptor.bind(); - - PinpointClientFactory clientFactory = createPinpointClientFactory(); - - EnhancedDataSender dataSender = newTcpDataSender(clientFactory, bindPort); - final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build(); - serverMetaDataRegistryService.addListener(new ServerMetaDataRegistryService.OnChangeListener() { - @Override - public void onServerMetaDataChange() { - agentInfoSender.refresh(); - } - }); - - // When - for (int i = 0; i < threadCount; i++) { - final String serviceName = "/name" + i; - executorService.submit(new Runnable() { - @Override - public void run() { - initLatch.countDown(); - try { - startLatch.await(); - ServiceInfo serviceInfo = new DefaultServiceInfo(serviceName, Collections.emptyList()); - serverMetaDataRegistryService.addServiceInfo(serviceInfo); - serverMetaDataRegistryService.notifyListeners(); - } catch (final Throwable t) { - exceptions.add(t); - } finally { - endLatch.countDown(); - } - } - }); - } - await(initLatch, 3000); - startLatch.countDown(); - await(endLatch, 3000); - executorService.shutdown(); - try { - waitExpectedRequestCount(threadCount, messageListener); - waitExpectedSuccessCount(threadCount, messageListener); - } finally { - closeAll(agentInfoSender, clientFactory); - testPinpointServerAcceptor.close(); - } - // Then - assertThat(exceptions).as("Failed with exceptions : " + exceptions).isEmpty(); - assertEquals(threadCount, messageListener.getRequestCount()); - assertEquals(threadCount, messageListener.getSuccessCount()); - } - - @SuppressWarnings("unused") - public void reconnectionStressTest() { - final long stressTestTime = 60 * 1000L; - final int randomMaxTime = 3000; - final long agentInfoSendRetryIntervalMs = 1000L; - final int maxTryPerAttempt = Integer.MAX_VALUE; - final int expectedTriesUntilSuccess = (int) stressTestTime / (randomMaxTime * 2) - 1; - - final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess); - ResponseServerMessageListener messageListener = messageListenerFactory.create(); - - PinpointClientFactory clientFactory = createPinpointClientFactory(); - - int availableTcpPort = SocketUtils.findAvailableTcpPort(47000); - - EnhancedDataSender dataSender = newTcpDataSender(clientFactory, availableTcpPort); - AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory) - .sendInterval(agentInfoSendRetryIntervalMs) - .maxTryPerAttempt(maxTryPerAttempt) - .setMessageConverter(resultResponseMessageConverter) - .build(); - - long startTime = System.currentTimeMillis(); - - try { - agentInfoSender.start(); - - while (System.currentTimeMillis() < startTime + stressTestTime) { - createAndDeleteServer(messageListenerFactory, Math.abs(RandomUtils.nextInt(0, randomMaxTime))); - sleep(Math.abs(RandomUtils.nextInt(0, 1000))); - } - - } finally { - closeAll(agentInfoSender, clientFactory); - } - assertEquals(1, messageListener.getSuccessCount()); - assertEquals(expectedTriesUntilSuccess, messageListener.getRequestCount()); - } - - private void createAndDeleteServer(ServerMessageListenerFactory messageListenerFactory, long waitTimeMillis) { - int availableTcpPort = SocketUtils.findAvailableTcpPort(47000); - - TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory); - try { - testPinpointServerAcceptor.bind(availableTcpPort); - sleep(waitTimeMillis); - } finally { - TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor); - } - } - - private void closeAll(AgentInfoSender agentInfoSender, PinpointClientFactory factory) { - if (agentInfoSender != null) { - agentInfoSender.stop(); - } - - if (factory != null) { - factory.release(); - } - } - - private AgentInformation createAgentInformation() { - return new DefaultAgentInformation("agentId", "agentName", "appName", false, - System.currentTimeMillis(), 1111, "hostname", "127.0.0.1", ServiceType.USER, - JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION); - } - - - private static class ResponseServerMessageListenerFactory implements ServerMessageListenerFactory { - - private final ResponseServerMessageListener responseServerMessageListener; - - public ResponseServerMessageListenerFactory() { - this(1); - } - - public ResponseServerMessageListenerFactory(int successCondition) { - this.responseServerMessageListener = new ResponseServerMessageListener(successCondition); - } - - @Override - public ResponseServerMessageListener create() { - return responseServerMessageListener; - } - - } - - private static class ResponseServerMessageListener implements ServerMessageListener { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - private final AtomicInteger requestCount; - private final AtomicInteger successCount; - - private final int successCondition; - - public ResponseServerMessageListener(int successCondition) { - this.requestCount = new AtomicInteger(); - this.successCount = new AtomicInteger(); - this.successCondition = successCondition; - } - - public int getRequestCount() { - return requestCount.get(); - } - - public int getSuccessCount() { - return successCount.get(); - } - - @Override - public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) { - logger.debug("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress()); - } - - @Override - public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) { - logger.debug("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress()); - - int requestCount = this.requestCount.incrementAndGet(); - if (requestCount < successCondition) { - return; - } - - try { - HeaderTBaseSerializer serializer = HeaderTBaseSerializerFactory.DEFAULT_FACTORY.createSerializer(); - - TResult result = new TResult(true); - byte[] resultBytes = serializer.serialize(result); - - this.successCount.incrementAndGet(); - - pinpointSocket.response(requestPacket.getRequestId(), resultBytes); - } catch (TException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Override - public HandshakeResponseCode handleHandshake(Map arg0) { - return HandshakeResponseType.Success.DUPLEX_COMMUNICATION; - } - - @Override - public void handlePing(PingPayloadPacket pingPacket, PinpointServer pinpointServer) { - logger.debug("ping received packet:{}, remote:{}", pingPacket, pinpointServer); - } - - } - - private PinpointClientFactory createPinpointClientFactory() { - PinpointClientFactory clientFactory = new DefaultPinpointClientFactory(); - clientFactory.setWriteTimeoutMillis(1000 * 3); - clientFactory.setRequestTimeoutMillis(1000 * 5); - clientFactory.setProperties(Collections.emptyMap()); - - return clientFactory; - } - - private void waitExpectedRequestCount(final int expectedRequestCount, final ResponseServerMessageListener listener) { - awaitility() - .untilAsserted(() -> assertThat(listener.getRequestCount()).isEqualTo(expectedRequestCount)); - } - - private void waitExpectedSuccessCount(final int expectedRequestCount, final ResponseServerMessageListener listener) { - awaitility() - .untilAsserted(() -> assertThat(listener.getSuccessCount()).isEqualTo(expectedRequestCount)); - } - - - private void sleep(long time) { - try { - Thread.sleep(time); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java index c05e6c2d0ce3..21d9802375cd 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java @@ -41,7 +41,7 @@ public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory modu String mockAgentName = "mockAgentName"; String mockApplicationName = "mockApplicationName"; AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, false, - config, Collections.emptyList(), Collections.emptyList()); + config, Collections.emptyList(), Collections.emptyList()); return new DefaultApplicationContext(agentOption, moduleFactory); } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockTraceContextFactory.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockTraceContextFactory.java index 42fea3fd49e4..99bcf1f82f08 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockTraceContextFactory.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockTraceContextFactory.java @@ -21,6 +21,8 @@ import com.google.inject.Module; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistryAdaptor; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.common.profiler.message.LoggingDataSender; import com.navercorp.pinpoint.profiler.AgentInformation; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.InterceptorRegistryModule; @@ -29,8 +31,6 @@ import com.navercorp.pinpoint.profiler.context.storage.LogStorageFactory; import com.navercorp.pinpoint.profiler.context.storage.StorageFactory; import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; -import com.navercorp.pinpoint.profiler.sender.LoggingDataSender; /** * @author emeroad diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/SpanEventTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/SpanEventTest.java deleted file mode 100644 index d8e741af3d3f..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/SpanEventTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2018 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.profiler.context; - -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessorV1; -import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import com.navercorp.pinpoint.thrift.dto.TSpanEvent; -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.Arrays; - -/** - * @author emeroad - */ -public class SpanEventTest { - private final Logger logger = LogManager.getLogger(this.getClass()); - private final SpanProcessor compressorV1 = new SpanProcessorV1(); - - @Test - public void testMarkStartTime() { - final DefaultTraceId traceId = new DefaultTraceId("agentId", 0, 0); - TraceRoot traceRoot = TraceRoot.remote(traceId, "agentId", System.currentTimeMillis(), 0); - - Span span = new Span(traceRoot); - span.markBeforeTime(); - - span.setElapsedTime((int) (span.getStartTime() + 10)); - logger.debug("span:{}", span); - - final SpanEvent spanEvent = new SpanEvent(); - long currentTime = System.currentTimeMillis(); - spanEvent.setStartTime(currentTime); - - spanEvent.setElapsedTime(10); - logger.debug("spanEvent:{}", spanEvent); - span.setSpanEventList(Arrays.asList(spanEvent)); - - TSpan tSpan = new TSpan(); - TSpanEvent tSpanEvent = new TSpanEvent(); - tSpan.addToSpanEventList(tSpanEvent); - compressorV1.preProcess(span, tSpan); - compressorV1.postProcess(span, tSpan); - - Assertions.assertEquals(span.getStartTime() + tSpanEvent.getStartElapsed(), spanEvent.getStartTime(), "startTime"); - Assertions.assertEquals(span.getStartTime() + tSpanEvent.getStartElapsed() + spanEvent.getElapsedTime(), spanEvent.getAfterTime(), "endTime"); - } - - @Test - public void testGetStartTime() throws Exception { - - } - - @Test - public void testMarkEndTime() throws Exception { - - } - - @Test - public void testGetEndTime() throws Exception { - - } -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java index d7f72abc2006..c2f60cdc456f 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java @@ -25,8 +25,6 @@ import com.navercorp.pinpoint.profiler.context.grpc.GrpcSpanMessageConverter; import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -37,8 +35,6 @@ */ public class GrpcSpanProcessorV2Test { - private final Logger logger = LogManager.getLogger(this.getClass()); - private SpanProcessor spanProcessorProtoV2 = new GrpcSpanProcessorV2(); private GrpcSpanMessageConverter converter = new GrpcSpanMessageConverter("agentId", (short) 1, spanProcessorProtoV2); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/SpanPostProcessorTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/SpanPostProcessorTest.java deleted file mode 100644 index 28da5c1d70c4..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/SpanPostProcessorTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2018 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.profiler.context.compress; - -import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.profiler.context.DefaultSpanChunk; -import com.navercorp.pinpoint.profiler.context.SpanChunk; -import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import com.navercorp.pinpoint.thrift.dto.TSpanEvent; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author emeroad - */ -public class SpanPostProcessorTest { - - private final String agentId = "agentId"; - private final long agentStartTime = System.currentTimeMillis(); - - @Test - public void postProcess1() { - - SpanProcessor spanChunkPostProcessor = new SpanProcessorV1(); - - TraceRoot internalTraceId = newInternalTraceId(); - TSpanChunk tSpanChunk = new TSpanChunk(); - try { - SpanChunk spanChunk = new DefaultSpanChunk(internalTraceId, new ArrayList()); - spanChunkPostProcessor.postProcess(spanChunk, tSpanChunk); - Assertions.fail(); - } catch (Exception ignored) { - } - } - - @Test - public void postProcess2() { - - SpanProcessor spanChunkPostProcessor = new SpanProcessorV1(); - - TraceRoot internalTraceId = newInternalTraceId(); - List tSpanEvents = new ArrayList(); - TSpanChunk tSpanChunk = new TSpanChunk(); - tSpanChunk.setSpanEventList(tSpanEvents); - - List spanEvents = new ArrayList(); - SpanChunk spanChunk = new DefaultSpanChunk(internalTraceId, spanEvents); - // one spanEvent - addSpanEvent(tSpanEvents, spanEvents); - spanChunkPostProcessor.postProcess(spanChunk, tSpanChunk); - - // two spanEvent - addSpanEvent(tSpanEvents, spanEvents); - spanChunkPostProcessor.postProcess(spanChunk, tSpanChunk); - - // three - addSpanEvent(tSpanEvents, spanEvents); - spanChunkPostProcessor.postProcess(spanChunk, tSpanChunk); - - } - - private void addSpanEvent(List tSpanEvents, List spanEvents) { - spanEvents.add(new SpanEvent()); - tSpanEvents.add(new TSpanEvent()); - } - - private TraceRoot newInternalTraceId() { - TraceId traceId = new DefaultTraceId(agentId, agentStartTime, 100); - return TraceRoot.remote(traceId, agentId, agentStartTime, 0); - } -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/provider/ClientFactoryProviderTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/provider/ClientFactoryProviderTest.java deleted file mode 100644 index 0f49674dfb5e..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/provider/ClientFactoryProviderTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.provider; - -import com.navercorp.pinpoint.common.util.ByteSizeUnit; -import com.navercorp.pinpoint.profiler.context.provider.thrift.AbstractClientFactoryProvider; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * @author Taejin Koo - */ -public class ClientFactoryProviderTest { - - @Test - public void getByteSizeTest() { - final int defaultSize = Integer.MAX_VALUE / 2; - - TestClientFactoryproviderTest testClientFactoryproviderTest = new TestClientFactoryproviderTest(); - int byteSize = testClientFactoryproviderTest.getByteSize("2g", defaultSize); - Assertions.assertEquals(Integer.MAX_VALUE, byteSize); - - byteSize = testClientFactoryproviderTest.getByteSize("100m", defaultSize); - Assertions.assertEquals(ByteSizeUnit.MEGA_BYTES.toBytesSizeAsInt(100), byteSize); - - byteSize = testClientFactoryproviderTest.getByteSize("-100", defaultSize); - Assertions.assertEquals(defaultSize, byteSize); - - byteSize = testClientFactoryproviderTest.getByteSize("-100m", defaultSize); - Assertions.assertEquals(defaultSize, byteSize); - } - - private static class TestClientFactoryproviderTest extends AbstractClientFactoryProvider { - - @Override - protected int getByteSize(String value, int defaultSize) { - return super.getByteSize(value, defaultSize); - } - } - -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoderTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoderTest.java deleted file mode 100644 index 176a6e7cf8cd..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/DefaultTransactionIdEncoderTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2019 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.profiler.context.thrift; - -import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.common.profiler.util.TransactionId; -import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; -import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -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.nio.ByteBuffer; -import java.util.Arrays; - -/** - * @author Woonduk Kang(emeroad) - */ -public class DefaultTransactionIdEncoderTest { - private final Logger logger = LogManager.getLogger(this.getClass()); - - public static final String DEFAULT_AGENT_ID = "defaultAgentId"; - - private final String agentId = "agentId"; - private final long agentStartTime = 11; - private final long transactionId = 1; - - private final String agentId2 = "agentId2"; - private final long agentStartTime2 = 12; - private final long transactionId2 = 2; - - private final DefaultTransactionIdEncoder transactionIdEncoder = new DefaultTransactionIdEncoder(agentId, agentStartTime); - - @Test - public void testCompressedTransactionId() { - TraceRoot traceRoot = getRootTraceId(); - TraceId traceId = traceRoot.getTraceId(); - - ByteBuffer encodeTxId = transactionIdEncoder.encodeTransactionId(traceId); - - byte[] transactionId = Arrays.copyOf(encodeTxId.array(), encodeTxId.remaining()); - TransactionId parsedTxId = TransactionIdUtils.parseTransactionId(transactionId, DEFAULT_AGENT_ID); - logger.debug("transactionId:{}", parsedTxId); - Assertions.assertEquals(DEFAULT_AGENT_ID, parsedTxId.getAgentId()); - Assertions.assertEquals(parsedTxId.getAgentStartTime(), agentStartTime); - Assertions.assertEquals(parsedTxId.getTransactionSequence(), transactionId2); - } - - @Test - public void testNormalTransactionId() { - TraceRoot traceRoot = getExternalTraceId(); - - TraceId traceId = traceRoot.getTraceId(); - ByteBuffer encodeTxId = transactionIdEncoder.encodeTransactionId(traceId); - - - byte[] transactionId = Arrays.copyOf(encodeTxId.array(), encodeTxId.remaining()); - TransactionId parsedTxId = TransactionIdUtils.parseTransactionId(transactionId, DEFAULT_AGENT_ID); - logger.debug("transactionId:{}", parsedTxId); - Assertions.assertEquals(parsedTxId.getAgentId(), agentId2); - Assertions.assertEquals(parsedTxId.getAgentStartTime(), agentStartTime2); - Assertions.assertEquals(parsedTxId.getTransactionSequence(), transactionId2); - } - - @Test - public void testDuplicateAgentId() { - TraceRoot traceRoot = getDuplicateAgentId(); - - TraceId traceId = traceRoot.getTraceId(); - ByteBuffer encodeTxId = transactionIdEncoder.encodeTransactionId(traceId); - - - byte[] transactionId = Arrays.copyOf(encodeTxId.array(), encodeTxId.remaining()); - TransactionId parsedTxId = TransactionIdUtils.parseTransactionId(transactionId, DEFAULT_AGENT_ID); - logger.debug("transactionId:{}", parsedTxId); - Assertions.assertEquals(DEFAULT_AGENT_ID, parsedTxId.getAgentId()); - Assertions.assertEquals(parsedTxId.getAgentStartTime(), agentStartTime2); - Assertions.assertEquals(parsedTxId.getTransactionSequence(), transactionId2); - } - - - private TraceRoot getRootTraceId() { - TraceId traceId = new DefaultTraceId(agentId, agentStartTime, transactionId2); - return TraceRoot.remote(traceId, agentId, agentStartTime, transactionId); - } - - private TraceRoot getExternalTraceId() { - TraceId traceId = new DefaultTraceId(agentId2, agentStartTime2, transactionId2); - return TraceRoot.remote(traceId, agentId, agentStartTime, transactionId); - } - - private TraceRoot getDuplicateAgentId() { - TraceId traceId = new DefaultTraceId(agentId, agentStartTime2, transactionId2); - return TraceRoot.remote(traceId, agentId, agentStartTime, transactionId); - } - - -} \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterTest.java deleted file mode 100644 index 690c5a430f01..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/SpanThriftMessageConverterTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2018 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.profiler.context.thrift; - -import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.common.util.IntStringValue; -import com.navercorp.pinpoint.profiler.context.Annotation; -import com.navercorp.pinpoint.profiler.context.DefaultAsyncId; -import com.navercorp.pinpoint.profiler.context.DefaultSpanChunk; -import com.navercorp.pinpoint.profiler.context.Span; -import com.navercorp.pinpoint.profiler.context.SpanChunk; -import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.profiler.context.annotation.Annotations; -import com.navercorp.pinpoint.profiler.context.compress.SpanProcessorV1; -import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; -import com.navercorp.pinpoint.profiler.context.id.Shared; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.profiler.context.id.TransactionIdEncoder; -import com.navercorp.pinpoint.profiler.util.RandomExUtils; -import com.navercorp.pinpoint.thrift.dto.TAnnotation; -import com.navercorp.pinpoint.thrift.dto.TSpan; -import com.navercorp.pinpoint.thrift.dto.TSpanChunk; -import com.navercorp.pinpoint.thrift.dto.TSpanEvent; -import org.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Woonduk Kang(emeroad) - */ -public class SpanThriftMessageConverterTest { - - private static final String APPLICATION_NAME = "app"; - private static final String AGENT_ID = "agent"; - private static final long AGENT_START_TIME = System.currentTimeMillis(); - - private final TransactionIdEncoder transactionIdEncoder = new DefaultTransactionIdEncoder(AGENT_ID, AGENT_START_TIME); - - private SpanProcessorV1 spanPostProcessor = new SpanProcessorV1(); - - private final SpanThriftMessageConverter messageConverter = new SpanThriftMessageConverter( - APPLICATION_NAME, - AGENT_ID, - AGENT_START_TIME, - ServiceType.STAND_ALONE.getCode(), - transactionIdEncoder, - spanPostProcessor - ); - - - private Span newSpan() { - final TraceId traceId = new DefaultTraceId(AGENT_ID, AGENT_START_TIME, 1L); - final TraceRoot traceRoot = TraceRoot.remote(traceId, AGENT_ID, AGENT_START_TIME, 100L); - return new Span(traceRoot); - } - - - @Test - public void buildTSpan() { - final Span span = newSpan(); - - span.setStartTime(System.currentTimeMillis()); - span.setElapsedTime(RandomExUtils.nextInt(0, 100)); - span.setAcceptorHost("acceptorHost"); - span.setExceptionInfo(new IntStringValue(RandomExUtils.nextInt(0, 100), "error")); - span.setApiId(RandomExUtils.nextInt(0, 100)); - span.setServiceType((short) RandomExUtils.nextInt(0, 100)); - span.setRemoteAddr("remoteAddr"); - span.setParentApplicationName("pApp"); - span.setParentApplicationType((short) RandomExUtils.nextInt(0, 100)); - - final TraceRoot traceRoot = span.getTraceRoot(); - Shared shared = traceRoot.getShared(); - shared.setEndPoint("endPoint"); - shared.setRpcName("rpcName"); - shared.setLoggingInfo((byte) RandomExUtils.nextInt(0, 10)); - shared.maskErrorCode(RandomExUtils.nextInt(0, 100)); - shared.setStatusCode(RandomExUtils.nextInt(0, 100)); - - span.addAnnotation(Annotations.of(1)); - span.setSpanEventList(Collections.singletonList(new SpanEvent())); - - final TSpan tSpan = messageConverter.buildTSpan(span); - - - assertEquals(span.getStartTime(), tSpan.getStartTime()); - assertEquals(span.getElapsedTime(), tSpan.getElapsed()); - assertEquals(span.getAcceptorHost(), tSpan.getAcceptorHost()); - assertEquals(span.getExceptionInfo().getIntValue(), tSpan.getExceptionInfo().getIntValue()); - assertEquals(span.getExceptionInfo().getStringValue(), tSpan.getExceptionInfo().getStringValue()); - assertEquals(span.getApiId(), tSpan.getApiId()); - assertEquals(span.getServiceType(), tSpan.getServiceType()); - assertEquals(span.getRemoteAddr(), tSpan.getRemoteAddr()); - assertEquals(span.getParentApplicationName(), tSpan.getParentApplicationName()); - assertEquals(span.getParentApplicationType(), tSpan.getParentApplicationType()); - - assertEquals(traceRoot.getTraceId().getSpanId(), tSpan.getSpanId()); - assertEquals(traceRoot.getShared().getEndPoint(), tSpan.getEndPoint()); - assertEquals(traceRoot.getShared().getRpcName(), tSpan.getRpc()); - assertEquals(traceRoot.getShared().getLoggingInfo(), tSpan.getLoggingTransactionInfo()); - assertEquals(traceRoot.getShared().getErrorCode(), tSpan.getErr()); -// TODO -// Assertions.assertEquals(traceRoot.getShared().getStatusCode(), ); - assertThat(span.getAnnotations()).hasSameSizeAs(tSpan.getAnnotations()); - assertThat(span.getSpanEventList()).hasSameSizeAs(tSpan.getSpanEventList()); - } - - - private SpanChunk newSpanChunk() { - final TraceId traceId = new DefaultTraceId(AGENT_ID, AGENT_START_TIME, 1L); - final TraceRoot traceRoot = TraceRoot.remote(traceId, AGENT_ID, AGENT_START_TIME, 100L); - return new DefaultSpanChunk(traceRoot, Collections.singletonList(new SpanEvent())); - } - - - @Test - public void buildTSpanChunk() { - final SpanChunk spanChunk = newSpanChunk(); - TraceRoot traceRoot = spanChunk.getTraceRoot(); - - TSpanChunk tSpanChunk = messageConverter.buildTSpanChunk(spanChunk); - - assertEquals(traceRoot.getTraceId().getSpanId(), tSpanChunk.getSpanId()); - assertEquals(traceRoot.getShared().getEndPoint(), tSpanChunk.getEndPoint()); - } - - - @Test - public void buildTSpanEvent() { - final long startTime = System.currentTimeMillis() - 100; - - SpanEvent spanEvent = new SpanEvent(); - spanEvent.setDepth(RandomExUtils.nextInt(0, 100)); - spanEvent.setStartTime(startTime + RandomExUtils.nextInt(0, 100)); - spanEvent.setAfterTime(spanEvent.getStartTime() + RandomExUtils.nextInt(5, 100)); - spanEvent.setDestinationId("destinationId"); - spanEvent.setSequence(RandomExUtils.nextInt(0, 100)); - spanEvent.setNextSpanId(RandomExUtils.nextInt(0, 100)); - - spanEvent.setAsyncIdObject(new DefaultAsyncId(RandomExUtils.nextInt(0, 100))); - - - spanEvent.addAnnotation(Annotations.of(1)); - - TSpanEvent tSpanEvent = messageConverter.buildTSpanEvent(spanEvent); - spanPostProcessor.postEventProcess(Collections.singletonList(spanEvent), Collections.singletonList(tSpanEvent), startTime); - - assertEquals(spanEvent.getDepth(), tSpanEvent.getDepth()); - assertEquals(spanEvent.getStartTime(), startTime + tSpanEvent.getStartElapsed()); - assertEquals(spanEvent.getAfterTime(), startTime + tSpanEvent.getStartElapsed() + tSpanEvent.getEndElapsed()); - assertEquals(spanEvent.getDestinationId(), tSpanEvent.getDestinationId()); - assertEquals(spanEvent.getSequence(), tSpanEvent.getSequence()); - assertEquals(spanEvent.getNextSpanId(), tSpanEvent.getNextSpanId()); - - assertEquals(spanEvent.getAsyncIdObject().getAsyncId(), tSpanEvent.getNextAsyncId()); - - assertThat(spanEvent.getAnnotations()).hasSameSizeAs(tSpanEvent.getAnnotations()); - } - - - @Test - public void buildTAnnotation() { - Annotation annotation = Annotations.of(RandomExUtils.nextInt(0, 100), "value"); - List> annotations = Collections.singletonList(annotation); - List tAnnotations = messageConverter.buildTAnnotation(annotations); - - TAnnotation tAnnotation = tAnnotations.get(0); - assertEquals(annotation.getKey(), tAnnotation.getKey()); - assertEquals(annotation.getValue(), tAnnotation.getValue().getStringValue()); - } - - -} \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfigTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfigTest.java deleted file mode 100644 index d28ca427ddd0..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/thrift/config/DefaultThriftTransportConfigTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.navercorp.pinpoint.profiler.context.thrift.config; - -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.io.IOException; -import java.util.Properties; - -public class DefaultThriftTransportConfigTest { - private final Logger logger = LogManager.getLogger(this.getClass()); - - @Test - public void testPlaceHolder() throws IOException { - Properties properties = new Properties(); - properties.setProperty("profiler.collector.span.ip", "${test1}"); - properties.setProperty("profiler.collector.stat.ip", "${test1}"); - properties.setProperty("profiler.collector.tcp.ip", "${test2}"); - // placeHolderValue - properties.setProperty("test1", "placeHolder1"); - properties.setProperty("test2", "placeHolder2"); - - - ThriftTransportConfig thriftTransportConfig = loadThriftTransportConfig(properties); - Assertions.assertEquals(thriftTransportConfig.getCollectorSpanServerIp(), "placeHolder1"); - Assertions.assertEquals(thriftTransportConfig.getCollectorStatServerIp(), "placeHolder1"); - Assertions.assertEquals(thriftTransportConfig.getCollectorTcpServerIp(), "placeHolder2"); - } - - - @Test - public void tcpCommandAcceptorConfigTest1() throws IOException { - Properties properties = new Properties(); - properties.put("profiler.tcpdatasender.command.accept.enable", "true"); - - ThriftTransportConfig thriftTransportConfig = loadThriftTransportConfig(properties); - Assertions.assertTrue(thriftTransportConfig.isTcpDataSenderCommandAcceptEnable()); - } - - @Test - public void tcpCommandAcceptorConfigTest2() throws IOException { - Properties properties = new Properties(); - properties.put("profiler.tcpdatasender.command.accept.enable", "true"); - - ThriftTransportConfig thriftTransportConfig = loadThriftTransportConfig(properties); - Assertions.assertTrue(thriftTransportConfig.isTcpDataSenderCommandAcceptEnable()); - } - - - private DefaultThriftTransportConfig loadThriftTransportConfig(Properties properties) { - DefaultThriftTransportConfig thriftTransportConfig = new DefaultThriftTransportConfig(); - thriftTransportConfig.read(properties); - return thriftTransportConfig; - } - - @Test - public void waterMarkConfigTest() { - Properties properties = new Properties(); - properties.setProperty("profiler.tcpdatasender.client.write.buffer.highwatermark", "6m"); - properties.setProperty("profiler.tcpdatasender.client.write.buffer.lowwatermark", "5m"); - properties.setProperty("profiler.spandatasender.write.buffer.highwatermark", "4m"); - properties.setProperty("profiler.spandatasender.write.buffer.lowwatermark", "3m"); - properties.setProperty("profiler.statdatasender.write.buffer.highwatermark", "2m"); - properties.setProperty("profiler.statdatasender.write.buffer.lowwatermark", "1m"); - - DefaultThriftTransportConfig thriftTransportConfig = new DefaultThriftTransportConfig(); - thriftTransportConfig.read(properties); - Assertions.assertEquals("6m", thriftTransportConfig.getTcpDataSenderPinpointClientWriteBufferHighWaterMark()); - Assertions.assertEquals("5m", thriftTransportConfig.getTcpDataSenderPinpointClientWriteBufferLowWaterMark()); - Assertions.assertEquals("4m", thriftTransportConfig.getSpanDataSenderWriteBufferHighWaterMark()); - Assertions.assertEquals("3m", thriftTransportConfig.getSpanDataSenderWriteBufferLowWaterMark()); - Assertions.assertEquals("2m", thriftTransportConfig.getStatDataSenderWriteBufferHighWaterMark()); - Assertions.assertEquals("1m", thriftTransportConfig.getStatDataSenderWriteBufferLowWaterMark()); - } -} \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataServiceTest.java index dca1ad6607f8..922b8d9afa0b 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataServiceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultApiMetaDataServiceTest.java @@ -17,10 +17,11 @@ package com.navercorp.pinpoint.profiler.metadata; import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.cache.IdAllocator; import com.navercorp.pinpoint.profiler.cache.SimpleCache; import com.navercorp.pinpoint.profiler.context.DefaultMethodDescriptor; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,7 +36,7 @@ public class DefaultApiMetaDataServiceTest { @Test public void cacheApi() { - EnhancedDataSender dataSender = mock(EnhancedDataSender.class); + EnhancedDataSender dataSender = mock(EnhancedDataSender.class); SimpleCache cache = new SimpleCache<>(new IdAllocator.ZigZagAllocator(1)); ApiMetaDataService apiMetaDataService = new DefaultApiMetaDataService(dataSender, cache); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataServiceTest.java index b79366cec369..8990798b5c36 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataServiceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultSqlMetaDataServiceTest.java @@ -17,9 +17,10 @@ package com.navercorp.pinpoint.profiler.metadata; import com.navercorp.pinpoint.bootstrap.context.ParsingResult; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.cache.IdAllocator; import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,7 +35,7 @@ public class DefaultSqlMetaDataServiceTest { @Test public void cacheSql() { - final EnhancedDataSender dataSender = mock(EnhancedDataSender.class); + final EnhancedDataSender dataSender = mock(EnhancedDataSender.class); SimpleCache sqlCache = new SimpleCache<>(new IdAllocator.ZigZagAllocator(), 100); final SqlMetaDataService sqlMetaDataService = new DefaultSqlMetaDataService(dataSender, sqlCache); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataServiceTest.java index 62a7f66d0a92..06fa2e538645 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataServiceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultStringMetaDataServiceTest.java @@ -16,15 +16,15 @@ package com.navercorp.pinpoint.profiler.metadata; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.cache.IdAllocator; import com.navercorp.pinpoint.profiler.cache.SimpleCache; -import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; /** @@ -34,8 +34,8 @@ public class DefaultStringMetaDataServiceTest { @Test public void cacheString() { - EnhancedDataSender dataSender = mock(EnhancedDataSender.class); - SimpleCache stringCache = new SimpleCache(new IdAllocator.ZigZagAllocator()); + EnhancedDataSender dataSender = mock(EnhancedDataSender.class); + SimpleCache stringCache = new SimpleCache<>(new IdAllocator.ZigZagAllocator()); StringMetaDataService stringMetaDataService = new DefaultStringMetaDataService(dataSender, stringCache); String str = "test"; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java index 608a140d4d16..5d559a6a9ad1 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java @@ -16,11 +16,11 @@ package com.navercorp.pinpoint.profiler.monitor; +import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshotBatch; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; -import com.navercorp.pinpoint.profiler.sender.DataSender; import org.junit.jupiter.api.Test; import org.mockito.Mockito; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java deleted file mode 100644 index 477492986134..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2018 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.profiler.receiver; - -import com.navercorp.pinpoint.profiler.receiver.service.EchoService; -import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; -import com.navercorp.pinpoint.rpc.stream.ServerStreamChannel; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.apache.thrift.TBase; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Taejin Koo - */ -public class ProfilerCommandServiceLocatorTest { - - @Test - public void throwNullTest1() { - Assertions.assertThrows(NullPointerException.class, () -> { - ProfilerCommandService commandService = null; - - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(commandService); - }); - } - - @Test - public void throwNullTest2() { - Assertions.assertThrows(NullPointerException.class, () -> { - ProfilerCommandServiceGroup commandServiceGroup = null; - - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(commandServiceGroup); - }); - } - - @Test - public void throwNullTest3() { - Assertions.assertThrows(NullPointerException.class, () -> { - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService((short) -1, null); - }); - } - - @Test - public void throwNullTest4() { - Assertions.assertThrows(NullPointerException.class, () -> { - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(TCommandType.RESULT.getCode(), null); - }); - } - - @Test - public void returnNullTest() { - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - ProfilerCommandServiceLocator commandServiceLocator = builder.build(); - - Assertions.assertNull(commandServiceLocator.getService((short) -1)); - Assertions.assertNull(commandServiceLocator.getSimpleService((short) -1)); - Assertions.assertNull(commandServiceLocator.getRequestService((short) -1)); - Assertions.assertNull(commandServiceLocator.getStreamService((short) -1)); - } - - @Test - public void basicFunctionTest1() { - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(new EchoService()); - builder.addService(new EchoService()); - DefaultProfilerCommandServiceLocator commandServiceLocator = (DefaultProfilerCommandServiceLocator) builder.build(); - - short commandEcho = TCommandType.ECHO.getCode(); - - assertThat(commandServiceLocator.getCommandServiceSize()).isEqualTo(1); - assertThat(commandServiceLocator.getCommandServiceCodes()).hasSize(1); - assertThat(commandServiceLocator.getCommandServiceCodes()).contains(commandEcho); - - Assertions.assertNotNull(commandServiceLocator.getService(commandEcho)); - Assertions.assertNotNull(commandServiceLocator.getRequestService(commandEcho)); - - Assertions.assertNull(commandServiceLocator.getSimpleService(commandEcho)); - Assertions.assertNull(commandServiceLocator.getStreamService(commandEcho)); - } - - @Test - public void basicFunctionTest2() { - ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(new MockCommandServiceGroup()); - DefaultProfilerCommandServiceLocator commandServiceLocator = (DefaultProfilerCommandServiceLocator) builder.build(); - - short commandResult = TCommandType.RESULT.getCode(); - - short commandTransfer = TCommandType.TRANSFER.getCode(); - - assertThat(commandServiceLocator.getCommandServiceSize()).isEqualTo(2); - assertThat(commandServiceLocator.getCommandServiceCodes()).hasSize(2); - assertThat(commandServiceLocator.getCommandServiceCodes()).contains(commandResult); - assertThat(commandServiceLocator.getCommandServiceCodes()).contains(commandTransfer); - - Assertions.assertNotNull(commandServiceLocator.getService(commandResult)); - Assertions.assertNotNull(commandServiceLocator.getSimpleService(commandResult)); - Assertions.assertNull(commandServiceLocator.getRequestService(commandResult)); - Assertions.assertNull(commandServiceLocator.getStreamService(commandResult)); - - Assertions.assertNotNull(commandServiceLocator.getService(commandTransfer)); - Assertions.assertNotNull(commandServiceLocator.getStreamService(commandTransfer)); - Assertions.assertNull(commandServiceLocator.getSimpleService(commandTransfer)); - Assertions.assertNull(commandServiceLocator.getRequestService(commandTransfer)); - } - - private static class MockSimpleCommandService implements ProfilerSimpleCommandService> { - - @Override - public void simpleCommandService(TBase tbase) { - - } - - @Override - public short getCommandServiceCode() { - return TCommandType.RESULT.getCode(); - } - - } - - private static class MockStreamCommandService implements ProfilerStreamCommandService> { - - @Override - public StreamCode streamCommandService(TBase tBase, ServerStreamChannel serverStreamChannel) { - return StreamCode.OK; - } - - @Override - public short getCommandServiceCode() { - return TCommandType.TRANSFER.getCode(); - } - - } - - private static class MockCommandServiceGroup implements ProfilerCommandServiceGroup { - - private static final ProfilerCommandService[] REGISTER_SERVICES = {new MockSimpleCommandService(), new MockStreamCommandService()}; - - @Override - public List getCommandServiceList() { - return Arrays.asList(REGISTER_SERVICES); - } - - } - -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpServiceTest.java deleted file mode 100644 index 5e76086ad161..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpServiceTest.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright 2019 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.profiler.receiver.service; - -import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; -import com.navercorp.pinpoint.common.util.ThreadMXBeanUtils; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.active.DefaultActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDumpRes; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.lang.management.ThreadInfo; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author Taejin Koo - */ -public class ActiveThreadDumpServiceTest { - - private static final int CREATE_SIZE = 10; - - private static final long DEFAULT_TIME_MILLIS = System.currentTimeMillis() - 1000000; - private static final long TIME_DIFF_INTERVAL = 100; - private static final long JOB_TIMEOUT = 1000 * 10; - - private final AtomicInteger idGenerator = new AtomicInteger(); - private final PinpointThreadFactory pinpointThreadFactory = new PinpointThreadFactory(this.getClass().getSimpleName()); - - private final WaitingJobListFactory waitingJobListFactory = new WaitingJobListFactory(); - - @AfterEach - public void tearDown() throws Exception { - waitingJobListFactory.close(); - } - - @Test - public void basicFunctionTest1() { - - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, JOB_TIMEOUT); - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - ActiveThreadDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadDumpRes response = (TCmdActiveThreadDumpRes) service.requestCommandService(createRequest(0, null, null)); - - Assertions.assertEquals(CREATE_SIZE, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest2() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, 1000 * 3); - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - TCmdActiveThreadDump tCmdActiveThreadDump = createRequest(0, null, Collections.singletonList(1L)); - - ActiveThreadDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadDumpRes response = (TCmdActiveThreadDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(1, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest3() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, 1000 * 3); - - int targetThreadNameSize = 3; - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - List threadNameList = extractThreadNameList(activeTraceInfoList, targetThreadNameSize); - TCmdActiveThreadDump tCmdActiveThreadDump = createRequest(0, threadNameList, null); - - ActiveThreadDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadDumpRes response = (TCmdActiveThreadDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(3, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest4() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, 1000 * 3); - - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - List copied = shuffle(activeTraceInfoList); - - int targetThreadNameSize = 3; - List threadNameList = extractThreadNameList(copied.subList(0, targetThreadNameSize), targetThreadNameSize); - - int targetTraceIdSize = 3; - List localTraceIdList = extractLocalTraceIdList(copied.subList(targetThreadNameSize, CREATE_SIZE), targetTraceIdSize); - TCmdActiveThreadDump tCmdActiveThreadDump = createRequest(0, threadNameList, localTraceIdList); - - ActiveThreadDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadDumpRes response = (TCmdActiveThreadDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(targetThreadNameSize + targetTraceIdSize, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest5() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, 1000 * 3); - - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - int limit = 3; - List oldTimeList = getOldTimeList(limit); - - TCmdActiveThreadDump tCmdActiveThreadDump = createRequest(limit, null, null); - - ActiveThreadDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadDumpRes response = (TCmdActiveThreadDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(limit, response.getThreadDumpsSize()); - - for (TActiveThreadDump dump : response.getThreadDumps()) { - assertThat(oldTimeList).contains(dump.getStartTime()); - } - - } - - - private List createMockActiveTraceInfoList(int createActiveTraceRepositorySize, long currentTimeMillis, long diff, List waitingJobList) { - List activeTraceInfoList = new ArrayList<>(createActiveTraceRepositorySize); - for (int i = 0; i < createActiveTraceRepositorySize; i++) { - ActiveTraceSnapshot activeTraceInfo = createActiveTraceInfo(currentTimeMillis + (diff * i), waitingJobList.get(i)); - activeTraceInfoList.add(activeTraceInfo); - } - return activeTraceInfoList; - } - - private ActiveTraceSnapshot createActiveTraceInfo(long startTime, Runnable runnable) { - Thread thread = pinpointThreadFactory.newThread(runnable); - thread.start(); - long threadId = thread.getId(); - - int id = idGenerator.incrementAndGet(); - LocalTraceRoot traceRoot = TraceRoot.local("agentId-" + id, startTime, id); - traceRoot.getShared().setThreadId(threadId); - - return DefaultActiveTraceSnapshot.of(traceRoot); - } - - private List getOldTimeList(int maxCount) { - List startTimeMillisList = new ArrayList<>(maxCount); - for (int i = 0; i < maxCount; i++) { - startTimeMillisList.add(DEFAULT_TIME_MILLIS + (TIME_DIFF_INTERVAL * i)); - } - return startTimeMillisList; - } - - private List extractThreadNameList(List activeTraceInfoList, int size) { - List copied = shuffle(activeTraceInfoList); - - List threadNameList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - - final ActiveTraceSnapshot activeTraceSnapshot = copied.get(i); - ThreadInfo thread = ThreadMXBeanUtils.getThreadInfo(activeTraceSnapshot.getThreadId()); - threadNameList.add(thread.getThreadName()); - } - - return threadNameList; - } - - private List extractLocalTraceIdList(List activeTraceInfoList, int size) { - List copied = shuffle(activeTraceInfoList); - - List localTraceIdList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - localTraceIdList.add(copied.get(i).getLocalTransactionId()); - } - - return localTraceIdList; - } - - private List shuffle(List list) { - List copied = new ArrayList<>(list); - Collections.shuffle(copied, ThreadLocalRandom.current()); - return copied; - } - - - private ActiveThreadDumpService createService(List activeTraceInfoList) { - ActiveTraceRepository activeTraceRepository = mock(ActiveTraceRepository.class); - when(activeTraceRepository.snapshot()).thenReturn(activeTraceInfoList); - - ActiveThreadDumpCoreService activeThreadDump = new ActiveThreadDumpCoreService(activeTraceRepository); - return new ActiveThreadDumpService(activeThreadDump); - } - - - private TCmdActiveThreadDump createRequest(int limit, List threadNameList, List localTraceIdList) { - TCmdActiveThreadDump request = new TCmdActiveThreadDump(); - if (limit > 0) { - request.setLimit(limit); - } - if (threadNameList != null) { - request.setThreadNameList(threadNameList); - } - if (localTraceIdList != null) { - request.setLocalTraceIdList(localTraceIdList); - } - return request; - } - - -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpServiceTest.java deleted file mode 100644 index b95e47aad2de..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpServiceTest.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2019 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.profiler.receiver.service; - -import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; -import com.navercorp.pinpoint.common.util.CollectionUtils; -import com.navercorp.pinpoint.common.util.ThreadMXBeanUtils; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.active.DefaultActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDump; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDumpRes; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.lang.management.ThreadInfo; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author Taejin Koo - */ -public class ActiveThreadLightDumpServiceTest { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - private static final int CREATE_SIZE = 10; - - private static final long DEFAULT_TIME_MILLIS = System.currentTimeMillis() - 1000000; - private static final long TIME_DIFF_INTERVAL = 100; - private static final long JOB_TIMEOUT = 1000 * 10; - - private final AtomicInteger idGenerator = new AtomicInteger(); - private final PinpointThreadFactory pinpointThreadFactory = new PinpointThreadFactory(this.getClass().getSimpleName()); - - private final WaitingJobListFactory waitingJobListFactory = new WaitingJobListFactory(); - - - @AfterEach - public void tearDown() throws Exception { - waitingJobListFactory.close(); - } - - @Test - public void basicFunctionTest1() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, JOB_TIMEOUT); - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - ActiveThreadLightDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadLightDumpRes response = (TCmdActiveThreadLightDumpRes) service.requestCommandService(createRequest(0, null, null)); - - Assertions.assertEquals(CREATE_SIZE, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest2() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, JOB_TIMEOUT); - - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - TCmdActiveThreadLightDump tCmdActiveThreadDump = createRequest(0, null, Collections.singletonList(1L)); - - ActiveThreadLightDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadLightDumpRes response = (TCmdActiveThreadLightDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(1, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest3() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, JOB_TIMEOUT); - - int targetThreadNameSize = 3; - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - List threadNameList = extractThreadNameList(activeTraceInfoList, targetThreadNameSize); - TCmdActiveThreadLightDump tCmdActiveThreadDump = createRequest(0, threadNameList, null); - - ActiveThreadLightDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadLightDumpRes response = (TCmdActiveThreadLightDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(3, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest4() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, JOB_TIMEOUT); - - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - List activeTraceSnapshotList = shuffle(activeTraceInfoList); - - int targetThreadNameSize = 3; - List threadNameList = extractThreadNameList(activeTraceSnapshotList.subList(0, targetThreadNameSize), targetThreadNameSize); - - int targetTraceIdSize = 3; - List localTraceIdList = extractLocalTraceIdList(activeTraceSnapshotList.subList(targetThreadNameSize, CREATE_SIZE), targetTraceIdSize); - TCmdActiveThreadLightDump tCmdActiveThreadDump = createRequest(0, threadNameList, localTraceIdList); - - ActiveThreadLightDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadLightDumpRes response = (TCmdActiveThreadLightDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(targetThreadNameSize + targetTraceIdSize, response.getThreadDumpsSize()); - - } - - @Test - public void basicFunctionTest5() { - List waitingJobList = this.waitingJobListFactory.createList(CREATE_SIZE, JOB_TIMEOUT); - - - List activeTraceInfoList = createMockActiveTraceInfoList(CREATE_SIZE, DEFAULT_TIME_MILLIS, TIME_DIFF_INTERVAL, waitingJobList); - - int limit = 3; - List oldTimeList = getOldTimeList(limit); - - TCmdActiveThreadLightDump tCmdActiveThreadDump = createRequest(limit, null, null); - - ActiveThreadLightDumpService service = createService(activeTraceInfoList); - TCmdActiveThreadLightDumpRes response = (TCmdActiveThreadLightDumpRes) service.requestCommandService(tCmdActiveThreadDump); - - Assertions.assertEquals(limit, response.getThreadDumpsSize()); - - for (TActiveThreadLightDump dump : response.getThreadDumps()) { - assertThat(oldTimeList).contains(dump.getStartTime()); - } - - } - - - private List createMockActiveTraceInfoList(int createActiveTraceRepositorySize, long currentTimeMillis, long diff, List waitingJobList) { - List activeTraceInfoList = new ArrayList<>(createActiveTraceRepositorySize); - for (int i = 0; i < createActiveTraceRepositorySize; i++) { - ActiveTraceSnapshot activeTraceInfo = createActiveTraceInfo(currentTimeMillis + (diff * i), waitingJobList.get(i)); - activeTraceInfoList.add(activeTraceInfo); - } - return activeTraceInfoList; - } - - private ActiveTraceSnapshot createActiveTraceInfo(long startTime, Runnable runnable) { - Thread thread = pinpointThreadFactory.newThread(runnable); - thread.start(); - long threadId = thread.getId(); - - int id = idGenerator.incrementAndGet(); - LocalTraceRoot traceRoot = TraceRoot.local("agentId-" + id, startTime, id); - traceRoot.getShared().setThreadId(threadId); - - return DefaultActiveTraceSnapshot.of(traceRoot); - } - - private List getOldTimeList(int maxCount) { - List startTimeMillisList = new ArrayList<>(maxCount); - for (int i = 0; i < maxCount; i++) { - startTimeMillisList.add(DEFAULT_TIME_MILLIS + (TIME_DIFF_INTERVAL * i)); - } - return startTimeMillisList; - } - - private List extractThreadNameList(List activeTraceInfoList, int size) { - List activeTraceSnapshotList = shuffle(activeTraceInfoList); - - List threadNameList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - final ActiveTraceSnapshot activeTraceSnapshot = activeTraceSnapshotList.get(i); - final long threadId = activeTraceSnapshot.getThreadId(); - ThreadInfo thread = ThreadMXBeanUtils.getThreadInfo(threadId); - threadNameList.add(thread.getThreadName()); - } - - return threadNameList; - } - - private List extractLocalTraceIdList(List activeTraceInfoList, int size) { - List activeTraceSnapshotList = shuffle(activeTraceInfoList); - - List localTraceIdList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - localTraceIdList.add(activeTraceSnapshotList.get(i).getLocalTransactionId()); - } - - return localTraceIdList; - } - - private List shuffle(List list) { - List result = new ArrayList<>(list); - Collections.shuffle(result, ThreadLocalRandom.current()); - return result; - } - - private ActiveThreadLightDumpService createService(List activeTraceInfoList) { - ActiveTraceRepository activeTraceRepository = mock(ActiveTraceRepository.class); - when(activeTraceRepository.snapshot()).thenReturn(activeTraceInfoList); - - ActiveThreadDumpCoreService activeThreadDump = new ActiveThreadDumpCoreService(activeTraceRepository); - return new ActiveThreadLightDumpService(activeThreadDump); - } - - private TCmdActiveThreadLightDump createRequest(int limit, List threadNameList, List localTraceIdList) { - TCmdActiveThreadLightDump request = new TCmdActiveThreadLightDump(); - if (limit > 0) { - request.setLimit(limit); - } - if (CollectionUtils.hasLength(threadNameList)) { - request.setThreadNameList(threadNameList); - } - if (CollectionUtils.hasLength(localTraceIdList)) { - request.setLocalTraceIdList(localTraceIdList); - } - return request; - } - -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadServiceTest.java deleted file mode 100644 index 39610ff9ae23..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadServiceTest.java +++ /dev/null @@ -1,98 +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. - */ - -package com.navercorp.pinpoint.profiler.receiver.service; - -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.active.DefaultActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeCollector; -import com.navercorp.pinpoint.profiler.monitor.metric.response.ReuseResponseTimeCollector; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCount; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes; - -import org.apache.thrift.TBase; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Taejin Koo - */ -public class ActiveThreadServiceTest { - - private long activeTraceId = 0; - - private static final int FAST_COUNT = 1; - private static final long FAST_EXECUTION_TIME = 500; - - private static final int NORMAL_COUNT = 2; - private static final long NORMAL_EXECUTION_TIME = 1500; - - private static final int SLOW_COUNT = 3; - private static final long SLOW_EXECUTION_TIME = 3500; - - private static final int VERY_SLOW_COUNT = 4; - private static final long VERY_SLOW_EXECUTION_TIME = 5500; - - - @Test - public void serviceTest1() { - ResponseTimeCollector responseTimeCollector = new ReuseResponseTimeCollector(); - ActiveTraceRepository activeTraceRepository = new DefaultActiveTraceRepository(responseTimeCollector); - - addActiveTrace(activeTraceRepository, FAST_EXECUTION_TIME, FAST_COUNT); - addActiveTrace(activeTraceRepository, NORMAL_EXECUTION_TIME, NORMAL_COUNT); - addActiveTrace(activeTraceRepository, SLOW_EXECUTION_TIME, SLOW_COUNT); - addActiveTrace(activeTraceRepository, VERY_SLOW_EXECUTION_TIME, VERY_SLOW_COUNT); - - try (ActiveThreadCountService service = new ActiveThreadCountService(activeTraceRepository)) { - TBase tBase = service.requestCommandService(new TCmdActiveThreadCount()); - if (tBase instanceof TCmdActiveThreadCountRes) { - List activeThreadCount = ((TCmdActiveThreadCountRes) tBase).getActiveThreadCount(); - assertThat(activeThreadCount.get(0)).isEqualTo(FAST_COUNT); - assertThat(activeThreadCount.get(1)).isEqualTo(NORMAL_COUNT); - assertThat(activeThreadCount.get(2)).isEqualTo(SLOW_COUNT); - assertThat(activeThreadCount.get(3)).isEqualTo(VERY_SLOW_COUNT); - } else { - Assertions.fail(); - } - } - } - - private void addActiveTrace(ActiveTraceRepository activeTraceRepository, long executionTime, int addCount) { - for (int i = 0; i < addCount; i++) { - TraceRoot traceRoot = createTraceRoot(executionTime); - activeTraceRepository.register(traceRoot); - } - } - - private TraceRoot createTraceRoot(long executionTime) { - TraceRoot traceRoot = Mockito.mock(TraceRoot.class); - Mockito.when(traceRoot.getTraceStartTime()).thenReturn(System.currentTimeMillis() - executionTime); - Mockito.when(traceRoot.getLocalTransactionId()).thenReturn(nextLocalTransactionId()); - return traceRoot; - } - - private long nextLocalTransactionId() { - return activeTraceId++; - } - -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/LimitedListTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/LimitedListTest.java deleted file mode 100644 index feb702eb3d97..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/LimitedListTest.java +++ /dev/null @@ -1,118 +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. - */ - -package com.navercorp.pinpoint.profiler.receiver.service; - -import com.navercorp.pinpoint.profiler.context.active.ActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.active.DefaultActiveTraceSnapshot; -import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -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.lang.management.ThreadInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import static org.mockito.Mockito.mock; - -/** - * @author Woonduk Kang(emeroad) - */ -public class LimitedListTest { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - - @Test - public void testMaxSize() { - Comparator threadDump = ThreadDumpComparator.INSTANCE.reversed(); - - final int maxSize = 10; - Collection limitedList = new LimitedList<>(maxSize, threadDump); - - final int id = 100; - final long startTime = System.currentTimeMillis(); - final long threadId = 1000; - - logger.debug("startTime:{}", startTime); - final List testData = newTestData(id, startTime, threadId, maxSize * 2); - final long lastTime = getLastObject(testData).getActiveTraceSnapshot().getStartTime(); - - logger.debug("addAll "); - limitedList.addAll(testData); - - logger.debug("size:{}", limitedList.size()); - for (ThreadDump activeTraceSnapshot : limitedList) { - logger.debug("priorityQueue:{}", activeTraceSnapshot); - } - - List sortedList = new ArrayList<>(limitedList); - sortedList.sort(threadDump); - for (ThreadDump activeTraceSnapshot : sortedList) { - logger.debug("poll:{}", activeTraceSnapshot); - } - - ThreadDump last = getLastObject(sortedList); - logger.debug("last pool:{}", last); - logger.debug("poll.startTime:{}", last.getActiveTraceSnapshot().getStartTime()); - logger.debug("startTime:{}", lastTime); - Assertions.assertEquals(last.getActiveTraceSnapshot().getStartTime(), startTime); - - } - - private T getLastObject(List testData) { - int lastIndex = getLastIndex(testData); - return testData.get(lastIndex); - } - - private int getLastIndex(List testData) { - return testData.size() - 1; - } - - private List newTestData(int localTransactionId, long startTime, long threadId, int size) { - - List result = new ArrayList<>(); - for (int i = 0; i < size; i++) { - LocalTraceRoot traceRoot = TraceRoot.local("agent-" + localTransactionId, startTime, localTransactionId); - traceRoot.getShared().setThreadId(threadId); - - ActiveTraceSnapshot activeTraceSnapshot = DefaultActiveTraceSnapshot.of(traceRoot); - ThreadInfo threadInfo = mock(ThreadInfo.class); - ThreadDump threadDump = new ThreadDump(activeTraceSnapshot, threadInfo); - - threadId++; - localTransactionId++; - startTime++; - result.add(threadDump); - } - - for (ThreadDump threadDump : result) { - logger.debug("newTestData:{}", threadDump); - } - - Collections.shuffle(result); - - return result; - } - - -} \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequestTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequestTest.java deleted file mode 100644 index c6f0d6e2e3d6..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpRequestTest.java +++ /dev/null @@ -1,111 +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. - */ - -package com.navercorp.pinpoint.profiler.receiver.service; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.List; - -/** - * @author Woonduk Kang(emeroad) - */ -public class ThreadDumpRequestTest { - - - @Test - public void getLimit() { - final int maxThreadDumpLimit = ThreadDumpRequest.MAX_THREAD_DUMP_LIMIT; - Assertions.assertEquals(ThreadDumpRequest.getLimit(-1), maxThreadDumpLimit); - Assertions.assertEquals(ThreadDumpRequest.getLimit(0), maxThreadDumpLimit); - Assertions.assertEquals(ThreadDumpRequest.getLimit(1000), 1000); - Assertions.assertEquals(ThreadDumpRequest.getLimit(maxThreadDumpLimit + 100), maxThreadDumpLimit); - } - - - @Test - public void enableTransactionId() { - - List localTransactionIdList = Collections.singletonList(1L); - List threadNameList = Collections.emptyList(); - ThreadDumpRequest request = new ThreadDumpRequest(StackTrace.DUMP, 10, localTransactionIdList, threadNameList); - Assertions.assertTrue(request.isEnableFilter()); - Assertions.assertTrue(request.isEnableLocalTransactionIdFilter()); - Assertions.assertFalse(request.isEnableThreadNameFilter()); - - Assertions.assertTrue(request.findLocalTransactionId(1)); - Assertions.assertFalse(request.findLocalTransactionId(2)); - - Assertions.assertFalse(request.findThreadName("a")); - Assertions.assertFalse(request.findThreadName("b")); - } - - @Test - public void enableThreadDump() { - - List localTransactionIdList = Collections.emptyList(); - List threadNameList = Collections.singletonList("a"); - - ThreadDumpRequest request = new ThreadDumpRequest(StackTrace.DUMP, 10, localTransactionIdList, threadNameList); - Assertions.assertTrue(request.isEnableFilter()); - Assertions.assertFalse(request.isEnableLocalTransactionIdFilter()); - Assertions.assertTrue(request.isEnableThreadNameFilter()); - - Assertions.assertFalse(request.findLocalTransactionId(1)); - Assertions.assertFalse(request.findLocalTransactionId(2)); - - Assertions.assertTrue(request.findThreadName("a")); - Assertions.assertFalse(request.findThreadName("b")); - } - - - @Test - public void filter() { - - List localTransactionIdList = Collections.singletonList(1L); - List threadNameList = Collections.singletonList("a"); - ThreadDumpRequest request = new ThreadDumpRequest(StackTrace.DUMP, 10, localTransactionIdList, threadNameList); - Assertions.assertTrue(request.isEnableFilter()); - Assertions.assertTrue(request.isEnableLocalTransactionIdFilter()); - Assertions.assertTrue(request.isEnableThreadNameFilter()); - - Assertions.assertTrue(request.findLocalTransactionId(1)); - Assertions.assertFalse(request.findLocalTransactionId(2)); - - Assertions.assertTrue(request.findThreadName("a")); - Assertions.assertFalse(request.findThreadName("b")); - } - - @Test - public void all() { - - List localTransactionIdList = Collections.emptyList(); - List threadNameList = Collections.emptyList(); - - ThreadDumpRequest request = new ThreadDumpRequest(StackTrace.DUMP, 10, localTransactionIdList, threadNameList); - Assertions.assertFalse(request.isEnableFilter()); - Assertions.assertFalse(request.isEnableLocalTransactionIdFilter()); - Assertions.assertFalse(request.isEnableThreadNameFilter()); - - Assertions.assertFalse(request.findLocalTransactionId(1)); - Assertions.assertFalse(request.findLocalTransactionId(2)); - - Assertions.assertFalse(request.findThreadName("a")); - Assertions.assertFalse(request.findThreadName("b")); - } -} \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJob.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJob.java deleted file mode 100644 index 668f8bf08512..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJob.java +++ /dev/null @@ -1,45 +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. - */ - -package com.navercorp.pinpoint.profiler.receiver.service; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * @author Woonduk Kang(emeroad) - */ -class WaitingJob implements Runnable { - private final CountDownLatch latch = new CountDownLatch(1); - private final long timeIntervalMillis; - - public WaitingJob(long timeIntervalMillis) { - this.timeIntervalMillis = timeIntervalMillis; - } - - @Override - public void run() { - try { - latch.await(timeIntervalMillis, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - - public void close() { - latch.countDown(); - } -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJobListFactory.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJobListFactory.java deleted file mode 100644 index f160cb5e1e6f..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/service/WaitingJobListFactory.java +++ /dev/null @@ -1,53 +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. - */ - -package com.navercorp.pinpoint.profiler.receiver.service; - -import com.navercorp.pinpoint.common.util.Assert; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Woonduk Kang(emeroad) - */ -class WaitingJobListFactory { - - private final List waitingJobList = new ArrayList(); - - - public List createList(int size, long timeout) { - Assert.state(waitingJobList.isEmpty(), "WaitingJob not close"); - - for (int i = 0; i < size; i++) { - WaitingJob latchJob = new WaitingJob(timeout); - waitingJobList.add(latchJob); - } - return waitingJobList; - } - - - public void close() { - if (this.waitingJobList.isEmpty()) { - return; - } - - for (WaitingJob waitingJob : waitingJobList) { - waitingJob.close(); - } - waitingJobList.clear(); - } -} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/CountingDataSender.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/CountingDataSender.java index cb0103462308..8bfe0adabe00 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/CountingDataSender.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/CountingDataSender.java @@ -16,10 +16,11 @@ package com.navercorp.pinpoint.profiler.sender; +import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.profiler.context.Span; import com.navercorp.pinpoint.profiler.context.SpanChunk; import com.navercorp.pinpoint.profiler.context.SpanType; -import com.navercorp.pinpoint.rpc.ResponseMessage; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; @@ -27,7 +28,7 @@ /** * @author emeroad */ -public class CountingDataSender implements EnhancedDataSender { +public class CountingDataSender implements EnhancedDataSender { private final AtomicInteger requestCounter = new AtomicInteger(); private final AtomicInteger requestRetryCounter = new AtomicInteger(); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java index 1357986ba5b9..9d4b4ac5e919 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java @@ -19,13 +19,14 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.bootstrap.context.ServerMetaData; import com.navercorp.pinpoint.bootstrap.context.ServiceInfo; +import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.AgentHeaderFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder; -import com.navercorp.pinpoint.grpc.client.config.ClientOption; import com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder; import com.navercorp.pinpoint.grpc.client.HeaderFactory; +import com.navercorp.pinpoint.grpc.client.config.ClientOption; import com.navercorp.pinpoint.profiler.AgentInformation; import com.navercorp.pinpoint.profiler.DefaultAgentInformation; import com.navercorp.pinpoint.profiler.JvmInformation; @@ -33,7 +34,6 @@ import com.navercorp.pinpoint.profiler.context.grpc.GrpcMetadataMessageConverter; import com.navercorp.pinpoint.profiler.context.provider.grpc.DnsExecutorServiceProvider; import com.navercorp.pinpoint.profiler.context.provider.grpc.GrpcNameResolverProvider; -import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; import com.navercorp.pinpoint.profiler.metadata.AgentInfo; import com.navercorp.pinpoint.profiler.metadata.MetaDataType; import com.navercorp.pinpoint.profiler.monitor.metric.gc.JvmGcType; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/ThreadDumpUtilsTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/ThreadDumpUtilsTest.java deleted file mode 100644 index 9cb40a37cdc2..000000000000 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/ThreadDumpUtilsTest.java +++ /dev/null @@ -1,57 +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. - */ - -package com.navercorp.pinpoint.profiler.util; - -import com.navercorp.pinpoint.profiler.context.thrift.ThreadStateThriftMessageConverter; -import com.navercorp.pinpoint.thrift.dto.command.TThreadState; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * @author Woonduk Kang(emeroad) - */ -public class ThreadDumpUtilsTest { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - - @Test - public void toTThreadState() { - ThreadStateThriftMessageConverter threadStateThriftMessageConverter = new ThreadStateThriftMessageConverter(); - - TThreadState newState = threadStateThriftMessageConverter.toMessage(Thread.State.NEW); - Assertions.assertEquals(newState, TThreadState.NEW); - - TThreadState runnable = threadStateThriftMessageConverter.toMessage(Thread.State.RUNNABLE); - Assertions.assertEquals(runnable, TThreadState.RUNNABLE); - - TThreadState blocked = threadStateThriftMessageConverter.toMessage(Thread.State.BLOCKED); - Assertions.assertEquals(blocked, TThreadState.BLOCKED); - - - TThreadState waiting = threadStateThriftMessageConverter.toMessage(Thread.State.WAITING); - Assertions.assertEquals(waiting, TThreadState.WAITING); - - TThreadState timedWaiting = threadStateThriftMessageConverter.toMessage(Thread.State.TIMED_WAITING); - Assertions.assertEquals(timedWaiting, TThreadState.TIMED_WAITING); - - TThreadState terminated = threadStateThriftMessageConverter.toMessage(Thread.State.TERMINATED); - Assertions.assertEquals(terminated, TThreadState.TERMINATED); - } -} \ No newline at end of file diff --git a/realtime/realtime-collector/src/main/java/com/navercorp/pinpoint/realtime/collector/service/ClusterAgentCommandService.java b/realtime/realtime-collector/src/main/java/com/navercorp/pinpoint/realtime/collector/service/ClusterAgentCommandService.java index 54878a900c71..dd729829814e 100644 --- a/realtime/realtime-collector/src/main/java/com/navercorp/pinpoint/realtime/collector/service/ClusterAgentCommandService.java +++ b/realtime/realtime-collector/src/main/java/com/navercorp/pinpoint/realtime/collector/service/ClusterAgentCommandService.java @@ -20,9 +20,9 @@ import com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection; import com.navercorp.pinpoint.collector.cluster.route.StreamRouteHandler; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.realtime.util.ScheduleUtil; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.packet.stream.StreamClosePacket; import com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket; import com.navercorp.pinpoint.rpc.server.PinpointServer; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java deleted file mode 100644 index 487368817335..000000000000 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2014 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.rpc; - -import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import com.navercorp.pinpoint.rpc.client.PinpointClient; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor; - -/** - * @author emeroad - */ -public final class ClassPreLoader { - - - public static void preload() { - try { - preload(65535); - } catch (Exception ignored) { - // skip - } - } - - public static void preload(int port) { - PinpointServerAcceptor serverAcceptor = null; - PinpointClient client = null; - PinpointClientFactory clientFactory = null; - try { - serverAcceptor = new PinpointServerAcceptor(); - serverAcceptor.bind("127.0.0.1", port); - - clientFactory = new DefaultPinpointClientFactory(); - client = clientFactory.connect("127.0.0.1", port); - client.sendSync(new byte[0]); - - - } catch (Exception ex) { - - System.err.print("preLoad error Caused:" + ex.getMessage()); - ex.printStackTrace(); - - final Logger logger = LogManager.getLogger(ClassPreLoader.class); - logger.warn("preLoad error Caused:{}", ex.getMessage(), ex); - if (ex instanceof PinpointSocketException) { - throw (PinpointSocketException)ex; - } else { - throw new PinpointSocketException(ex.getMessage(), ex); - } - } finally { - if (client != null) { - try { - client.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - if(clientFactory != null) { - try { - clientFactory.release(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (serverAcceptor != null) { - try { - serverAcceptor.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - } - } - -} diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/PinpointSocket.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/PinpointSocket.java index 0d98eafa42f2..7fda2d53592f 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/PinpointSocket.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/PinpointSocket.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.rpc; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.cluster.ClusterOption; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannel; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannelEventHandler; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClient.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClient.java index 3e3a98f0e463..0ece6bfe4605 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClient.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClient.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.rpc.client; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.cluster.ClusterOption; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannel; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannelEventHandler; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClientHandler.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClientHandler.java index e680a81c3889..df517e1e2eed 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClientHandler.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/DefaultPinpointClientHandler.java @@ -16,10 +16,10 @@ package com.navercorp.pinpoint.rpc.client; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.MessageListener; import com.navercorp.pinpoint.rpc.PinpointSocket; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.StateChangeEventListener; import com.navercorp.pinpoint.rpc.client.ConnectFuture.Result; import com.navercorp.pinpoint.rpc.cluster.ClusterOption; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/PinpointClientHandler.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/PinpointClientHandler.java index ec476c219e0a..adf63e210913 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/PinpointClientHandler.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/PinpointClientHandler.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.rpc.client; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.cluster.ClusterOption; import com.navercorp.pinpoint.rpc.common.SocketStateCode; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannel; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/ReconnectStateClientHandler.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/ReconnectStateClientHandler.java index adde05247fdd..8cf31c99794c 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/ReconnectStateClientHandler.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/ReconnectStateClientHandler.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.rpc.client; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.client.ConnectFuture.Result; import com.navercorp.pinpoint.rpc.cluster.ClusterOption; import com.navercorp.pinpoint.rpc.common.SocketStateCode; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/RequestManager.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/RequestManager.java index ba47c8d1739b..bf9a6a00cdd8 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/RequestManager.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/client/RequestManager.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.rpc.client; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.packet.RequestPacket; import com.navercorp.pinpoint.rpc.packet.ResponsePacket; import com.navercorp.pinpoint.rpc.server.PinpointServer; diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/server/DefaultPinpointServer.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/server/DefaultPinpointServer.java index 939c43b139d3..29b0d67705c1 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/server/DefaultPinpointServer.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/server/DefaultPinpointServer.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.rpc.server; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.client.RequestManager; import com.navercorp.pinpoint.rpc.client.WriteFailFutureListener; import com.navercorp.pinpoint.rpc.cluster.ClusterOption; diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/ClassPreLoaderTest.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/ClassPreLoaderTest.java deleted file mode 100644 index 663b747f23ce..000000000000 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/ClassPreLoaderTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2014 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.rpc; - -import org.junit.jupiter.api.Test; - -/** - * @author emeroad - */ -public class ClassPreLoaderTest { - @Test - public void testPreload() throws Exception { - ClassPreLoader.preload(); - } -} diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java index 6fa87b74b76f..fefa308b6c33 100644 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java +++ b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.rpc.client; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.TestByteUtils; import com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils; import com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor; diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/ReconnectTest.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/ReconnectTest.java index 99a6eb27de34..b8a1f2691e80 100644 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/ReconnectTest.java +++ b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/ReconnectTest.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.rpc.client; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.TestByteUtils; import com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils; import com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor; diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/RequestManagerTest.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/RequestManagerTest.java index cd1b44b1e392..a3eb8f04ed4f 100644 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/RequestManagerTest.java +++ b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/RequestManagerTest.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.rpc.client; -import com.navercorp.pinpoint.rpc.ResponseMessage; +import com.navercorp.pinpoint.io.ResponseMessage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jboss.netty.util.HashedWheelTimer; diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/util/PinpointRPCTestUtils.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/util/PinpointRPCTestUtils.java index d0dc4844ba5c..eaa88fcc927b 100644 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/util/PinpointRPCTestUtils.java +++ b/rpc/src/test/java/com/navercorp/pinpoint/rpc/util/PinpointRPCTestUtils.java @@ -16,11 +16,11 @@ package com.navercorp.pinpoint.rpc.util; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.rpc.LoggingStateChangeEventListener; import com.navercorp.pinpoint.rpc.MessageListener; import com.navercorp.pinpoint.rpc.PinpointSocket; import com.navercorp.pinpoint.rpc.PinpointSocketException; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory; import com.navercorp.pinpoint.rpc.client.PinpointClient; import com.navercorp.pinpoint.rpc.packet.HandshakePropertyType; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/FailedPinpointRouteResponse.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/FailedPinpointRouteResponse.java index b659efc51c1e..4b8e41d02ecd 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/FailedPinpointRouteResponse.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/FailedPinpointRouteResponse.java @@ -19,6 +19,8 @@ import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; import org.apache.thrift.TBase; +import java.util.Objects; + /** * @author Taejin Koo */ @@ -28,8 +30,13 @@ public class FailedPinpointRouteResponse implements PinpointRouteResponse { private final TBase response; public FailedPinpointRouteResponse(TRouteResult routeResult, TBase response) { - this.routeResult = routeResult; - this.response = response; + this.routeResult = Objects.requireNonNull(routeResult, "routeResult"); + this.response = Objects.requireNonNull(response, "response"); + } + + public FailedPinpointRouteResponse(TRouteResult routeResult) { + this.routeResult = Objects.requireNonNull(routeResult, "routeResult"); + this.response = null; } @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java index 7875bc7b73f1..07d1ae00ed10 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java @@ -18,9 +18,9 @@ import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.util.CollectionUtils; +import com.navercorp.pinpoint.io.ResponseMessage; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.rpc.PinpointSocket; -import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannel; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannelEventHandler; @@ -170,7 +170,7 @@ public PinpointRouteResponse invoke(ClusterKey clusterKey, byte[] payload) throw public PinpointRouteResponse invoke(ClusterKey clusterKey, byte[] payload, long timeout) throws TException { final List socketList = clusterManager.getSocket(clusterKey); if (CollectionUtils.nullSafeSize(socketList) != 1) { - return new FailedPinpointRouteResponse(TRouteResult.NOT_FOUND, null); + return new FailedPinpointRouteResponse(TRouteResult.NOT_FOUND); } final PinpointSocket socket = socketList.get(0); @@ -225,12 +225,12 @@ private PinpointRouteResponse getResponse(CompletableFuture fut ResponseMessage responseMessage = future.get(timeout, TimeUnit.MILLISECONDS); return routeResponseParser.parse(responseMessage.getMessage()); } catch (ExecutionException e) { - return new FailedPinpointRouteResponse(TRouteResult.UNKNOWN, null); + return new FailedPinpointRouteResponse(TRouteResult.UNKNOWN); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - return new FailedPinpointRouteResponse(TRouteResult.UNKNOWN, null); + return new FailedPinpointRouteResponse(TRouteResult.UNKNOWN); } catch (TimeoutException e) { - return new FailedPinpointRouteResponse(TRouteResult.TIMEOUT, null); + return new FailedPinpointRouteResponse(TRouteResult.TIMEOUT); } } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/AgentActiveThreadDumpListSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/AgentActiveThreadDumpListSerializerTest.java index 6dd32b7f3560..b5f44295661d 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/view/AgentActiveThreadDumpListSerializerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/view/AgentActiveThreadDumpListSerializerTest.java @@ -20,11 +20,11 @@ import com.navercorp.pinpoint.common.server.util.json.TypeRef; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.common.util.ThreadMXBeanUtils; -import com.navercorp.pinpoint.profiler.context.thrift.ThreadDumpThriftMessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.ThreadDumpMetricSnapshot; import com.navercorp.pinpoint.profiler.util.ThreadDumpUtils; import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; +import com.navercorp.pinpoint.thrift.sender.message.ThreadDumpThriftMessageConverter; import com.navercorp.pinpoint.web.vo.activethread.AgentActiveThreadDumpFactory; import com.navercorp.pinpoint.web.vo.activethread.AgentActiveThreadDumpList; import org.junit.jupiter.api.Assertions; diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/activethread/AgentActiveThreadDumpListTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/activethread/AgentActiveThreadDumpListTest.java index ad87c7fc07fd..33f295e86e6d 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/activethread/AgentActiveThreadDumpListTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/vo/activethread/AgentActiveThreadDumpListTest.java @@ -17,8 +17,6 @@ package com.navercorp.pinpoint.web.vo.activethread; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; -import com.navercorp.pinpoint.profiler.context.thrift.ThreadDumpThriftMessageConverter; -import com.navercorp.pinpoint.profiler.context.thrift.ThreadStateThriftMessageConverter; import com.navercorp.pinpoint.profiler.monitor.metric.deadlock.ThreadDumpMetricSnapshot; import com.navercorp.pinpoint.profiler.util.ThreadDumpUtils; import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; @@ -26,6 +24,8 @@ import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; import com.navercorp.pinpoint.thrift.dto.command.TThreadLightDump; import com.navercorp.pinpoint.thrift.dto.command.TThreadState; +import com.navercorp.pinpoint.thrift.sender.message.ThreadDumpThriftMessageConverter; +import com.navercorp.pinpoint.thrift.sender.message.ThreadStateThriftMessageConverter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;